// 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 "test_tools.h" #include #include #include #include #include #include namespace { // clang-format off // base units inline constexpr struct second_ : named_unit<"s"> {} second; inline constexpr struct metre_ : named_unit<"m"> {} metre; inline constexpr struct gram_ : named_unit<"g"> {} gram; inline constexpr struct kilogram_ : decltype(kilo) {} kilogram; // derived named units inline constexpr struct radian_ : named_unit<"rad", metre / metre> {} radian; inline constexpr struct steradian_ : named_unit<"sr", square / square> {} steradian; inline constexpr struct hertz_ : named_unit<"Hz", 1 / second> {} hertz; inline constexpr struct becquerel : named_unit<"Bq", 1 / second> {} becquerel; inline constexpr struct newton_ : named_unit<"N", kilogram * metre / square> {} newton; inline constexpr struct pascal_ : named_unit<"Pa", newton / square> {} pascal; inline constexpr struct joule_ : named_unit<"J", newton * metre> {} joule; inline constexpr struct watt_ : named_unit<"W", joule / second> {} watt; inline constexpr struct minute_ : named_unit<"min", mag<60> * second> {} minute; inline constexpr struct hour_ : named_unit<"h", mag<60> * minute> {} hour; inline constexpr struct day_ : named_unit<"d", mag<24> * hour> {} day; inline constexpr struct astronomical_unit_ : named_unit<"au", mag<149'597'870'700> * metre> {} astronomical_unit; inline constexpr struct degree_ : named_unit * radian> {} degree; inline constexpr struct are_ : named_unit<"a", square>> {} are; inline constexpr struct hectare_ : decltype(hecto) {} hectare; inline constexpr struct litre_ : named_unit<"l", cubic>> {} litre; inline constexpr struct tonne_ : named_unit<"t", mag<1000> * kilogram> {} tonne; inline constexpr struct dalton_ : named_unit<"Da", mag * mag_power<10, -27> * kilogram> {} dalton; inline constexpr struct electronvolt_ : named_unit<"eV", mag * mag_power<10, -19> * joule> {} electronvolt; inline constexpr struct kilometre_ : decltype(kilo) {} kilometre; // clang-format on } // concepts verification static_assert(Unit); static_assert(Unit); static_assert(Unit); static_assert(Unit); static_assert(Unit); static_assert(Unit)>); static_assert(Unit)>); static_assert(Unit)>); static_assert(Unit * second)>); static_assert(Unit); static_assert(NamedUnit); static_assert(NamedUnit); static_assert(NamedUnit); static_assert(NamedUnit); static_assert(NamedUnit); static_assert(!NamedUnit)>); static_assert(!NamedUnit)>); static_assert(!NamedUnit)>); static_assert(!NamedUnit * second)>); static_assert(!NamedUnit); static_assert(kilo == kilometre); static_assert(mag<1000> * metre == kilo); static_assert(mag<1000> * metre == kilometre); static_assert(equivalent, kilometre>); static_assert(equivalent * metre, kilo>); static_assert(equivalent * metre, kilometre>); static_assert(metre != kilometre); static_assert(mag<100> * metre != kilometre); static_assert(milli != kilometre); static_assert(!equivalent); static_assert(!equivalent * metre, kilometre>); static_assert(!equivalent, kilometre>); static_assert(1 / second != hertz); static_assert(becquerel != hertz); static_assert(equivalent<1 / second, hertz>); static_assert(!equivalent); using namespace units; using namespace units::isq; struct metre : named_unit {}; struct centimetre : prefixed_unit {}; struct kilometre : prefixed_unit {}; struct yard : named_scaled_unit(), metre> {}; struct foot : named_scaled_unit(), yard> {}; struct dim_length : base_dimension<"length", metre> {}; struct second : named_unit {}; struct hour : named_scaled_unit(), second> {}; struct dim_time : base_dimension<"time", second> {}; struct kelvin : named_unit {}; #if !UNITS_COMP_MSVC static_assert([](P) { return !requires { typename prefixed_unit; }; }(si::kilo{})); // no prefix allowed #endif struct metre_per_second : derived_unit {}; struct dim_speed : derived_dimension, units::exponent> {}; struct kilometre_per_hour : derived_scaled_unit {}; static_assert(equivalent); static_assert(equivalent); static_assert(compare(), metre>>, metre>); static_assert(compare(), metre>>, centimetre>); static_assert(compare>, yard>); static_assert(compare(), metre>>, foot>); static_assert(compare>, kilometre_per_hour>); static_assert(centimetre::symbol == "cm"); static_assert(kilometre::symbol == "km"); static_assert(kilometre_per_hour::symbol == "km/h"); } // namespace