diff --git a/README.md b/README.md index f0f6a56f..e955a6b7 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ NOTE: This library as of now compiles correctly only with gcc-9.1 and newer. - Support for derived dimensions in `exp` added - Added `pow()` and `sqrt()` operations on quantities - `units` removed from a `std::experimental` namespace + - `downcasting_traits` renamed to `downcast_traits` and refactored helpers - 0.3.1 Sep 18, 2019 - cmcstl2 dependency changed to range-v3 0.9.1 diff --git a/doc/DESIGN.md b/doc/DESIGN.md index 7cf3a15c..51f9e67b 100644 --- a/doc/DESIGN.md +++ b/doc/DESIGN.md @@ -89,7 +89,7 @@ derived from `units::dimension` class template: template concept Dimension = std::is_empty_v && - detail::is_dimension>; // exposition only + detail::is_dimension>; // exposition only ``` #### `Exponents` @@ -219,7 +219,7 @@ struct dimension_multiply; template struct dimension_multiply, dimension> { - using type = downcasting_traits_t, dimension>>; + using type = downcast_traits_t, dimension>>; }; template @@ -275,7 +275,7 @@ derived from `units::unit` class template: template concept Unit = std::is_empty_v && - detail::is_unit>; // exposition only + detail::is_unit>; // exposition only ``` ### `Quantities` @@ -450,7 +450,7 @@ and are not arguably much easier to understand thus provide better user experience. -Downcasting capability is provided through dedicated `downcasting_traits`, concept, a few helper aliases and by +Downcasting capability is provided through dedicated `downcast_traits`, concept, a few helper aliases and by `base_type` member type in `downcast_base` class template. ```cpp @@ -467,28 +467,25 @@ concept Downcastable = std::derived_from>; template -using downcast_from = T::base_type; +using downcast_base_t = T::base_type; template -using downcast_to = std::type_identity; +struct downcast_traits : std::type_identity {}; template -struct downcasting_traits : downcast_to {}; - -template -using downcasting_traits_t = downcasting_traits::type; +using downcast_traits_t = downcast_traits::type; ``` With that the downcasting functionality is enabled by: ```cpp struct length : make_dimension_t> {}; -template<> struct downcasting_traits> : downcast_to {}; +template<> struct downcast_traits> : std::type_identity {}; ``` ```cpp struct kilometre : unit {}; -template<> struct downcasting_traits> : downcast_to {}; +template<> struct downcast_traits> : std::type_identity {}; ``` @@ -507,7 +504,7 @@ In order to extend the library with custom dimensions the user has to: ```cpp struct digital_information : units::make_dimension_t> {}; template<> - struct units::downcasting_traits> : units::downcast_to {}; + struct units::downcast_traits> : units::std::type_identity_t {}; ``` 2. Define a concept that will match a new dimension: @@ -521,10 +518,10 @@ In order to extend the library with custom dimensions the user has to: ```cpp struct bit : units::unit {}; - template<> struct units::downcasting_traits> : units::downcast_to {}; + template<> struct units::downcast_traits> : units::std::type_identity_t {}; struct byte : units::unit> {}; - template<> struct units::downcasting_traits> : units::downcast_to {}; + template<> struct units::downcast_traits> : units::std::type_identity_t {}; ``` 4. Provide user-defined literals for the most important units: @@ -568,7 +565,7 @@ In order to extend the library with custom dimensions the user has to: and allow implicit conversion to and from the underlying value type or types that are convertible to/from that value type. -9. Should we standardize accompany tools (`downcasting_traits`, `type_list` operations, `common_ratio`, etc)? +9. Should we standardize accompany tools (`downcast_traits`, `type_list` operations, `common_ratio`, etc)? 10. `k`, `K`, `W`, `F` UDLs conflict with gcc GNU extensions (https://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Fixed_002dPoint.html) for floating point types. diff --git a/src/include/units/bits/downcasting.h b/src/include/units/bits/downcasting.h index d27b9a51..6950b9c0 100644 --- a/src/include/units/bits/downcasting.h +++ b/src/include/units/bits/downcasting.h @@ -40,15 +40,12 @@ namespace units { std::derived_from>; template - using downcast_from = T::base_type; + using downcast_base_t = T::base_type; template - using downcast_to = std::type_identity; + struct downcast_traits : std::type_identity {}; template - struct downcasting_traits : downcast_to {}; - - template - using downcasting_traits_t = downcasting_traits::type; + using downcast_traits_t = downcast_traits::type; } // namespace units diff --git a/src/include/units/dimension.h b/src/include/units/dimension.h index 6ecd45bd..87ea5c2e 100644 --- a/src/include/units/dimension.h +++ b/src/include/units/dimension.h @@ -87,7 +87,7 @@ namespace units { template concept bool Dimension = std::is_empty_v && - detail::is_dimension>; + detail::is_dimension>; // exp @@ -156,10 +156,10 @@ namespace units { struct dim_invert; template - struct dim_invert> : std::type_identity...>>> {}; + struct dim_invert> : std::type_identity...>>> {}; template - using dim_invert_t = dim_invert>::type; + using dim_invert_t = dim_invert>::type; // todo: force as the only user interface to create dimensions through modules @@ -221,7 +221,7 @@ namespace units { template struct extract, ERest...> { - using type = extract_t, Num, Den>, ERest...>; + using type = extract_t, Num, Den>, ERest...>; }; } // namespace detail @@ -248,7 +248,7 @@ namespace units { struct dimension_multiply; template - struct dimension_multiply, dimension> : std::type_identity, dimension>>> {}; + struct dimension_multiply, dimension> : std::type_identity, dimension>>> {}; template using dimension_multiply_t = dimension_multiply::type; @@ -271,7 +271,7 @@ namespace units { struct dimension_sqrt; template - struct dimension_sqrt> : std::type_identity...>>> {}; + struct dimension_sqrt> : std::type_identity...>>> {}; template using dimension_sqrt_t = dimension_sqrt::type; @@ -281,7 +281,7 @@ namespace units { struct dimension_pow; template - struct dimension_pow, N> : std::type_identity...>>> {}; + struct dimension_pow, N> : std::type_identity...>>> {}; template using dimension_pow_t = dimension_pow::type; diff --git a/src/include/units/dimensions/acceleration.h b/src/include/units/dimensions/acceleration.h index ac68bf83..e7088e82 100644 --- a/src/include/units/dimensions/acceleration.h +++ b/src/include/units/dimensions/acceleration.h @@ -27,13 +27,13 @@ namespace units { struct acceleration : make_dimension_t, exp> {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; template concept bool Acceleration = QuantityOf; struct metre_per_second_sq : derived_unit {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; inline namespace literals { diff --git a/src/include/units/dimensions/area.h b/src/include/units/dimensions/area.h index b0fd45ba..66e725f8 100644 --- a/src/include/units/dimensions/area.h +++ b/src/include/units/dimensions/area.h @@ -27,25 +27,25 @@ namespace units { struct area : make_dimension_t> {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; template concept bool Area = QuantityOf; struct square_millimetre : derived_unit {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; struct square_centimetre : derived_unit {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; struct square_metre : derived_unit {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; struct square_kilometre : derived_unit {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; struct square_foot : derived_unit {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; inline namespace literals { diff --git a/src/include/units/dimensions/capacitance.h b/src/include/units/dimensions/capacitance.h index 41436eb3..5766f943 100644 --- a/src/include/units/dimensions/capacitance.h +++ b/src/include/units/dimensions/capacitance.h @@ -29,13 +29,13 @@ namespace units { struct capacitance : make_dimension_t, exp> {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; template concept bool Capacitance = QuantityOf; struct farad : derived_unit {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; inline namespace literals { diff --git a/src/include/units/dimensions/current.h b/src/include/units/dimensions/current.h index 275ba564..e1cabe7e 100644 --- a/src/include/units/dimensions/current.h +++ b/src/include/units/dimensions/current.h @@ -28,13 +28,13 @@ namespace units { struct current : make_dimension_t> {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; template concept bool Current = QuantityOf; struct ampere : unit {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; inline namespace literals { diff --git a/src/include/units/dimensions/electric_charge.h b/src/include/units/dimensions/electric_charge.h index 195eda18..572f06a2 100644 --- a/src/include/units/dimensions/electric_charge.h +++ b/src/include/units/dimensions/electric_charge.h @@ -29,13 +29,13 @@ namespace units { struct electric_charge : make_dimension_t, exp> {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; template concept bool ElectricCharge = QuantityOf; struct coulomb : derived_unit {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; inline namespace literals { diff --git a/src/include/units/dimensions/energy.h b/src/include/units/dimensions/energy.h index 49fc59b6..d6d5b1cd 100644 --- a/src/include/units/dimensions/energy.h +++ b/src/include/units/dimensions/energy.h @@ -29,13 +29,13 @@ namespace units { struct energy : make_dimension_t, exp> {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; template concept bool Energy = QuantityOf; struct joule : derived_unit {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; inline namespace literals { diff --git a/src/include/units/dimensions/force.h b/src/include/units/dimensions/force.h index c4d9b2c8..05bfef14 100644 --- a/src/include/units/dimensions/force.h +++ b/src/include/units/dimensions/force.h @@ -29,13 +29,13 @@ namespace units { struct force : make_dimension_t, exp> {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; template concept bool Force = QuantityOf; struct newton : derived_unit {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; inline namespace literals { diff --git a/src/include/units/dimensions/frequency.h b/src/include/units/dimensions/frequency.h index 19c9fe7b..5606e815 100644 --- a/src/include/units/dimensions/frequency.h +++ b/src/include/units/dimensions/frequency.h @@ -28,28 +28,28 @@ namespace units { struct frequency : make_dimension_t> {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; template concept bool Frequency = QuantityOf; struct hertz : derived_unit {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; struct millihertz : milli {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; struct kilohertz : kilo {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; struct megahertz : mega {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; struct gigahertz : giga {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; struct terahertz : tera {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; inline namespace literals { diff --git a/src/include/units/dimensions/length.h b/src/include/units/dimensions/length.h index f02506f3..ef736c58 100644 --- a/src/include/units/dimensions/length.h +++ b/src/include/units/dimensions/length.h @@ -28,23 +28,23 @@ namespace units { struct length : make_dimension_t> {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; template concept bool Length = QuantityOf; // SI units struct metre : unit {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; struct millimetre : milli {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; struct centimetre : centi {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; struct kilometre : kilo {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; inline namespace literals { @@ -68,16 +68,16 @@ namespace units { // US customary units struct yard : unit> {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; struct foot : unit, yard::ratio>> {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; struct inch : unit, foot::ratio>> {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; struct mile : unit, yard::ratio>> {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; inline namespace literals { diff --git a/src/include/units/dimensions/luminous_intensity.h b/src/include/units/dimensions/luminous_intensity.h index 21263247..fdd43594 100644 --- a/src/include/units/dimensions/luminous_intensity.h +++ b/src/include/units/dimensions/luminous_intensity.h @@ -28,13 +28,13 @@ namespace units { struct luminous_intensity : make_dimension_t> {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; template concept bool LuminousIntensity = QuantityOf; struct candela : unit {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; inline namespace literals { diff --git a/src/include/units/dimensions/mass.h b/src/include/units/dimensions/mass.h index 432b4bb3..4533b0c6 100644 --- a/src/include/units/dimensions/mass.h +++ b/src/include/units/dimensions/mass.h @@ -28,16 +28,16 @@ namespace units { struct mass : make_dimension_t> {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; template concept bool Mass = QuantityOf; struct gram : unit> {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; struct kilogram : kilo {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; inline namespace literals { diff --git a/src/include/units/dimensions/power.h b/src/include/units/dimensions/power.h index 1e8cd408..de8a7492 100644 --- a/src/include/units/dimensions/power.h +++ b/src/include/units/dimensions/power.h @@ -28,13 +28,13 @@ namespace units { struct power : make_dimension_t, exp> {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; template concept bool Power = QuantityOf; struct watt : derived_unit {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; inline namespace literals { diff --git a/src/include/units/dimensions/pressure.h b/src/include/units/dimensions/pressure.h index 0b7c6bac..f8eaa576 100644 --- a/src/include/units/dimensions/pressure.h +++ b/src/include/units/dimensions/pressure.h @@ -29,13 +29,13 @@ namespace units { struct pressure : make_dimension_t, exp> {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; template concept bool Pressure = QuantityOf; struct pascal : derived_unit {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; inline namespace literals { diff --git a/src/include/units/dimensions/substance.h b/src/include/units/dimensions/substance.h index 64ab5513..2cc21957 100644 --- a/src/include/units/dimensions/substance.h +++ b/src/include/units/dimensions/substance.h @@ -28,13 +28,13 @@ namespace units { struct substance : make_dimension_t> {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; template concept bool Substance = QuantityOf; struct mole : unit {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; inline namespace literals { diff --git a/src/include/units/dimensions/temperature.h b/src/include/units/dimensions/temperature.h index 5ec92eef..90f3d06b 100644 --- a/src/include/units/dimensions/temperature.h +++ b/src/include/units/dimensions/temperature.h @@ -28,13 +28,13 @@ namespace units { struct temperature : make_dimension_t> {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; template concept bool ThermodynamicTemperature = QuantityOf; struct kelvin : unit {}; - template<> struct downcasting_traits> : downcast_to {}; + template<> struct downcast_traits> : std::type_identity {}; inline namespace literals { diff --git a/src/include/units/dimensions/time.h b/src/include/units/dimensions/time.h index fa198b0b..6cd5fb0c 100644 --- a/src/include/units/dimensions/time.h +++ b/src/include/units/dimensions/time.h @@ -28,28 +28,28 @@ namespace units { struct time : make_dimension_t> {}; - template<> struct downcasting_traits> : downcast_to