1#ifndef LIBSBX_UTILITY_TIMER_HPP_
2#define LIBSBX_UTILITY_TIMER_HPP_
9#include <libsbx/units/time.hpp>
11namespace sbx::utility {
25 std::chrono::time_point<std::chrono::high_resolution_clock> _start{};
33 template<
typename Callable>
34 requires (std::is_invocable_v<Callable, const units::second&>)
36 : _on_destroy{std::forward<Callable>(callable)},
37 _start{std::chrono::high_resolution_clock::now()} { }
41 const auto now = std::chrono::high_resolution_clock::now();
42 const auto elapsed =
units::second{std::chrono::duration_cast<std::chrono::duration<std::float_t>>(now - _start).count()};
44 std::invoke(_on_destroy, elapsed);
51 std::chrono::time_point<std::chrono::high_resolution_clock> _start;
Definition: quantity.hpp:65