// 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. #pragma once #include #include #include #include #include #include namespace units { namespace detail { template concept basic_arithmetic = // exposition only std::magma && std::magma && std::magma && std::magma; } // namespace detail // PrefixType struct prefix_type; template concept PrefixType = std::derived_from; // Prefix // TODO gcc:92150 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92150 // namespace detail { // template // inline constexpr bool is_prefix = false; // template // inline constexpr bool is_prefix> = true; // } // namespace detail template // concept Prefix = detail::is_prefix; concept Prefix = true; namespace detail { template inline constexpr bool is_ratio = false; } // namespace detail template concept Ratio = detail::is_ratio; // UnitRatio template concept UnitRatio = Ratio && (R::num * R::den > 0); // Unit template struct scaled_unit; template concept Unit = is_derived_from_instantiation; // BaseDimension template requires U::is_named struct base_dimension; namespace detail { #if __GNUC__ == 9 && __GNUC_MINOR__ < 2 template inline constexpr bool is_base_dimension = true; #else template inline constexpr bool is_base_dimension = false; template inline constexpr bool is_base_dimension> = true; #endif } // namespace detail template concept BaseDimension = detail::is_base_dimension; // Exponent namespace detail { template inline constexpr bool is_exp = false; } // namespace detail template concept Exponent = detail::is_exp; // DerivedDimension namespace detail { template requires (BaseDimension && ... && BaseDimension) struct derived_dimension_base; } // namespace detail template concept DerivedDimension = is_instantiation, detail::derived_dimension_base>; // Dimension template concept Dimension = BaseDimension || DerivedDimension; // UnitOf namespace detail { template struct dimension_unit_impl; template struct dimension_unit_impl { using type = D::base_unit; }; template struct dimension_unit_impl { using type = D::coherent_unit; }; } // namespace detail template using dimension_unit = detail::dimension_unit_impl::type; template concept UnitOf = Unit && Dimension && std::same_as::reference>; // Quantity namespace detail { template inline constexpr bool is_quantity = false; } // namespace detail template concept Quantity = detail::is_quantity; // Scalar template concept Scalar = (!Quantity) && std::regular && std::totally_ordered && detail::basic_arithmetic; } // namespace units