// 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 namespace { using namespace units; using dimension_one_ = struct dimension_one; // clang-format off BASE_DIMENSION_(length, "L"); BASE_DIMENSION_(time, "T"); BASE_DIMENSION_(mass, "M"); inline constexpr struct second_ : named_unit<"s", time> {} second; DERIVED_DIMENSION_(frequency, decltype(1 / time)); DERIVED_DIMENSION_(action, decltype(1 / time)); DERIVED_DIMENSION_(area, decltype(length * length)); DERIVED_DIMENSION_(volume, decltype(area * length)); DERIVED_DIMENSION_(speed, decltype(length / time)); inline constexpr struct velocity_ : speed_ {} velocity; DERIVED_DIMENSION_(acceleration, decltype(speed / time)); DERIVED_DIMENSION_(force, decltype(mass * acceleration)); DERIVED_DIMENSION_(moment_of_force, decltype(length * force)); DERIVED_DIMENSION_(torque, decltype(moment_of_force)); DERIVED_DIMENSION_(pressure, decltype(force / area)); DERIVED_DIMENSION_(stress, decltype(pressure)); DERIVED_DIMENSION_(strain, decltype(stress / stress)); DERIVED_DIMENSION_(power, decltype(force * speed)); DERIVED_DIMENSION_(efficiency, decltype(power / power)); DERIVED_DIMENSION_(energy, decltype(force * length)); // clang-format on // concepts verification static_assert(BaseDimension); static_assert(!BaseDimension); static_assert(!DerivedDimension); static_assert(DerivedDimension); static_assert(Dimension); static_assert(Dimension); static_assert(DerivedDimension); static_assert(DerivedDimension); // dimension_one static_assert(BaseDimension); // length // derived dimension expression template syntax verification static_assert(is_of_type<1 / time, derived_dimension>>); static_assert(is_of_type<1 / (1 / time), time_>); static_assert(is_of_type); static_assert(is_of_type