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-04-09 21:31:09 +01:00
|
|
|
#include <units/time.h>
|
|
|
|
#include <units/length.h>
|
|
|
|
#include <units/mass.h>
|
|
|
|
#include <units/current.h>
|
|
|
|
#include <units/current.h>
|
|
|
|
#include <units/temperature.h>
|
|
|
|
#include <units/substance.h>
|
|
|
|
#include <units/luminous_intensity.h>
|
|
|
|
|
|
|
|
#include <units/frequency.h>
|
|
|
|
#include <units/velocity.h>
|
|
|
|
|
2018-08-22 12:11:19 +02:00
|
|
|
#include <utility>
|
|
|
|
|
2018-09-28 07:47:37 -07:00
|
|
|
namespace {
|
2019-04-09 17:22:15 +02:00
|
|
|
|
2018-09-28 07:47:37 -07:00
|
|
|
using namespace units;
|
2018-08-22 12:11:19 +02:00
|
|
|
|
2018-09-28 07:47:37 -07:00
|
|
|
// frequency
|
2018-08-22 12:11:19 +02:00
|
|
|
|
2018-09-28 07:47:37 -07:00
|
|
|
static_assert(2 / 1_s == 2_Hz);
|
|
|
|
static_assert(1000 / 1_s == 1_kHz);
|
2018-09-29 18:08:02 -07:00
|
|
|
static_assert(1 / 1_ms == 1_kHz);
|
2018-09-28 07:47:37 -07:00
|
|
|
static_assert(3.2_GHz == 3'200'000'000_Hz);
|
2018-08-22 12:11:19 +02:00
|
|
|
|
2018-09-28 07:47:37 -07:00
|
|
|
// time
|
2018-08-22 12:11:19 +02:00
|
|
|
|
2018-09-28 07:47:37 -07:00
|
|
|
static_assert(1_h == 3600_s);
|
2018-08-22 12:11:19 +02:00
|
|
|
|
2018-09-28 07:47:37 -07:00
|
|
|
// length
|
2018-08-22 12:11:19 +02:00
|
|
|
|
2018-09-28 07:47:37 -07:00
|
|
|
static_assert(1_km == 1000_m);
|
2019-04-09 13:34:55 +02:00
|
|
|
static_assert(1_m == 100_cm);
|
|
|
|
static_assert(1_m == 1000_mm);
|
2018-09-28 07:47:37 -07:00
|
|
|
static_assert(1_km + 1_m == 1001_m);
|
|
|
|
static_assert(10_km / 5_km == 2);
|
|
|
|
static_assert(10_km / 2 == 5_km);
|
2018-08-22 12:11:19 +02:00
|
|
|
|
2019-04-09 13:34:55 +02:00
|
|
|
static_assert(1_yd == 0.9144_m);
|
|
|
|
static_assert(1_yd == 3_ft);
|
|
|
|
static_assert(1_ft == 12_in);
|
|
|
|
static_assert(1_mi == 1760_yd);
|
|
|
|
|
2018-10-19 13:02:58 +02:00
|
|
|
// static_assert(5_in + 8_cm == 207_mm);
|
2018-10-16 15:39:39 +02:00
|
|
|
|
2018-09-28 07:47:37 -07:00
|
|
|
// velocity
|
2018-08-22 12:11:19 +02:00
|
|
|
|
2018-09-29 18:08:02 -07:00
|
|
|
static_assert(std::is_same_v<decltype(1_km / 1_s), velocity<unit<dimension_velocity, std::ratio<1000, 1>>, long long int>>);
|
2018-08-22 12:11:19 +02:00
|
|
|
|
2018-09-28 07:47:37 -07:00
|
|
|
static_assert(10_m / 5_s == 2_mps);
|
|
|
|
static_assert(10 / 5_s * 1_m == 2_mps);
|
|
|
|
static_assert(1_km / 1_s == 1000_mps);
|
|
|
|
// static_assert(1_km / 1_h == 1_kmph); // should not compile
|
|
|
|
static_assert(1.0_km / 1_h == 1_kmph);
|
|
|
|
static_assert(1000.0_m / 3600.0_s == 1_kmph);
|
2018-08-22 12:11:19 +02:00
|
|
|
|
2019-04-09 13:34:55 +02:00
|
|
|
static_assert(10.0_mi / 2_h == 5_mph);
|
|
|
|
|
2018-09-28 07:47:37 -07:00
|
|
|
static_assert(2_kmph * 2_h == 4_km);
|
|
|
|
// static_assert(2_kmph * 15_min == 500_m); // should not compile
|
|
|
|
static_assert(2_kmph * 15.0_min == 500_m);
|
|
|
|
static_assert(2.0_kmph * 15_min == 500_m);
|
2018-08-22 12:11:19 +02:00
|
|
|
|
2018-09-28 07:47:37 -07:00
|
|
|
static_assert(2_km / 2_kmph == 1_h);
|
|
|
|
// static_assert(2000_m / 2_kmph == 1_h); // should not compile
|
2018-09-29 18:08:02 -07:00
|
|
|
static_assert(quantity_cast<length<kilometer, int>>(2000_m) / 2_kmph == 1_h);
|
2018-08-22 12:11:19 +02:00
|
|
|
|
2018-09-28 07:47:37 -07:00
|
|
|
} // namespace
|