forked from mpusz/mp-units
refactor: DOWNCAST_MODE
renamed to UNITS_DOWNCAST_MODE
This commit is contained in:
@ -84,11 +84,11 @@ class UnitsConan(ConanFile):
|
|||||||
def _configure_cmake(self, folder="src"):
|
def _configure_cmake(self, folder="src"):
|
||||||
cmake = CMake(self)
|
cmake = CMake(self)
|
||||||
if self.options.downcast_mode == "off":
|
if self.options.downcast_mode == "off":
|
||||||
cmake.definitions["DOWNCAST_MODE"] = 0
|
cmake.definitions["UNITS_DOWNCAST_MODE"] = 0
|
||||||
elif self.options.downcast_mode == "on":
|
elif self.options.downcast_mode == "on":
|
||||||
cmake.definitions["DOWNCAST_MODE"] = 1
|
cmake.definitions["UNITS_DOWNCAST_MODE"] = 1
|
||||||
elif self.options.downcast_mode == "auto":
|
elif self.options.downcast_mode == "auto":
|
||||||
cmake.definitions["DOWNCAST_MODE"] = 2
|
cmake.definitions["UNITS_DOWNCAST_MODE"] = 2
|
||||||
|
|
||||||
if self._run_tests:
|
if self._run_tests:
|
||||||
# developer's mode (unit tests, examples, documentation, restrictive compilation warnings, ...)
|
# developer's mode (unit tests, examples, documentation, restrictive compilation warnings, ...)
|
||||||
|
@ -134,14 +134,14 @@ Specifies how :ref:`The Downcasting Facility` works:
|
|||||||
CMake Options
|
CMake Options
|
||||||
^^^^^^^^^^^^^
|
^^^^^^^^^^^^^
|
||||||
|
|
||||||
DOWNCAST_MODE
|
UNITS_DOWNCAST_MODE
|
||||||
+++++++++++++
|
+++++++++++++++++++
|
||||||
|
|
||||||
**Values**: ``OFF``/``ON``/``AUTO``
|
**Values**: ``OFF``/``ON``/``AUTO``
|
||||||
|
|
||||||
**Defaulted to**: ``ON``
|
**Defaulted to**: ``ON``
|
||||||
|
|
||||||
Equivalent to `downcast`_.
|
Equivalent to `downcast_mode`_.
|
||||||
|
|
||||||
|
|
||||||
GENERATE_DOCS
|
GENERATE_DOCS
|
||||||
|
@ -37,7 +37,7 @@ int main()
|
|||||||
using namespace units::physical::si::literals;
|
using namespace units::physical::si::literals;
|
||||||
Speed auto v1 = avg_speed(220_q_km, 2_q_h);
|
Speed auto v1 = avg_speed(220_q_km, 2_q_h);
|
||||||
Speed auto v2 = avg_speed(si::length<si::international::mile>(140), si::time<si::hour>(2));
|
Speed auto v2 = avg_speed(si::length<si::international::mile>(140), si::time<si::hour>(2));
|
||||||
#if DOWNCAST_MODE == 0
|
#if UNITS_DOWNCAST_MODE == 0
|
||||||
Speed auto v3 = quantity_cast<si::dim_speed, si::metre_per_second>(v2);
|
Speed auto v3 = quantity_cast<si::dim_speed, si::metre_per_second>(v2);
|
||||||
#else
|
#else
|
||||||
Speed auto v3 = quantity_cast<si::metre_per_second>(v2);
|
Speed auto v3 = quantity_cast<si::metre_per_second>(v2);
|
||||||
|
@ -131,7 +131,7 @@ void example()
|
|||||||
const auto t = si::time<si::second, measurement<double>>(measurement(1.2, 0.1));
|
const auto t = si::time<si::second, measurement<double>>(measurement(1.2, 0.1));
|
||||||
|
|
||||||
const Speed auto v1 = a * t;
|
const Speed auto v1 = a * t;
|
||||||
#if DOWNCAST_MODE == 0
|
#if UNITS_DOWNCAST_MODE == 0
|
||||||
std::cout << a << " * " << t << " = " << v1 << " = " << quantity_cast<si::dim_speed, si::kilometre_per_hour>(v1) << '\n';
|
std::cout << a << " * " << t << " = " << v1 << " = " << quantity_cast<si::dim_speed, si::kilometre_per_hour>(v1) << '\n';
|
||||||
#else
|
#else
|
||||||
std::cout << a << " * " << t << " = " << v1 << " = " << quantity_cast<si::kilometre_per_hour>(v1) << '\n';
|
std::cout << a << " * " << t << " = " << v1 << " = " << quantity_cast<si::kilometre_per_hour>(v1) << '\n';
|
||||||
|
@ -27,8 +27,8 @@ project(mp-units
|
|||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
set(DOWNCAST_MODE ON CACHE STRING "Select downcasting mode")
|
set(UNITS_DOWNCAST_MODE ON CACHE STRING "Select downcasting mode")
|
||||||
set_property(CACHE DOWNCAST_MODE PROPERTY STRINGS AUTO ON OFF)
|
set_property(CACHE UNITS_DOWNCAST_MODE PROPERTY STRINGS AUTO ON OFF)
|
||||||
|
|
||||||
# set path to custom cmake modules
|
# set path to custom cmake modules
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
|
||||||
@ -84,15 +84,15 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(DOWNCAST_MODE STREQUAL "AUTO")
|
if(UNITS_DOWNCAST_MODE STREQUAL "AUTO")
|
||||||
message(STATUS "Configuring DOWNCAST_MODE=AUTOMATIC")
|
message(STATUS "Configuring UNITS_DOWNCAST_MODE=AUTOMATIC")
|
||||||
target_compile_definitions(mp-units INTERFACE DOWNCAST_MODE=2)
|
target_compile_definitions(mp-units INTERFACE UNITS_DOWNCAST_MODE=2)
|
||||||
elseif(DOWNCAST_MODE)
|
elseif(UNITS_DOWNCAST_MODE)
|
||||||
message(STATUS "Configuring DOWNCAST_MODE=ON")
|
message(STATUS "Configuring UNITS_DOWNCAST_MODE=ON")
|
||||||
target_compile_definitions(mp-units INTERFACE DOWNCAST_MODE=1)
|
target_compile_definitions(mp-units INTERFACE UNITS_DOWNCAST_MODE=1)
|
||||||
else()
|
else()
|
||||||
message(STATUS "Configuring DOWNCAST_MODE=OFF")
|
message(STATUS "Configuring UNITS_DOWNCAST_MODE=OFF")
|
||||||
target_compile_definitions(mp-units INTERFACE DOWNCAST_MODE=0)
|
target_compile_definitions(mp-units INTERFACE UNITS_DOWNCAST_MODE=0)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_library(mp-units::mp-units ALIAS mp-units)
|
add_library(mp-units::mp-units ALIAS mp-units)
|
||||||
|
10
src/include/units/bits/external/downcasting.h
vendored
10
src/include/units/bits/external/downcasting.h
vendored
@ -25,12 +25,12 @@
|
|||||||
#include <units/bits/external/hacks.h>
|
#include <units/bits/external/hacks.h>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#ifdef DOWNCAST_MODE
|
#ifdef UNITS_DOWNCAST_MODE
|
||||||
#if DOWNCAST_MODE < 0 || DOWNCAST_MODE > 2
|
#if UNITS_DOWNCAST_MODE < 0 || UNITS_DOWNCAST_MODE > 2
|
||||||
#error "Invalid DOWNCAST_MODE value"
|
#error "Invalid UNITS_DOWNCAST_MODE value"
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#define DOWNCAST_MODE 1
|
#define UNITS_DOWNCAST_MODE 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace units {
|
namespace units {
|
||||||
@ -72,7 +72,7 @@ enum class downcast_mode {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<typename Target, Downcastable T, downcast_mode mode = static_cast<downcast_mode>(DOWNCAST_MODE)>
|
template<typename Target, Downcastable T, downcast_mode mode = static_cast<downcast_mode>(UNITS_DOWNCAST_MODE)>
|
||||||
struct downcast_dispatch : std::conditional_t<mode == downcast_mode::off, T,
|
struct downcast_dispatch : std::conditional_t<mode == downcast_mode::off, T,
|
||||||
#ifdef COMP_MSVC
|
#ifdef COMP_MSVC
|
||||||
downcast_child<Target, T>> {};
|
downcast_child<Target, T>> {};
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
namespace units {
|
namespace units {
|
||||||
|
|
||||||
// DimensionOfT
|
// DimensionOfT
|
||||||
#if DOWNCAST_MODE == 0
|
#if UNITS_DOWNCAST_MODE == 0
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ concept EquivalentUnknownDimensionOfT = Dimension<Dim> && is_derived_from_specia
|
|||||||
*/
|
*/
|
||||||
template<typename Dim, template<typename...> typename DimTemplate>
|
template<typename Dim, template<typename...> typename DimTemplate>
|
||||||
concept DimensionOfT = Dimension<Dim> && (is_derived_from_specialization_of<Dim, DimTemplate>
|
concept DimensionOfT = Dimension<Dim> && (is_derived_from_specialization_of<Dim, DimTemplate>
|
||||||
#if DOWNCAST_MODE == 0
|
#if UNITS_DOWNCAST_MODE == 0
|
||||||
|| EquivalentUnknownDimensionOfT<Dim, DimTemplate>
|
|| EquivalentUnknownDimensionOfT<Dim, DimTemplate>
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
|
@ -459,7 +459,7 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]")
|
|||||||
|
|
||||||
SECTION("percents")
|
SECTION("percents")
|
||||||
{
|
{
|
||||||
#if DOWNCAST_MODE == 0
|
#if UNITS_DOWNCAST_MODE == 0
|
||||||
const auto q = quantity_cast<dim_one, percent>(15._q_m / 100._q_m);
|
const auto q = quantity_cast<dim_one, percent>(15._q_m / 100._q_m);
|
||||||
#else
|
#else
|
||||||
const auto q = quantity_cast<percent>(15._q_m / 100._q_m);
|
const auto q = quantity_cast<percent>(15._q_m / 100._q_m);
|
||||||
|
@ -57,7 +57,7 @@ static_assert(!Area<si::time<si::second>>);
|
|||||||
|
|
||||||
static_assert(Volume<si::volume<si::cubic_metre>>);
|
static_assert(Volume<si::volume<si::cubic_metre>>);
|
||||||
static_assert(!Volume<si::area<si::square_metre>>);
|
static_assert(!Volume<si::area<si::square_metre>>);
|
||||||
#if DOWNCAST_MODE == 0
|
#if UNITS_DOWNCAST_MODE == 0
|
||||||
static_assert(Volume<quantity<unknown_dimension<exponent<si::dim_length, 3>>, unknown_coherent_unit>>);
|
static_assert(Volume<quantity<unknown_dimension<exponent<si::dim_length, 3>>, unknown_coherent_unit>>);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -66,19 +66,19 @@ static_assert(!Speed<si::time<si::second>>);
|
|||||||
|
|
||||||
static_assert(Acceleration<si::acceleration<si::metre_per_second_sq>>);
|
static_assert(Acceleration<si::acceleration<si::metre_per_second_sq>>);
|
||||||
static_assert(!Acceleration<si::time<si::second>>);
|
static_assert(!Acceleration<si::time<si::second>>);
|
||||||
#if DOWNCAST_MODE == 0
|
#if UNITS_DOWNCAST_MODE == 0
|
||||||
static_assert(Acceleration<quantity<unknown_dimension<exponent<si::dim_length, 1>, exponent<si::dim_time, -2>>, unknown_coherent_unit>>);
|
static_assert(Acceleration<quantity<unknown_dimension<exponent<si::dim_length, 1>, exponent<si::dim_time, -2>>, unknown_coherent_unit>>);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static_assert(Force<si::force<si::newton>>);
|
static_assert(Force<si::force<si::newton>>);
|
||||||
static_assert(!Force<si::time<si::second>>);
|
static_assert(!Force<si::time<si::second>>);
|
||||||
#if DOWNCAST_MODE == 0
|
#if UNITS_DOWNCAST_MODE == 0
|
||||||
// static_assert(Force<quantity<unknown_dimension<exponent<si::dim_length, 1>, exponent<si::dim_time, -2>, exponent<si::dim_mass, 1>>, unknown_coherent_unit>>);
|
// static_assert(Force<quantity<unknown_dimension<exponent<si::dim_length, 1>, exponent<si::dim_time, -2>, exponent<si::dim_mass, 1>>, unknown_coherent_unit>>);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static_assert(Energy<si::energy<si::joule>>);
|
static_assert(Energy<si::energy<si::joule>>);
|
||||||
static_assert(!Energy<si::time<si::second>>);
|
static_assert(!Energy<si::time<si::second>>);
|
||||||
#if DOWNCAST_MODE == 0
|
#if UNITS_DOWNCAST_MODE == 0
|
||||||
// static_assert(Energy<quantity<unknown_dimension<exponent<si::dim_mass, 1>, exponent<si::dim_length, 2>, exponent<si::dim_time, -3>>, unknown_coherent_unit>>);
|
// static_assert(Energy<quantity<unknown_dimension<exponent<si::dim_mass, 1>, exponent<si::dim_length, 2>, exponent<si::dim_time, -3>>, unknown_coherent_unit>>);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ static_assert(q1.count() == 2);
|
|||||||
constexpr dimensionless<one> q2 = q1;
|
constexpr dimensionless<one> q2 = q1;
|
||||||
static_assert(q2.count() == 2000);
|
static_assert(q2.count() == 2000);
|
||||||
|
|
||||||
#if DOWNCAST_MODE == 0
|
#if UNITS_DOWNCAST_MODE == 0
|
||||||
static_assert(quantity_cast<dim_one, one>(q1).count() == 2000);
|
static_assert(quantity_cast<dim_one, one>(q1).count() == 2000);
|
||||||
#else
|
#else
|
||||||
static_assert(quantity_cast<one>(q1).count() == 2000);
|
static_assert(quantity_cast<one>(q1).count() == 2000);
|
||||||
@ -310,7 +310,7 @@ static_assert(invalid_dimensionless_operations<int>);
|
|||||||
|
|
||||||
static_assert(compare<decltype(10_q_km / 5_q_km), quantity<dim_one, one, std::int64_t>>);
|
static_assert(compare<decltype(10_q_km / 5_q_km), quantity<dim_one, one, std::int64_t>>);
|
||||||
|
|
||||||
#if DOWNCAST_MODE == 0
|
#if UNITS_DOWNCAST_MODE == 0
|
||||||
static_assert(quantity_cast<dim_one, percent>(50._q_m / 100._q_m).count() == 50);
|
static_assert(quantity_cast<dim_one, percent>(50._q_m / 100._q_m).count() == 50);
|
||||||
#else
|
#else
|
||||||
static_assert(quantity_cast<percent>(50._q_m / 100._q_m).count() == 50);
|
static_assert(quantity_cast<percent>(50._q_m / 100._q_m).count() == 50);
|
||||||
@ -347,7 +347,7 @@ static_assert(compare<decltype(pow<2>(2_q_m)), decltype(4_q_m2)>);
|
|||||||
|
|
||||||
// downcasting
|
// downcasting
|
||||||
|
|
||||||
#if DOWNCAST_MODE == 0
|
#if UNITS_DOWNCAST_MODE == 0
|
||||||
|
|
||||||
static_assert(std::is_same_v<decltype(10_q_m / 5_q_s), quantity<unknown_dimension<units::exponent<dim_length, 1>, units::exponent<dim_time, -1>>, scaled_unit<ratio(1), unknown_coherent_unit>, std::int64_t>>);
|
static_assert(std::is_same_v<decltype(10_q_m / 5_q_s), quantity<unknown_dimension<units::exponent<dim_length, 1>, units::exponent<dim_time, -1>>, scaled_unit<ratio(1), unknown_coherent_unit>, std::int64_t>>);
|
||||||
static_assert(std::is_same_v<decltype(1_q_mm + 1_q_km), length<scaled_unit<ratio(1, 1, -3), metre>, std::int64_t>>);
|
static_assert(std::is_same_v<decltype(1_q_mm + 1_q_km), length<scaled_unit<ratio(1, 1, -3), metre>, std::int64_t>>);
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include "units/bits/equivalent.h"
|
#include "units/bits/equivalent.h"
|
||||||
|
|
||||||
template<typename T, typename U>
|
template<typename T, typename U>
|
||||||
inline constexpr bool compare_impl = DOWNCAST_MODE != 0 ? std::is_same_v<T, U> : (std::is_same_v<T, U> || units::equivalent<T, U>);
|
inline constexpr bool compare_impl = UNITS_DOWNCAST_MODE != 0 ? std::is_same_v<T, U> : (std::is_same_v<T, U> || units::equivalent<T, U>);
|
||||||
|
|
||||||
template<typename T, typename U>
|
template<typename T, typename U>
|
||||||
inline constexpr bool compare = compare_impl<std::remove_cvref_t<T>, std::remove_cvref_t<U>>;
|
inline constexpr bool compare = compare_impl<std::remove_cvref_t<T>, std::remove_cvref_t<U>>;
|
||||||
|
Reference in New Issue
Block a user