2019-12-11 16:20:08 +01: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.
2021-03-16 12:03:25 +01:00
#include <units/isq/si/acceleration.h>
2021-03-30 13:21:05 +02:00
#include <units/isq/si/area.h> // IWYU pragma: keep
#include <units/isq/si/cgs/cgs.h>
2021-03-16 12:03:25 +01:00
#include <units/isq/si/energy.h>
#include <units/isq/si/force.h>
2021-03-30 13:21:05 +02:00
#include <units/isq/si/length.h> // IWYU pragma: keep
2021-03-16 12:03:25 +01:00
#include <units/isq/si/mass.h>
#include <units/isq/si/power.h>
#include <units/isq/si/pressure.h>
#include <units/isq/si/speed.h>
2021-03-30 13:21:05 +02:00
#include <units/isq/si/time.h> // IWYU pragma: keep
2019-12-11 16:20:08 +01:00
namespace {
2021-03-16 12:03:25 +01:00
using namespace units :: isq ;
2019-12-11 16:20:08 +01:00
2021-02-21 15:49:57 -04:00
static_assert ( units :: detail :: quantity_ratio < si :: length < si :: metre >> == units :: ratio ( 1 ));
static_assert ( units :: detail :: quantity_ratio < si :: cgs :: length < si :: cgs :: centimetre >> == units :: ratio ( 1 , 100 ));
static_assert ( units :: detail :: quantity_ratio < si :: speed < si :: metre_per_second >> == units :: ratio ( 1 ));
static_assert ( units :: detail :: quantity_ratio < si :: cgs :: speed < si :: cgs :: centimetre_per_second >> == units :: ratio ( 1 , 100 ));
static_assert ( units :: detail :: quantity_ratio < si :: force < si :: newton >> == units :: ratio ( 1000 )); // defined in terms of kilogram that are 1000 * gram
static_assert ( units :: detail :: quantity_ratio < si :: cgs :: force < si :: cgs :: dyne >> == units :: ratio ( 1 , 100 )); // defined in terms of gram so only centimetre ratio counts here
2020-05-08 10:50:34 +02:00
2020-09-10 17:14:33 +02:00
static_assert ( si :: cgs :: length < si :: cgs :: centimetre > ( 100 ) == si :: length < si :: metre > ( 1 ));
static_assert ( si :: cgs :: mass < si :: cgs :: gram > ( 1'000 ) == si :: mass < si :: kilogram > ( 1 ));
static_assert ( si :: cgs :: time < si :: cgs :: second > ( 1 ) == si :: time < si :: second > ( 1 ));
static_assert ( si :: cgs :: speed < si :: cgs :: centimetre_per_second > ( 100 ) == si :: speed < si :: metre_per_second > ( 1 ));
static_assert ( si :: cgs :: area < si :: cgs :: square_centimetre > ( 10000 ) == si :: area < si :: square_metre > ( 1 ));
static_assert ( si :: cgs :: acceleration < si :: cgs :: gal > ( 100 ) == si :: acceleration < si :: metre_per_second_sq > ( 1 ));
static_assert ( si :: cgs :: force < si :: cgs :: dyne > ( 100'000 ) == si :: force < si :: newton > ( 1 ));
static_assert ( si :: cgs :: energy < si :: cgs :: erg > ( 10'000'000 ) == si :: energy < si :: joule > ( 1 ));
static_assert ( si :: cgs :: power < si :: cgs :: erg_per_second > ( 10'000'000 ) == si :: power < si :: watt > ( 1 ));
static_assert ( si :: cgs :: pressure < si :: cgs :: barye > ( 10 ) == si :: pressure < si :: pascal > ( 1 ));
2019-12-11 16:20:08 +01:00
namespace si_test {
2021-03-16 12:03:25 +01:00
using namespace units :: isq :: si :: literals ;
2019-12-11 16:20:08 +01:00
2020-09-10 17:14:33 +02:00
static_assert ( si :: cgs :: length < si :: cgs :: centimetre > ( 100 ) == 1 _q_m );
static_assert ( si :: cgs :: mass < si :: cgs :: gram > ( 1'000 ) == 1 _q_kg );
static_assert ( si :: cgs :: time < si :: cgs :: second > ( 1 ) == 1 _q_s );
static_assert ( si :: cgs :: speed < si :: cgs :: centimetre_per_second > ( 100 ) == 1 _q_m_per_s );
static_assert ( si :: cgs :: acceleration < si :: cgs :: gal > ( 100 ) == 1 _q_m_per_s2 );
static_assert ( si :: cgs :: force < si :: cgs :: dyne > ( 100'000 ) == 1 _q_N );
static_assert ( si :: cgs :: energy < si :: cgs :: erg > ( 10'000'000 ) == 1 _q_J );
static_assert ( si :: cgs :: power < si :: cgs :: erg_per_second > ( 10'000'000 ) == 1 _q_W );
static_assert ( si :: cgs :: pressure < si :: cgs :: barye > ( 10 ) == 1 _q_Pa );
2019-12-11 16:20:08 +01:00
}
namespace cgs_test {
2021-03-16 12:03:25 +01:00
using namespace units :: isq :: si :: cgs :: literals ;
2019-12-11 16:20:08 +01:00
2020-09-09 19:20:35 +02:00
static_assert ( 100 _q_cm == si :: length < si :: metre > ( 1 ));
static_assert ( 1'000 _q_g == si :: mass < si :: kilogram > ( 1 ));
static_assert ( 1 _q_s == si :: time < si :: second > ( 1 ));
static_assert ( 100 _q_cm_per_s == si :: speed < si :: metre_per_second > ( 1 ));
static_assert ( 100 _q_Gal == si :: acceleration < si :: metre_per_second_sq > ( 1 ));
static_assert ( 100'000 _q_dyn == si :: force < si :: newton > ( 1 ));
static_assert ( 10'000'000 _q_erg == si :: energy < si :: joule > ( 1 ));
static_assert ( 10'000'000 _q_erg_per_s == si :: power < si :: watt > ( 1 ));
static_assert ( 10 _q_Ba == si :: pressure < si :: pascal > ( 1 ));
2019-12-11 16:20:08 +01:00
}
namespace both_test {
2021-03-16 12:03:25 +01:00
using namespace units :: isq :: si :: literals ;
using namespace units :: isq :: si :: cgs :: literals ;
2019-12-11 16:20:08 +01:00
2020-09-09 19:20:35 +02:00
// static_assert(100_q_cm == 1_q_m); // ambiguous
// static_assert(1'000_q_g == 1_q_kg); // ambiguous
static_assert ( 1 _q_s == 1 _q_s );
static_assert ( 100 _q_cm_per_s == 1 _q_m_per_s );
static_assert ( 100 _q_Gal == 1 _q_m_per_s2 );
static_assert ( 100'000 _q_dyn == 1 _q_N );
static_assert ( 10'000'000 _q_erg == 1 _q_J );
static_assert ( 10'000'000 _q_erg_per_s == 1 _q_W );
static_assert ( 10 _q_Ba == quantity_cast < double > ( 1 _q_Pa ));
2019-12-11 16:20:08 +01:00
}
2019-12-12 15:37:52 +01:00
namespace cgs_test {
// addition
2020-09-09 19:20:35 +02:00
// static_assert(100_q_cm + si::length<si::metre>(1) == si::length<si::metre>(2)); // should not compile (different dimensions)
// static_assert(si::length<si::metre>(1) + 100_q_cm == si::length<si::metre>(2)); // should not compile (different dimensions)
static_assert ( quantity_cast < si :: length < si :: metre >> ( 100 _q_cm ) + si :: length < si :: metre > ( 1 ) == si :: length < si :: metre > ( 2 ));
static_assert ( si :: length < si :: metre > ( 1 ) + quantity_cast < si :: length < si :: metre >> ( 100 _q_cm ) == si :: length < si :: metre > ( 2 ));
2020-09-10 17:14:33 +02:00
static_assert ( 100 _q_cm + quantity_cast < si :: cgs :: length < si :: cgs :: centimetre >> ( si :: length < si :: metre > ( 1 )) == 200 _q_cm );
static_assert ( quantity_cast < si :: cgs :: length < si :: cgs :: centimetre >> ( si :: length < si :: metre > ( 1 )) + 100 _q_cm == 200 _q_cm );
2019-12-12 15:37:52 +01:00
// substraction
2020-09-09 19:20:35 +02:00
// static_assert(500_q_cm - si::length<si::metre>(1) == si::length<si::metre>(4)); // should not compile (different dimensions)
// static_assert(si::length<si::metre>(5) - 100_q_cm == si::length<si::metre>(4)); // should not compile (different dimensions)
static_assert ( quantity_cast < si :: length < si :: metre >> ( 500 _q_cm ) - si :: length < si :: metre > ( 1 ) == si :: length < si :: metre > ( 4 ));
static_assert ( si :: length < si :: metre > ( 5 ) - quantity_cast < si :: length < si :: metre >> ( 100 _q_cm ) == si :: length < si :: metre > ( 4 ));
2020-09-10 17:14:33 +02:00
static_assert ( 500 _q_cm - quantity_cast < si :: cgs :: length < si :: cgs :: centimetre >> ( si :: length < si :: metre > ( 1 )) == 400 _q_cm );
static_assert ( quantity_cast < si :: cgs :: length < si :: cgs :: centimetre >> ( si :: length < si :: metre > ( 5 )) - 100 _q_cm == 400 _q_cm );
2019-12-12 15:37:52 +01:00
// multiplication
2020-09-09 19:20:35 +02:00
// static_assert(200_q_cm * si::length<si::metre>(2) == si::area<si::square_metre>(4)); // should not compile (unknown dimension)
2019-12-12 15:37:52 +01:00
2020-09-09 19:20:35 +02:00
static_assert ( quantity_cast < si :: dim_length > ( 200. _q_cm ) * si :: length < si :: metre > ( 2 ) == si :: area < si :: square_metre > ( 4 ));
2020-09-10 17:14:33 +02:00
static_assert ( 200. _q_cm * quantity_cast < si :: cgs :: dim_length > ( si :: length < si :: metre > ( 2 )) == 40'000 _q_cm2 );
2019-12-12 15:37:52 +01:00
// TODO Add support for quantity_cast on an unknown_dimension?
2020-09-09 19:20:35 +02:00
// static_assert(quantity_cast<si::area<si::square_metre>>(200_q_cm * si::length<si::metre>(2)) == si::area<si::square_metre>(4));
// static_assert(quantity_cast<si::dim_area>(200_q_cm * si::length<si::metre>(2)) == si::area<si::square_metre>(4));
2020-09-10 17:14:33 +02:00
// static_assert(quantity_cast<si::cgs::area<si::cgs::square_centimeters>>(200_q_cm * si::length<si::metre>(2)) == 40'000_q_cm2);
// static_assert(quantity_cast<si::cgs::dim_area>(200_q_cm * si::length<si::metre>(2)) == 40'000_q_cm2);
2019-12-12 15:37:52 +01:00
// division
2020-09-09 19:20:35 +02:00
// static_assert(si::area<si::square_metre>(4) / 200_q_cm == si::length<si::metre>(2)); // should not compile (unknown dimension)
2019-12-12 15:37:52 +01:00
2020-09-09 19:20:35 +02:00
static_assert ( si :: area < si :: square_metre > ( 4 ) / quantity_cast < si :: length < si :: metre >> ( 200 _q_cm ) == si :: length < si :: metre > ( 2 ));
2020-09-10 17:14:33 +02:00
static_assert ( quantity_cast < si :: cgs :: area < si :: cgs :: square_centimetre >> ( si :: area < si :: square_metre > ( 4 )) / 200. _q_cm == 200 _q_cm );
2019-12-12 15:37:52 +01:00
2019-12-11 16:20:08 +01:00
}
2019-12-12 15:37:52 +01:00
}