// 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 namespace units { struct dimension_length : make_dimension_t> {}; template<> struct downcasting_traits> : downcast_to {}; template concept bool Length = Quantity && std::Same; template using length = quantity; // SI units struct meter : unit {}; template<> struct downcasting_traits> : downcast_to {}; struct millimeter : milli {}; template<> struct downcasting_traits> : downcast_to {}; struct centimeter : centi {}; template<> struct downcasting_traits> : downcast_to {}; struct kilometer : kilo {}; template<> struct downcasting_traits> : downcast_to {}; inline namespace literals { // mm constexpr auto operator""_mm(unsigned long long l) { return length(l); } constexpr auto operator""_mm(long double l) { return length(l); } // cm constexpr auto operator""_cm(unsigned long long l) { return length(l); } constexpr auto operator""_cm(long double l) { return length(l); } // m constexpr auto operator""_m(unsigned long long l) { return length(l); } constexpr auto operator""_m(long double l) { return length(l); } // km constexpr auto operator""_km(unsigned long long l) { return length(l); } constexpr auto operator""_km(long double l) { return length(l); } } // namespace literals // US customary units struct yard : unit> {}; template<> struct downcasting_traits> : downcast_to {}; struct foot : unit, yard::ratio>> {}; template<> struct downcasting_traits> : downcast_to {}; struct inch : unit, foot::ratio>> {}; template<> struct downcasting_traits> : downcast_to {}; struct mile : unit, yard::ratio>> {}; template<> struct downcasting_traits> : downcast_to {}; inline namespace literals { // yd constexpr auto operator""_yd(unsigned long long l) { return length(l); } constexpr auto operator""_yd(long double l) { return length(l); } // ft constexpr auto operator""_ft(unsigned long long l) { return length(l); } constexpr auto operator""_ft(long double l) { return length(l); } // in constexpr auto operator""_in(unsigned long long l) { return length(l); } constexpr auto operator""_in(long double l) { return length(l); } // mi constexpr auto operator""_mi(unsigned long long l) { return length(l); } constexpr auto operator""_mi(long double l) { return length(l); } } // namespace literals } // namespace units