// The MIT License (MIT) // // Copyright (c) 2018 Mateusz Pusz // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. #include #include #include /* ************** DERIVED DIMENSIONS THAT INCLUDE UNITS WITH SPECIAL NAMES **************** */ namespace { struct base_dim_digital_information { static constexpr const char* value = "digital information"; }; struct digital_information : units::make_dimension_t> {}; template concept bool DigitalInformation = units::QuantityOf; struct bit : units::unit {}; struct byte : units::unit> {}; inline namespace literals { constexpr auto operator""_b(unsigned long long l) { return units::quantity(l); } constexpr auto operator""_b(long double l) { return units::quantity(l); } constexpr auto operator""_B(unsigned long long l) { return units::quantity(l); } constexpr auto operator""_B(long double l) { return units::quantity(l); } } } template<> struct units::downcasting_traits> : units::downcast_to {}; template<> struct units::downcasting_traits> : units::downcast_to {}; template<> struct units::downcasting_traits> : units::downcast_to<::byte> {}; namespace { static_assert(1_B == 8_b); } namespace { using namespace units; // power spectral density struct power_spectral_density : make_dimension_t, units::exp> {}; struct sq_volt_per_hertz : unit {}; // amplitude spectral density struct amplitude_spectral_density : make_dimension_t, units::exp> {}; // todo: add support for derived_unit //struct volt_per_sq_hertz : derived_unit {}; struct volt_per_sqrt_hertz : unit {}; } namespace units { template<> struct downcasting_traits> : downcast_to {}; template<> struct downcasting_traits> : downcast_to {}; template<> struct downcasting_traits> : downcast_to {}; template<> struct downcasting_traits> : downcast_to {}; } namespace { static_assert(std::is_same_v, amplitude_spectral_density>); static_assert(std::is_same_v, power_spectral_density>); static_assert(std::is_same_v(quantity(4))), decltype(quantity(16))>); static_assert(std::is_same_v(16))), decltype(quantity(4))>); }