// 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 : units::base_dimension<"digital information", "b"> {}; struct digital_information : units::derived_dimension> {}; template concept DigitalInformation = units::QuantityOf; struct data_prefix : units::prefix_type {}; struct kibi : units::prefix, "Ki"> {}; struct bit : units::named_coherent_derived_unit {}; struct kilobit : units::prefixed_derived_unit {}; struct byte : units::named_scaled_derived_unit, data_prefix> {}; struct kilobyte : units::prefixed_derived_unit {}; inline namespace literals { constexpr auto operator""_b(unsigned long long l) { return units::quantity(l); } constexpr auto operator""_Kib(unsigned long long l) { return units::quantity(l); } constexpr auto operator""_B(unsigned long long l) { return units::quantity(l); } constexpr auto operator""_KiB(unsigned long long l) { return units::quantity(l); } } } namespace { static_assert(1_B == 8_b); static_assert(1024_b == 1_Kib); static_assert(1024_B == 1_KiB); static_assert(8 * 1024_b == 1_KiB); static_assert(8 * 1_Kib == 1_KiB); } namespace { using namespace units; // power spectral density struct power_spectral_density : derived_dimension, units::exp> {}; struct sq_volt_per_hertz : coherent_derived_unit {}; // amplitude spectral density struct amplitude_spectral_density : derived_dimension, units::exp> {}; struct volt_per_sqrt_hertz : coherent_derived_unit {}; } 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))>); }