diff --git a/example/v2_framework.cpp b/example/v2_framework.cpp index 1167c7f0..c117af2a 100644 --- a/example/v2_framework.cpp +++ b/example/v2_framework.cpp @@ -41,25 +41,25 @@ inline constexpr struct dim_amount_of_substance : base_dimension<"N"> { inline constexpr struct dim_luminous_intensity : base_dimension<"J"> { } dim_luminous_intensity; +inline constexpr struct dim_frequency : decltype(1 / dim_time) { +} dim_frequency; +inline constexpr struct dim_area : decltype(dim_length * dim_length) { +} dim_area; +inline constexpr struct dim_volume : decltype(dim_area * dim_length) { +} dim_volume; +inline constexpr struct dim_speed : decltype(dim_length / dim_time) { +} dim_speed; +inline constexpr struct dim_acceleration : decltype(dim_speed / dim_time) { +} dim_acceleration; + +// inline constexpr auto speed = length / time; + // using dim_speed = decltype(dim_length / dim_time); // inline constexpr dim_speed dim_speed; // template // concept Length = QuantityOf; -// inline constexpr struct dim_frequency : decltype(1 / dim_time) { -// } dim_frequency; -// inline constexpr struct dim_area : decltype(dim_length * dim_length) { -// } dim_area; -// inline constexpr struct dim_volume : decltype(dim_area * dim_length) { -// } dim_volume; -// inline constexpr struct dim_speed : decltype(dim_length / dim_time) { -// } dim_speed; -// inline constexpr struct dim_acceleration : decltype(dim_speed / dim_time) { -// } dim_acceleration; - -// inline constexpr auto speed = length / time; - } // namespace units::isq #include @@ -212,21 +212,15 @@ inline constexpr struct length : system_reference { } length; inline constexpr struct time : system_reference { } time; -// inline constexpr struct frequency : system_reference { -inline constexpr struct frequency : system_reference { +inline constexpr struct frequency : system_reference { } frequency; -// inline constexpr struct area : system_reference { -inline constexpr struct area : system_reference { +inline constexpr struct area : system_reference { } area; -// inline constexpr struct volume : system_reference { -inline constexpr struct volume : system_reference { +inline constexpr struct volume : system_reference { } volume; -// inline constexpr struct speed : system_reference { -inline constexpr struct speed : system_reference { +inline constexpr struct speed : system_reference { } speed; -// inline constexpr struct acceleration : system_reference { -inline constexpr struct acceleration : - system_reference { +inline constexpr struct acceleration : system_reference { } acceleration; } // namespace units::isq::si @@ -277,49 +271,47 @@ static_assert(is_of_type, per>>>); static_assert(is_of_type); -// static_assert( -// is_of_type>>); -// static_assert( -// is_of_type>>); -// static_assert(is_of_type, per>>); -// static_assert(is_of_type<1 / (dim_speed * dim_speed) * dim_length, -// derived_dimension>>>); +static_assert(is_of_type); +static_assert(is_of_type>>); +static_assert( + is_of_type>>>); +static_assert(is_of_type<1 / (dim_speed * dim_speed) * dim_length, + derived_dimension, per>>); namespace si { // comparisons of equivalent dimensions static_assert(dim_length / dim_length == dim_one); -static_assert(1 / dim_time == frequency::dimension); -static_assert(1 / frequency::dimension == dim_time); -static_assert(frequency::dimension * dim_time == dim_one); +static_assert(1 / dim_time == dim_frequency); +static_assert(1 / dim_frequency == dim_time); +static_assert(dim_frequency * dim_time == dim_one); -static_assert(dim_length * dim_length == area::dimension); -static_assert(dim_length * dim_length != volume::dimension); -static_assert(area::dimension / dim_length == dim_length); +static_assert(dim_length * dim_length == dim_area); +static_assert(dim_length * dim_length != dim_volume); +static_assert(dim_area / dim_length == dim_length); -static_assert(dim_length * dim_length * dim_length == volume::dimension); -static_assert(area::dimension * dim_length == volume::dimension); -static_assert(volume::dimension / dim_length == area::dimension); -static_assert(volume::dimension / dim_length / dim_length == dim_length); -static_assert(area::dimension * area::dimension / dim_length == volume::dimension); -static_assert(area::dimension * (area::dimension / dim_length) == volume::dimension); -static_assert(volume::dimension / (dim_length * dim_length) == dim_length); +static_assert(dim_length * dim_length * dim_length == dim_volume); +static_assert(dim_area * dim_length == dim_volume); +static_assert(dim_volume / dim_length == dim_area); +static_assert(dim_volume / dim_length / dim_length == dim_length); +static_assert(dim_area * dim_area / dim_length == dim_volume); +static_assert(dim_area * (dim_area / dim_length) == dim_volume); +static_assert(dim_volume / (dim_length * dim_length) == dim_length); -static_assert(dim_length / dim_time == speed::dimension); -static_assert(dim_length * dim_time != speed::dimension); -static_assert(dim_length / dim_time / dim_time != speed::dimension); -static_assert(dim_length / speed::dimension == dim_time); -static_assert(speed::dimension * dim_time == dim_length); +static_assert(dim_length / dim_time == dim_speed); +static_assert(dim_length * dim_time != dim_speed); +static_assert(dim_length / dim_time / dim_time != dim_speed); +static_assert(dim_length / dim_speed == dim_time); +static_assert(dim_speed * dim_time == dim_length); -static_assert(dim_length / dim_time / dim_time == acceleration::dimension); -static_assert(dim_length / (dim_time * dim_time) == acceleration::dimension); -static_assert(speed::dimension / dim_time == acceleration::dimension); -static_assert(speed::dimension / acceleration::dimension == dim_time); -static_assert(acceleration::dimension * dim_time == speed::dimension); -static_assert(acceleration::dimension * (dim_time * dim_time) == dim_length); -static_assert(acceleration::dimension / speed::dimension == frequency::dimension); +static_assert(dim_length / dim_time / dim_time == dim_acceleration); +static_assert(dim_length / (dim_time * dim_time) == dim_acceleration); +static_assert(dim_speed / dim_time == dim_acceleration); +static_assert(dim_speed / dim_acceleration == dim_time); +static_assert(dim_acceleration * dim_time == dim_speed); +static_assert(dim_acceleration * (dim_time * dim_time) == dim_length); +static_assert(dim_acceleration / dim_speed == dim_frequency); } // namespace si @@ -368,35 +360,35 @@ static_assert(is_of_type -struct derived_dimension : detail::expr_fractions, Ds...> {}; +struct derived_dimension : detail::expr_fractions, Ds...> { + using type = derived_dimension; +}; template std::true_type is_derived_dimension(const volatile derived_dimension*); @@ -122,37 +124,46 @@ namespace detail { template<> inline constexpr bool is_dim_one = true; +template +struct dim_type_impl { + using type = T; +}; + +template +struct dim_type_impl { + using type = T::type; +}; + +template +using dim_type = dim_type_impl::type; + } // namespace detail template [[nodiscard]] constexpr Dimension auto operator*(D1, D2) { - return detail::expr_multiply(); + return detail::expr_multiply, detail::dim_type, struct dim_one, + detail::type_list_of_base_dimension_less, derived_dimension>(); } template [[nodiscard]] constexpr Dimension auto operator/(D1, D2) { - return detail::expr_divide(); + return detail::expr_divide, detail::dim_type, struct dim_one, + detail::type_list_of_base_dimension_less, derived_dimension>(); } template [[nodiscard]] constexpr Dimension auto operator/(int value, D) { gsl_Assert(value == 1); - return detail::expr_invert(); + return detail::expr_invert, struct dim_one, derived_dimension>(); } template [[nodiscard]] constexpr bool operator==(D1, D2) { - return false; -} - -template -[[nodiscard]] constexpr bool operator==(D, D) -{ - return true; + return is_same_v, detail::dim_type>; } // TODO consider adding the support for text output of the dimensional equation