mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-03 20:34:26 +02:00
Concepts-related hacks added to import them to std namespace
This commit is contained in:
@@ -30,7 +30,7 @@ namespace units {
|
||||
template<> struct upcasting_traits<upcast_from<dimension_area>> : upcast_to<dimension_area> {};
|
||||
|
||||
template<typename T>
|
||||
concept bool Area = Quantity<T> && std::experimental::ranges::Same<typename T::dimension, dimension_area>;
|
||||
concept bool Area = Quantity<T> && std::Same<typename T::dimension, dimension_area>;
|
||||
|
||||
template<Unit U = struct square_meter, Number Rep = double>
|
||||
using area = quantity<dimension_area, U, Rep>;
|
||||
|
@@ -22,13 +22,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <experimental/ranges/concepts>
|
||||
#include <units/bits/hacks.h>
|
||||
|
||||
namespace units {
|
||||
|
||||
template<typename T>
|
||||
concept bool Number = std::experimental::ranges::Regular<T> &&
|
||||
std::experimental::ranges::StrictTotallyOrdered<T> &&
|
||||
concept bool Number = std::Regular<T> &&
|
||||
std::StrictTotallyOrdered<T> &&
|
||||
requires(T a, T b) {
|
||||
{ a + b } -> T;
|
||||
{ a - b } -> T;
|
||||
|
@@ -22,12 +22,23 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <experimental/ranges/concepts>
|
||||
|
||||
namespace std {
|
||||
|
||||
// type_identity
|
||||
template<typename T>
|
||||
struct type_identity { using type = T; };
|
||||
|
||||
template<typename T>
|
||||
using type_identity_t = typename type_identity<T>::type;
|
||||
|
||||
}
|
||||
// concepts
|
||||
using experimental::ranges::Same;
|
||||
using experimental::ranges::Integral;
|
||||
using experimental::ranges::DerivedFrom;
|
||||
using experimental::ranges::Regular;
|
||||
using experimental::ranges::StrictTotallyOrdered;
|
||||
using experimental::ranges::ConvertibleTo;
|
||||
|
||||
}
|
@@ -23,7 +23,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <units/bits/hacks.h>
|
||||
#include <experimental/ranges/concepts>
|
||||
#include <type_traits>
|
||||
|
||||
namespace units {
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace units {
|
||||
requires {
|
||||
typename T::base_type;
|
||||
} &&
|
||||
std::experimental::ranges::DerivedFrom<T, upcast_base<typename T::base_type>>;
|
||||
std::DerivedFrom<T, upcast_base<typename T::base_type>>;
|
||||
|
||||
template<Upcastable T>
|
||||
using upcast_from = typename T::base_type;
|
||||
|
@@ -31,7 +31,7 @@ namespace units {
|
||||
template<> struct upcasting_traits<upcast_from<dimension_current>> : upcast_to<dimension_current> {};
|
||||
|
||||
template<typename T>
|
||||
concept bool Current = Quantity<T> && std::experimental::ranges::Same<typename T::dimension, dimension_current>;
|
||||
concept bool Current = Quantity<T> && std::Same<typename T::dimension, dimension_current>;
|
||||
|
||||
template<Unit U = struct ampere, Number Rep = double>
|
||||
using current = quantity<dimension_current, U, Rep>;
|
||||
|
@@ -22,8 +22,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <units/bits/upcasting.h>
|
||||
#include <units/bits/type_list.h>
|
||||
#include <units/bits/upcasting.h>
|
||||
|
||||
namespace units {
|
||||
|
||||
@@ -91,11 +91,13 @@ namespace units {
|
||||
|
||||
// is_dimension
|
||||
namespace detail {
|
||||
|
||||
template<typename T>
|
||||
inline constexpr bool is_dimension = false;
|
||||
|
||||
template<Exponent... Es>
|
||||
inline constexpr bool is_dimension<dimension<Es...>> = true;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<typename T>
|
||||
|
@@ -31,7 +31,7 @@ namespace units {
|
||||
template<> struct upcasting_traits<upcast_from<dimension_frequency>> : upcast_to<dimension_frequency> {};
|
||||
|
||||
template<typename T>
|
||||
concept bool Frequency = Quantity<T> && std::experimental::ranges::Same<typename T::dimension, dimension_frequency>;
|
||||
concept bool Frequency = Quantity<T> && std::Same<typename T::dimension, dimension_frequency>;
|
||||
|
||||
template<Unit U = struct hertz, Number Rep = double>
|
||||
using frequency = quantity<dimension_frequency, U, Rep>;
|
||||
|
@@ -31,7 +31,7 @@ namespace units {
|
||||
template<> struct upcasting_traits<upcast_from<dimension_length>> : upcast_to<dimension_length> {};
|
||||
|
||||
template<typename T>
|
||||
concept bool Length = Quantity<T> && std::experimental::ranges::Same<typename T::dimension, dimension_length>;
|
||||
concept bool Length = Quantity<T> && std::Same<typename T::dimension, dimension_length>;
|
||||
|
||||
template<Unit U = struct meter, Number Rep = double>
|
||||
using length = quantity<dimension_length, U, Rep>;
|
||||
|
@@ -31,7 +31,7 @@ namespace units {
|
||||
template<> struct upcasting_traits<upcast_from<dimension_luminous_intensity>> : upcast_to<dimension_luminous_intensity> {};
|
||||
|
||||
template<typename T>
|
||||
concept bool LuminousIntensity = Quantity<T> && std::experimental::ranges::Same<typename T::dimension, dimension_luminous_intensity>;
|
||||
concept bool LuminousIntensity = Quantity<T> && std::Same<typename T::dimension, dimension_luminous_intensity>;
|
||||
|
||||
template<Unit U = struct candela, Number Rep = double>
|
||||
using luminous_intensity = quantity<dimension_luminous_intensity, U, Rep>;
|
||||
|
@@ -31,7 +31,7 @@ namespace units {
|
||||
template<> struct upcasting_traits<upcast_from<dimension_mass>> : upcast_to<dimension_mass> {};
|
||||
|
||||
template<typename T>
|
||||
concept bool Mass = Quantity<T> && std::experimental::ranges::Same<typename T::dimension, dimension_mass>;
|
||||
concept bool Mass = Quantity<T> && std::Same<typename T::dimension, dimension_mass>;
|
||||
|
||||
template<Unit U = class kilogram, Number Rep = double>
|
||||
using mass = quantity<dimension_mass, U, Rep>;
|
||||
|
@@ -32,7 +32,7 @@ namespace units {
|
||||
// is_quantity
|
||||
|
||||
template<Dimension D, Unit U, Number Rep>
|
||||
requires std::experimental::ranges::Same<D, typename U::dimension>
|
||||
requires std::Same<D, typename U::dimension>
|
||||
class quantity;
|
||||
|
||||
namespace detail {
|
||||
@@ -114,7 +114,7 @@ namespace units {
|
||||
} // namespace detail
|
||||
|
||||
template<Quantity To, Dimension D, Unit U, Number Rep>
|
||||
requires std::experimental::ranges::Same<typename To::dimension, D>
|
||||
requires std::Same<typename To::dimension, D>
|
||||
constexpr To quantity_cast(const quantity<D, U, Rep>& q)
|
||||
{
|
||||
using c_ratio = std::ratio_divide<typename U::ratio, typename To::unit::ratio>;
|
||||
@@ -136,7 +136,7 @@ namespace units {
|
||||
// quantity
|
||||
|
||||
template<Dimension D, Unit U, Number Rep>
|
||||
requires std::experimental::ranges::Same<D, typename U::dimension>
|
||||
requires std::Same<D, typename U::dimension>
|
||||
class quantity {
|
||||
Rep value_;
|
||||
|
||||
@@ -150,15 +150,15 @@ namespace units {
|
||||
quantity() = default;
|
||||
quantity(const quantity&) = default;
|
||||
|
||||
template<std::experimental::ranges::ConvertibleTo<rep> Rep2>
|
||||
template<std::ConvertibleTo<rep> Rep2>
|
||||
requires treat_as_floating_point<rep> || (!treat_as_floating_point<Rep2>)
|
||||
constexpr explicit quantity(const Rep2& r) : value_{static_cast<rep>(r)}
|
||||
{
|
||||
}
|
||||
|
||||
template<Quantity Q2>
|
||||
requires std::experimental::ranges::Same<dimension, typename Q2::dimension> &&
|
||||
std::experimental::ranges::ConvertibleTo<typename Q2::rep, rep> &&
|
||||
requires std::Same<dimension, typename Q2::dimension> &&
|
||||
std::ConvertibleTo<typename Q2::rep, rep> &&
|
||||
(treat_as_floating_point<rep> ||
|
||||
(std::ratio_divide<typename Q2::unit::ratio, typename unit::ratio>::den == 1 &&
|
||||
!treat_as_floating_point<typename Q2::rep>))
|
||||
|
@@ -31,7 +31,7 @@ namespace units {
|
||||
template<> struct upcasting_traits<upcast_from<dimension_substance>> : upcast_to<dimension_substance> {};
|
||||
|
||||
template<typename T>
|
||||
concept bool Substance = Quantity<T> && std::experimental::ranges::Same<typename T::dimension, dimension_substance>;
|
||||
concept bool Substance = Quantity<T> && std::Same<typename T::dimension, dimension_substance>;
|
||||
|
||||
template<Unit U = struct mole, Number Rep = double>
|
||||
using substance = quantity<dimension_substance, U, Rep>;
|
||||
|
@@ -31,7 +31,7 @@ namespace units {
|
||||
template<> struct upcasting_traits<upcast_from<dimension_temperature>> : upcast_to<dimension_temperature> {};
|
||||
|
||||
template<typename T>
|
||||
concept bool ThermodynamicTemperature = Quantity<T> && std::experimental::ranges::Same<typename T::dimension, dimension_temperature>;
|
||||
concept bool ThermodynamicTemperature = Quantity<T> && std::Same<typename T::dimension, dimension_temperature>;
|
||||
|
||||
template<Unit U = struct kelvin, Number Rep = double>
|
||||
using temperature = quantity<dimension_temperature, U, Rep>;
|
||||
|
@@ -31,7 +31,7 @@ namespace units {
|
||||
template<> struct upcasting_traits<upcast_from<dimension_time>> : upcast_to<dimension_time> {};
|
||||
|
||||
template<typename T>
|
||||
concept bool Time = Quantity<T> && std::experimental::ranges::Same<typename T::dimension, dimension_time>;
|
||||
concept bool Time = Quantity<T> && std::Same<typename T::dimension, dimension_time>;
|
||||
|
||||
template<Unit U = struct second, Number Rep = double>
|
||||
using time = quantity<dimension_time, U, Rep>;
|
||||
|
@@ -31,7 +31,7 @@ namespace units {
|
||||
template<> struct upcasting_traits<upcast_from<dimension_velocity>> : upcast_to<dimension_velocity> {};
|
||||
|
||||
template<typename T>
|
||||
concept bool Velocity = Quantity<T> && std::experimental::ranges::Same<typename T::dimension, dimension_velocity>;
|
||||
concept bool Velocity = Quantity<T> && std::Same<typename T::dimension, dimension_velocity>;
|
||||
|
||||
template<Unit U = struct meter_per_second, Number Rep = double>
|
||||
using velocity = quantity<dimension_velocity, U, Rep>;
|
||||
|
Reference in New Issue
Block a user