2018-08-22 12:11:19 +02:00
|
|
|
// 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.
|
|
|
|
|
2019-12-01 19:47:58 +01:00
|
|
|
#include "units/unit.h"
|
2020-05-08 10:50:34 +02:00
|
|
|
#include "units/bits/equivalent.h"
|
2019-12-01 19:47:58 +01:00
|
|
|
#include "units/physical/si/prefixes.h"
|
2018-08-22 12:11:19 +02:00
|
|
|
|
2018-09-28 07:47:37 -07:00
|
|
|
namespace {
|
2019-04-09 17:22:15 +02:00
|
|
|
|
2019-12-01 19:47:58 +01:00
|
|
|
using namespace units;
|
2020-05-08 22:39:24 +02:00
|
|
|
using namespace units::physical;
|
2019-07-24 11:58:15 +02:00
|
|
|
|
2020-05-08 10:50:34 +02:00
|
|
|
template<typename T, typename U>
|
|
|
|
inline constexpr bool compare = DOWNCAST_MODE != 0 ? std::is_same_v<T, U> : (std::is_same_v<T, U> || units::equivalent<T, U>);
|
|
|
|
|
2019-12-01 19:47:58 +01:00
|
|
|
struct metre : named_unit<metre, "m", si::prefix> {};
|
|
|
|
struct centimetre : prefixed_unit<centimetre, si::centi, metre> {};
|
|
|
|
struct kilometre : prefixed_unit<kilometre, si::kilo, metre> {};
|
2020-06-27 19:15:46 +02:00
|
|
|
struct yard : named_scaled_unit<yard, "yd", no_prefix, ratio(9'144, 1, -4), metre> {};
|
|
|
|
struct foot : named_scaled_unit<foot, "ft", no_prefix, ratio(1, 3), yard> {};
|
2019-12-01 19:47:58 +01:00
|
|
|
struct dim_length : base_dimension<"length", metre> {};
|
2019-07-24 16:55:21 +02:00
|
|
|
|
2019-12-01 19:47:58 +01:00
|
|
|
struct second : named_unit<second, "s", si::prefix> {};
|
2020-06-27 19:15:46 +02:00
|
|
|
struct hour : named_scaled_unit<hour, "h", no_prefix, ratio(36, 1, 2), second> {};
|
2019-12-01 19:47:58 +01:00
|
|
|
struct dim_time : base_dimension<"time", second> {};
|
2019-07-24 16:55:21 +02:00
|
|
|
|
2019-12-07 16:30:40 +01:00
|
|
|
struct kelvin : named_unit<kelvin, "K", no_prefix> {};
|
2020-09-06 15:35:08 +02:00
|
|
|
|
|
|
|
#if COMP_GCC >= 10
|
|
|
|
static_assert([]<Prefix P>(P) { return !requires { typename prefixed_unit<struct kilokelvin, P, kelvin>; }; }(si::kilo{})); // no prefix allowed
|
2020-09-05 22:39:34 -04:00
|
|
|
#endif
|
2019-12-07 16:30:40 +01:00
|
|
|
|
2019-12-01 19:47:58 +01:00
|
|
|
struct metre_per_second : unit<metre_per_second> {};
|
2020-09-08 11:02:16 +02:00
|
|
|
struct dim_speed : derived_dimension<dim_speed, metre_per_second, units::exponent<dim_length, 1>, units::exponent<dim_time, -1>> {};
|
2020-05-14 16:00:38 +02:00
|
|
|
struct kilometre_per_hour : deduced_unit<kilometre_per_hour, dim_speed, kilometre, hour> {};
|
2019-11-04 06:46:53 +00:00
|
|
|
|
2020-05-08 10:50:34 +02:00
|
|
|
static_assert(compare<downcast<scaled_unit<ratio(1), metre>>, metre>);
|
|
|
|
static_assert(compare<downcast<scaled_unit<ratio(1, 1, -2), metre>>, centimetre>);
|
|
|
|
static_assert(compare<downcast<scaled_unit<ratio(yard::ratio.num, yard::ratio.den, yard::ratio.exp), metre>>, yard>);
|
|
|
|
static_assert(compare<downcast<scaled_unit<yard::ratio * ratio(1, 3), metre>>, foot>);
|
|
|
|
static_assert(compare<downcast<scaled_unit<kilometre::ratio / hour::ratio, metre_per_second>>, kilometre_per_hour>);
|
2020-09-06 15:35:08 +02:00
|
|
|
|
|
|
|
#if COMP_GCC >= 10
|
2020-09-05 22:22:18 -04:00
|
|
|
static_assert([]<ratio R>() { return !requires { typename scaled_unit<R, metre>; }; }.template operator()<ratio(-1, 1)>()); // negative unit ratio
|
|
|
|
#endif
|
2019-11-04 06:46:53 +00:00
|
|
|
|
2019-12-01 19:47:58 +01:00
|
|
|
static_assert(centimetre::symbol == "cm");
|
|
|
|
static_assert(kilometre::symbol == "km");
|
2019-12-11 08:07:13 +01:00
|
|
|
static_assert(kilometre_per_hour::symbol == "km/h");
|
2019-11-04 06:46:53 +00:00
|
|
|
|
2018-09-28 07:47:37 -07:00
|
|
|
} // namespace
|