mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-01 19:34:29 +02:00
refactor: chrono
types now convert to quantity kinds
This commit is contained in:
@@ -60,7 +60,7 @@ template<typename Period>
|
|||||||
|
|
||||||
template<typename Rep, typename Period>
|
template<typename Rep, typename Period>
|
||||||
struct quantity_like_traits<std::chrono::duration<Rep, Period>> {
|
struct quantity_like_traits<std::chrono::duration<Rep, Period>> {
|
||||||
static constexpr auto reference = isq::duration[detail::time_unit_from_chrono_period<Period>()];
|
static constexpr auto reference = detail::time_unit_from_chrono_period<Period>();
|
||||||
using rep = Rep;
|
using rep = Rep;
|
||||||
[[nodiscard]] static constexpr rep number(const std::chrono::duration<Rep, Period>& q) { return q.count(); }
|
[[nodiscard]] static constexpr rep number(const std::chrono::duration<Rep, Period>& q) { return q.count(); }
|
||||||
};
|
};
|
||||||
@@ -75,7 +75,7 @@ inline constexpr chrono_point_origin_<C> chrono_point_origin;
|
|||||||
|
|
||||||
template<typename C, typename Rep, typename Period>
|
template<typename C, typename Rep, typename Period>
|
||||||
struct quantity_point_like_traits<std::chrono::time_point<C, std::chrono::duration<Rep, Period>>> {
|
struct quantity_point_like_traits<std::chrono::time_point<C, std::chrono::duration<Rep, Period>>> {
|
||||||
static constexpr auto reference = isq::time[detail::time_unit_from_chrono_period<Period>()];
|
static constexpr auto reference = detail::time_unit_from_chrono_period<Period>();
|
||||||
static constexpr auto point_origin = chrono_point_origin<C>;
|
static constexpr auto point_origin = chrono_point_origin<C>;
|
||||||
using rep = Rep;
|
using rep = Rep;
|
||||||
[[nodiscard]] static constexpr auto relative(const std::chrono::time_point<C, std::chrono::duration<Rep, Period>>& qp)
|
[[nodiscard]] static constexpr auto relative(const std::chrono::time_point<C, std::chrono::duration<Rep, Period>>& qp)
|
||||||
|
@@ -37,7 +37,7 @@ using sys_days =
|
|||||||
std::chrono::time_point<std::chrono::system_clock,
|
std::chrono::time_point<std::chrono::system_clock,
|
||||||
std::chrono::duration<long, std::ratio_multiply<std::ratio<24>, std::chrono::hours::period>>>;
|
std::chrono::duration<long, std::ratio_multiply<std::ratio<24>, std::chrono::hours::period>>>;
|
||||||
template<Unit auto U, typename C, typename Rep = double>
|
template<Unit auto U, typename C, typename Rep = double>
|
||||||
using time_point = quantity_point<isq::time[U], chrono_point_origin<C>, Rep>;
|
using time_point = quantity_point<U, chrono_point_origin<C>, Rep>;
|
||||||
|
|
||||||
static_assert(QuantityLike<std::chrono::seconds>);
|
static_assert(QuantityLike<std::chrono::seconds>);
|
||||||
static_assert(QuantityPointLike<sys_seconds>);
|
static_assert(QuantityPointLike<sys_seconds>);
|
||||||
@@ -82,8 +82,8 @@ static_assert(!std::convertible_to<sys_seconds, time_point<si::day, std::chrono:
|
|||||||
|
|
||||||
|
|
||||||
// CTAD
|
// CTAD
|
||||||
static_assert(is_of_type<quantity{1s}, quantity<isq::time[si::second], std::chrono::seconds::rep>>);
|
static_assert(is_of_type<quantity{1s}, quantity<si::second, std::chrono::seconds::rep>>);
|
||||||
static_assert(is_of_type<quantity{1h}, quantity<isq::time[si::hour], std::chrono::hours::rep>>);
|
static_assert(is_of_type<quantity{1h}, quantity<si::hour, std::chrono::hours::rep>>);
|
||||||
static_assert(
|
static_assert(
|
||||||
is_of_type<quantity_point{sys_seconds{1s}}, time_point<si::second, std::chrono::system_clock, sys_seconds::rep>>);
|
is_of_type<quantity_point{sys_seconds{1s}}, time_point<si::second, std::chrono::system_clock, sys_seconds::rep>>);
|
||||||
static_assert(is_of_type<quantity_point{sys_days{sys_days::duration{1}}},
|
static_assert(is_of_type<quantity_point{sys_days{sys_days::duration{1}}},
|
||||||
|
Reference in New Issue
Block a user