refactor: modules support redesigned
This commit is contained in:
1 parent
b582e200a0
commit
0eaf6e2e56
129 files changed
+271
-838
No files matched your search
+58
-51
@@ -28,60 +28,67 @@ if(NOT TARGET gsl::gsl-lite)
|
||||
endif()
|
||||
|
||||
# core library definition
|
||||
add_library(
|
||||
mp-units-core
|
||||
INTERFACE
|
||||
include/mp-units/bits/external/algorithm.h
|
||||
include/mp-units/bits/external/fixed_string.h
|
||||
include/mp-units/bits/external/math_concepts.h
|
||||
include/mp-units/bits/external/prime.h
|
||||
include/mp-units/bits/external/type_list.h
|
||||
include/mp-units/bits/external/type_name.h
|
||||
include/mp-units/bits/external/type_traits.h
|
||||
include/mp-units/bits/dimension_concepts.h
|
||||
include/mp-units/bits/expression_template.h
|
||||
include/mp-units/bits/get_associated_quantity.h
|
||||
include/mp-units/bits/get_common_base.h
|
||||
include/mp-units/bits/magnitude.h
|
||||
include/mp-units/bits/quantity_cast.h
|
||||
include/mp-units/bits/quantity_concepts.h
|
||||
include/mp-units/bits/quantity_point_concepts.h
|
||||
include/mp-units/bits/quantity_spec_concepts.h
|
||||
include/mp-units/bits/ratio.h
|
||||
include/mp-units/bits/reference_concepts.h
|
||||
include/mp-units/bits/representation_concepts.h
|
||||
include/mp-units/bits/sudo_cast.h
|
||||
include/mp-units/bits/symbol_text.h
|
||||
include/mp-units/bits/text_tools.h
|
||||
include/mp-units/bits/unit_concepts.h
|
||||
include/mp-units/bits/value_cast.h
|
||||
include/mp-units/concepts.h
|
||||
include/mp-units/core.h
|
||||
include/mp-units/customization_points.h
|
||||
include/mp-units/dimension.h
|
||||
include/mp-units/quantity.h
|
||||
include/mp-units/quantity_point.h
|
||||
include/mp-units/quantity_spec.h
|
||||
include/mp-units/reference.h
|
||||
include/mp-units/system_reference.h
|
||||
include/mp-units/unit.h
|
||||
)
|
||||
target_link_libraries(mp-units-core INTERFACE gsl::gsl-lite mp-units::core-macros)
|
||||
target_include_directories(
|
||||
mp-units-core ${unitsAsSystem} INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
add_units_module(
|
||||
core
|
||||
DEPENDENCIES gsl::gsl-lite
|
||||
HEADERS include/mp-units/bits/external/algorithm.h
|
||||
include/mp-units/bits/external/fixed_string.h
|
||||
include/mp-units/bits/external/hacks.h
|
||||
include/mp-units/bits/external/math_concepts.h
|
||||
include/mp-units/bits/external/prime.h
|
||||
include/mp-units/bits/external/type_list.h
|
||||
include/mp-units/bits/external/type_name.h
|
||||
include/mp-units/bits/external/type_traits.h
|
||||
include/mp-units/bits/core_gmf.h
|
||||
include/mp-units/bits/dimension_concepts.h
|
||||
include/mp-units/bits/expression_template.h
|
||||
include/mp-units/bits/get_associated_quantity.h
|
||||
include/mp-units/bits/get_common_base.h
|
||||
include/mp-units/bits/magnitude.h
|
||||
include/mp-units/bits/quantity_cast.h
|
||||
include/mp-units/bits/quantity_concepts.h
|
||||
include/mp-units/bits/quantity_point_concepts.h
|
||||
include/mp-units/bits/quantity_spec_concepts.h
|
||||
include/mp-units/bits/ratio.h
|
||||
include/mp-units/bits/reference_concepts.h
|
||||
include/mp-units/bits/representation_concepts.h
|
||||
include/mp-units/bits/sudo_cast.h
|
||||
include/mp-units/bits/symbol_text.h
|
||||
include/mp-units/bits/text_tools.h
|
||||
include/mp-units/bits/unit_concepts.h
|
||||
include/mp-units/bits/value_cast.h
|
||||
include/mp-units/compare.h
|
||||
include/mp-units/compat_macros.h
|
||||
include/mp-units/concepts.h
|
||||
include/mp-units/core.h
|
||||
include/mp-units/customization_points.h
|
||||
include/mp-units/dimension.h
|
||||
include/mp-units/math.h
|
||||
include/mp-units/quantity.h
|
||||
include/mp-units/quantity_point.h
|
||||
include/mp-units/quantity_spec.h
|
||||
include/mp-units/random.h
|
||||
include/mp-units/reference.h
|
||||
include/mp-units/system_reference.h
|
||||
include/mp-units/unit.h
|
||||
MODULE_INTERFACE_UNIT mp-units-core.cpp
|
||||
)
|
||||
|
||||
if(${projectPrefix}BUILD_CXX_MODULES)
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
|
||||
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18)
|
||||
target_compile_definitions(mp-units-core PUBLIC _LIBCPP_NO_ABI_TAG)
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 18)
|
||||
target_compile_options(mp-units-core PUBLIC "-Wno-include-angled-in-module-purview")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
target_compile_options(
|
||||
mp-units-core
|
||||
INTERFACE /utf-8 # Specifies both the source character set and the execution character set as UTF-8
|
||||
mp-units-core ${${projectPrefix}TARGET_SCOPE}
|
||||
/utf-8 # Specifies both the source character set and the execution character set as UTF-8
|
||||
)
|
||||
endif()
|
||||
|
||||
set_target_properties(mp-units-core PROPERTIES EXPORT_NAME core)
|
||||
add_library(mp-units::core ALIAS mp-units-core)
|
||||
|
||||
# installation
|
||||
install(TARGETS mp-units-core EXPORT mp-unitsTargets)
|
||||
install(DIRECTORY include/mp-units TYPE INCLUDE)
|
||||
@@ -0,0 +1,50 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
// core
|
||||
#include <gsl/gsl-lite.hpp>
|
||||
#include <mp-units/bits/external/hacks.h>
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <compare>
|
||||
#include <concepts>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <numbers>
|
||||
#include <numeric>
|
||||
#include <optional>
|
||||
#include <random>
|
||||
#include <ranges>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
// si
|
||||
#include <chrono>
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#if __clang__
|
||||
#define MP_UNITS_COMP_CLANG __clang_major__
|
||||
#elif __GNUC__
|
||||
#define MP_UNITS_COMP_GCC __GNUC__
|
||||
#define MP_UNITS_COMP_GCC_MINOR __GNUC_MINOR__
|
||||
#elif _MSC_VER
|
||||
#define MP_UNITS_COMP_MSVC _MSC_VER
|
||||
#endif
|
||||
|
||||
// Adapted from https://github.com/ericniebler/range-v3/blob/master/include/range/v3/detail/config.hpp#L185.
|
||||
#define MP_UNITS_PRAGMA(X) _Pragma(#X)
|
||||
#if !MP_UNITS_COMP_MSVC
|
||||
#define MP_UNITS_DIAGNOSTIC_PUSH MP_UNITS_PRAGMA(GCC diagnostic push)
|
||||
#define MP_UNITS_DIAGNOSTIC_POP MP_UNITS_PRAGMA(GCC diagnostic pop)
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_PRAGMAS MP_UNITS_PRAGMA(GCC diagnostic ignored "-Wpragmas")
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE(X) \
|
||||
MP_UNITS_DIAGNOSTIC_IGNORE_PRAGMAS \
|
||||
MP_UNITS_PRAGMA(GCC diagnostic ignored "-Wunknown-pragmas") \
|
||||
MP_UNITS_PRAGMA(GCC diagnostic ignored "-Wunknown-warning-option") \
|
||||
MP_UNITS_PRAGMA(GCC diagnostic ignored X)
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_EXPR_ALWAYS_TF
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_FLOAT_EQUAL MP_UNITS_DIAGNOSTIC_IGNORE("-Wfloat-equal")
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_LOSS_OF_DATA
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES MP_UNITS_DIAGNOSTIC_IGNORE("-Wmissing-braces")
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_NON_TEMPLATE_FRIEND MP_UNITS_DIAGNOSTIC_IGNORE("-Wnon-template-friend")
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_SHADOW MP_UNITS_DIAGNOSTIC_IGNORE("-Wshadow")
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_ZERO_AS_NULLPOINTER_CONSTANT \
|
||||
MP_UNITS_DIAGNOSTIC_IGNORE("-Wzero-as-nullpointer-constant")
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_DEPRECATED MP_UNITS_DIAGNOSTIC_IGNORE("-Wdeprecated-declarations")
|
||||
#else
|
||||
#define MP_UNITS_DIAGNOSTIC_PUSH MP_UNITS_PRAGMA(warning(push))
|
||||
#define MP_UNITS_DIAGNOSTIC_POP MP_UNITS_PRAGMA(warning(pop))
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_PRAGMAS MP_UNITS_PRAGMA(warning(disable : 4068))
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE(X) MP_UNITS_DIAGNOSTIC_IGNORE_PRAGMAS MP_UNITS_PRAGMA(warning(disable : X))
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_EXPR_ALWAYS_TF MP_UNITS_DIAGNOSTIC_IGNORE(4296)
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_FLOAT_EQUAL
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_LOSS_OF_DATA MP_UNITS_DIAGNOSTIC_IGNORE(4244)
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_NON_TEMPLATE_FRIEND
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_SHADOW MP_UNITS_DIAGNOSTIC_IGNORE(4459)
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE MP_UNITS_DIAGNOSTIC_IGNORE(4702)
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_ZERO_AS_NULLPOINTER_CONSTANT
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_DEPRECATED
|
||||
#endif
|
||||
|
||||
#if MP_UNITS_COMP_MSVC
|
||||
|
||||
#define MP_UNITS_TYPENAME typename
|
||||
|
||||
#else
|
||||
|
||||
#define MP_UNITS_TYPENAME
|
||||
|
||||
#endif
|
||||
|
||||
#if (defined MP_UNITS_COMP_CLANG && MP_UNITS_COMP_CLANG < 17)
|
||||
|
||||
#define MP_UNITS_CONSTEVAL constexpr
|
||||
|
||||
#else
|
||||
|
||||
#define MP_UNITS_CONSTEVAL consteval
|
||||
|
||||
#endif
|
||||
|
||||
#if MP_UNITS_COMP_MSVC
|
||||
|
||||
#define MP_UNITS_CONSTRAINED_AUTO_WORKAROUND(X)
|
||||
#define MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(X)
|
||||
|
||||
#else
|
||||
|
||||
#define MP_UNITS_CONSTRAINED_AUTO_WORKAROUND(X) X
|
||||
#define MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(X) X
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,95 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <compare>
|
||||
|
||||
namespace mp_units {
|
||||
|
||||
template<typename T>
|
||||
requires requires {
|
||||
{
|
||||
T::zero()
|
||||
} -> std::equality_comparable_with<T>;
|
||||
}
|
||||
[[nodiscard]] constexpr bool is_eq_zero(T v)
|
||||
{
|
||||
return v == T::zero();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
requires requires {
|
||||
{
|
||||
T::zero()
|
||||
} -> std::equality_comparable_with<T>;
|
||||
}
|
||||
[[nodiscard]] constexpr bool is_neq_zero(T v)
|
||||
{
|
||||
return v != T::zero();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
requires requires {
|
||||
{
|
||||
T::zero()
|
||||
} -> std::three_way_comparable_with<T>;
|
||||
}
|
||||
[[nodiscard]] constexpr bool is_lt_zero(T v)
|
||||
{
|
||||
return v < T::zero();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
requires requires {
|
||||
{
|
||||
T::zero()
|
||||
} -> std::three_way_comparable_with<T>;
|
||||
}
|
||||
[[nodiscard]] constexpr bool is_gt_zero(T v)
|
||||
{
|
||||
return v > T::zero();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
requires requires {
|
||||
{
|
||||
T::zero()
|
||||
} -> std::three_way_comparable_with<T>;
|
||||
}
|
||||
[[nodiscard]] constexpr bool is_lteq_zero(T v)
|
||||
{
|
||||
return v <= T::zero();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
requires requires {
|
||||
{
|
||||
T::zero()
|
||||
} -> std::three_way_comparable_with<T>;
|
||||
}
|
||||
[[nodiscard]] constexpr bool is_gteq_zero(T v)
|
||||
{
|
||||
return v >= T::zero();
|
||||
}
|
||||
|
||||
} // namespace mp_units
|
||||
@@ -0,0 +1,39 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <mp-units/bits/external/hacks.h>
|
||||
|
||||
#ifdef __cpp_explicit_this_parameter
|
||||
|
||||
#define QUANTITY_SPEC(name, ...) \
|
||||
inline constexpr struct name : ::mp_units::quantity_spec<__VA_ARGS__> { \
|
||||
} name
|
||||
|
||||
#else
|
||||
|
||||
#define QUANTITY_SPEC(name, ...) \
|
||||
inline constexpr struct name : ::mp_units::quantity_spec<name, __VA_ARGS__> { \
|
||||
} name
|
||||
|
||||
#endif
|
||||
@@ -22,13 +22,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <mp-units/bits/math_core.h>
|
||||
#include <mp-units/compare.h>
|
||||
#include <mp-units/compat_macros.h>
|
||||
#include <mp-units/concepts.h>
|
||||
#include <mp-units/customization_points.h>
|
||||
#include <mp-units/dimension.h>
|
||||
#include <mp-units/math.h>
|
||||
#include <mp-units/quantity.h>
|
||||
#include <mp-units/quantity_point.h>
|
||||
#include <mp-units/quantity_spec.h>
|
||||
#include <mp-units/random.h>
|
||||
#include <mp-units/reference.h>
|
||||
#include <mp-units/system_reference.h>
|
||||
#include <mp-units/unit.h>
|
||||
@@ -0,0 +1,380 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <mp-units/bits/external/hacks.h>
|
||||
#include <mp-units/bits/value_cast.h>
|
||||
#include <mp-units/customization_points.h>
|
||||
#include <mp-units/quantity.h>
|
||||
#include <mp-units/unit.h>
|
||||
|
||||
// IWYU pragma: begin_exports
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
// IWYU pragma: end_exports
|
||||
|
||||
#include <limits>
|
||||
|
||||
namespace mp_units {
|
||||
|
||||
/**
|
||||
* @brief Computes the value of a quantity raised to the `Num/Den` power
|
||||
*
|
||||
* Both the quantity value and its quantity specification are the base of the operation.
|
||||
*
|
||||
* @tparam Num Exponent numerator
|
||||
* @tparam Den Exponent denominator
|
||||
* @param q Quantity being the base of the operation
|
||||
* @return Quantity The result of computation
|
||||
*/
|
||||
template<std::intmax_t Num, std::intmax_t Den = 1, auto R, typename Rep>
|
||||
requires detail::non_zero<Den> && requires(Rep v) {
|
||||
quantity_values<Rep>::one();
|
||||
requires requires { pow(v, 1.0); } || requires { std::pow(v, 1.0); };
|
||||
}
|
||||
[[nodiscard]] constexpr quantity<pow<Num, Den>(R), Rep> pow(const quantity<R, Rep>& q) noexcept
|
||||
|
||||
{
|
||||
if constexpr (Num == 0) {
|
||||
return quantity<pow<Num, Den>(R), Rep>::one();
|
||||
} else if constexpr (ratio{Num, Den} == 1) {
|
||||
return q;
|
||||
} else {
|
||||
using std::pow;
|
||||
return {
|
||||
static_cast<Rep>(pow(q.numerical_value_ref_in(q.unit), static_cast<double>(Num) / static_cast<double>(Den))),
|
||||
pow<Num, Den>(R)};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Computes the square root of a quantity
|
||||
*
|
||||
* Both the quantity value and its quantity specification are the base of the operation.
|
||||
*
|
||||
* @param q Quantity being the base of the operation
|
||||
* @return Quantity The result of computation
|
||||
*/
|
||||
template<auto R, typename Rep>
|
||||
requires requires(Rep v) { sqrt(v); } || requires(Rep v) { std::sqrt(v); }
|
||||
[[nodiscard]] constexpr quantity<sqrt(R), Rep> sqrt(const quantity<R, Rep>& q) noexcept
|
||||
{
|
||||
using std::sqrt;
|
||||
return {static_cast<Rep>(sqrt(q.numerical_value_ref_in(q.unit))), sqrt(R)};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Computes the cubic root of a quantity
|
||||
*
|
||||
* Both the quantity value and its quantity specification are the base of the operation.
|
||||
*
|
||||
* @param q Quantity being the base of the operation
|
||||
* @return Quantity The result of computation
|
||||
*/
|
||||
template<auto R, typename Rep>
|
||||
requires requires(Rep v) { cbrt(v); } || requires(Rep v) { std::cbrt(v); }
|
||||
[[nodiscard]] constexpr quantity<cbrt(R), Rep> cbrt(const quantity<R, Rep>& q) noexcept
|
||||
{
|
||||
using std::cbrt;
|
||||
return {static_cast<Rep>(cbrt(q.numerical_value_ref_in(q.unit))), cbrt(R)};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Computes Euler's raised to the given power
|
||||
*
|
||||
* @note Such an operation has sense only for a dimensionless quantity.
|
||||
*
|
||||
* @param q Quantity being the base of the operation
|
||||
* @return Quantity The value of the same quantity type
|
||||
*/
|
||||
template<ReferenceOf<dimensionless> auto R, typename Rep>
|
||||
requires requires(Rep v) { exp(v); } || requires(Rep v) { std::exp(v); }
|
||||
[[nodiscard]] constexpr quantity<R, Rep> exp(const quantity<R, Rep>& q)
|
||||
{
|
||||
using std::exp;
|
||||
return value_cast<get_unit(R)>(
|
||||
quantity{static_cast<Rep>(exp(q.force_numerical_value_in(q.unit))), detail::clone_reference_with<one>(R)});
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Computes the absolute value of a quantity
|
||||
*
|
||||
* @param q Quantity being the base of the operation
|
||||
* @return Quantity The absolute value of a provided quantity
|
||||
*/
|
||||
template<auto R, typename Rep>
|
||||
requires requires(Rep v) { abs(v); } || requires(Rep v) { std::abs(v); }
|
||||
[[nodiscard]] constexpr quantity<R, Rep> abs(const quantity<R, Rep>& q) noexcept
|
||||
{
|
||||
using std::abs;
|
||||
return {static_cast<Rep>(abs(q.numerical_value_ref_in(q.unit))), R};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Determines if a number is finite.
|
||||
*
|
||||
* @param a: Number to analyze.
|
||||
* @return bool: Whether the number is finite or not.
|
||||
*/
|
||||
template<auto R, typename Rep>
|
||||
requires requires(Rep v) { isfinite(v); } || requires(Rep v) { std::isfinite(v); }
|
||||
[[nodiscard]] constexpr bool isfinite(const quantity<R, Rep>& a) noexcept
|
||||
{
|
||||
using std::isfinite;
|
||||
return isfinite(a.numerical_value_ref_in(a.unit));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Determines if a number is infinite.
|
||||
*
|
||||
* @param a: Number to analyze.
|
||||
* @return bool: Whether the number is infinite or not.
|
||||
*/
|
||||
template<auto R, typename Rep>
|
||||
requires requires(Rep v) { isinf(v); } || requires(Rep v) { std::isinf(v); }
|
||||
[[nodiscard]] constexpr bool isinf(const quantity<R, Rep>& a) noexcept
|
||||
{
|
||||
using std::isinf;
|
||||
return isinf(a.numerical_value_ref_in(a.unit));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Determines if a number is a nan.
|
||||
*
|
||||
* @param a: Number to analyze.
|
||||
* @return bool: Whether the number is a NaN or not.
|
||||
*/
|
||||
template<auto R, typename Rep>
|
||||
requires requires(Rep v) { isnan(v); } || requires(Rep v) { std::isnan(v); }
|
||||
[[nodiscard]] constexpr bool isnan(const quantity<R, Rep>& a) noexcept
|
||||
{
|
||||
using std::isnan;
|
||||
return isnan(a.numerical_value_ref_in(a.unit));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Computes the fma of 3 quantities
|
||||
*
|
||||
* @param a: Multiplicand
|
||||
* @param x: Multiplicand
|
||||
* @param b: Addend
|
||||
* @return Quantity: The nearest floating point representable to ax+b
|
||||
*/
|
||||
template<auto R, auto S, auto T, typename Rep1, typename Rep2, typename Rep3>
|
||||
requires requires { common_quantity_spec(get_quantity_spec(R) * get_quantity_spec(S), get_quantity_spec(T)); } &&
|
||||
(get_unit(R) * get_unit(S) == get_unit(T)) && requires(Rep1 v1, Rep2 v2, Rep3 v3) {
|
||||
requires requires { fma(v1, v2, v3); } || requires { std::fma(v1, v2, v3); };
|
||||
}
|
||||
[[nodiscard]] constexpr QuantityOf<common_quantity_spec(
|
||||
get_quantity_spec(R) * get_quantity_spec(S), get_quantity_spec(T))> auto fma(const quantity<R, Rep1>& a,
|
||||
const quantity<S, Rep2>& x,
|
||||
const quantity<T, Rep3>& b) noexcept
|
||||
{
|
||||
using std::fma;
|
||||
return quantity{
|
||||
fma(a.numerical_value_ref_in(a.unit), x.numerical_value_ref_in(x.unit), b.numerical_value_ref_in(b.unit)),
|
||||
common_reference(R * S, T)};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Returns the epsilon of the quantity
|
||||
*
|
||||
* The returned value is defined by a <tt>std::numeric_limits<typename Q::rep>::epsilon()</tt>.
|
||||
*
|
||||
* @tparam Q Quantity type being the base of the operation
|
||||
* @return Quantity The epsilon value for quantity's representation type
|
||||
*/
|
||||
template<Representation Rep, Reference R>
|
||||
requires requires { std::numeric_limits<Rep>::epsilon(); }
|
||||
[[nodiscard]] constexpr quantity<R{}, Rep> epsilon(R r) noexcept
|
||||
{
|
||||
return {static_cast<Rep>(std::numeric_limits<Rep>::epsilon()), r};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Computes the largest quantity with integer representation and unit type To with its number not greater than q
|
||||
*
|
||||
* @tparam q Quantity being the base of the operation
|
||||
* @return Quantity The rounded quantity with unit type To
|
||||
*/
|
||||
template<Unit auto To, auto R, typename Rep>
|
||||
[[nodiscard]] constexpr quantity<detail::clone_reference_with<To>(R), Rep> floor(const quantity<R, Rep>& q) noexcept
|
||||
requires((!treat_as_floating_point<Rep>) || requires(Rep v) { floor(v); } || requires(Rep v) { std::floor(v); }) &&
|
||||
(To == get_unit(R) || requires {
|
||||
q.force_in(To);
|
||||
quantity_values<Rep>::one();
|
||||
})
|
||||
{
|
||||
const auto handle_signed_results = [&]<typename T>(const T& res) {
|
||||
if (res > q) {
|
||||
return res - T::one();
|
||||
}
|
||||
return res;
|
||||
};
|
||||
if constexpr (treat_as_floating_point<Rep>) {
|
||||
using std::floor;
|
||||
if constexpr (To == get_unit(R)) {
|
||||
return {static_cast<Rep>(floor(q.numerical_value_ref_in(q.unit))), detail::clone_reference_with<To>(R)};
|
||||
} else {
|
||||
return handle_signed_results(
|
||||
quantity{static_cast<Rep>(floor(q.force_numerical_value_in(To))), detail::clone_reference_with<To>(R)});
|
||||
}
|
||||
} else {
|
||||
if constexpr (To == get_unit(R)) {
|
||||
return q.force_in(To);
|
||||
} else {
|
||||
return handle_signed_results(q.force_in(To));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Computes the smallest quantity with integer representation and unit type To with its number not less than q
|
||||
*
|
||||
* @tparam q Quantity being the base of the operation
|
||||
* @return Quantity The rounded quantity with unit type To
|
||||
*/
|
||||
template<Unit auto To, auto R, typename Rep>
|
||||
[[nodiscard]] constexpr quantity<detail::clone_reference_with<To>(R), Rep> ceil(const quantity<R, Rep>& q) noexcept
|
||||
requires((!treat_as_floating_point<Rep>) || requires(Rep v) { ceil(v); } || requires(Rep v) { std::ceil(v); }) &&
|
||||
(To == get_unit(R) || requires {
|
||||
q.force_in(To);
|
||||
quantity_values<Rep>::one();
|
||||
})
|
||||
{
|
||||
const auto handle_signed_results = [&]<typename T>(const T& res) {
|
||||
if (res < q) {
|
||||
return res + T::one();
|
||||
}
|
||||
return res;
|
||||
};
|
||||
if constexpr (treat_as_floating_point<Rep>) {
|
||||
using std::ceil;
|
||||
if constexpr (To == get_unit(R)) {
|
||||
return {static_cast<Rep>(ceil(q.numerical_value_ref_in(q.unit))), detail::clone_reference_with<To>(R)};
|
||||
} else {
|
||||
return handle_signed_results(
|
||||
quantity{static_cast<Rep>(ceil(q.force_numerical_value_in(To))), detail::clone_reference_with<To>(R)});
|
||||
}
|
||||
} else {
|
||||
if constexpr (To == get_unit(R)) {
|
||||
return q.force_in(To);
|
||||
} else {
|
||||
return handle_signed_results(q.force_in(To));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Computes the nearest quantity with integer representation and unit type To to q
|
||||
*
|
||||
* Rounding halfway cases away from zero, regardless of the current rounding mode.
|
||||
*
|
||||
* @tparam q Quantity being the base of the operation
|
||||
* @return Quantity The rounded quantity with unit type To
|
||||
*/
|
||||
template<Unit auto To, auto R, typename Rep>
|
||||
[[nodiscard]] constexpr quantity<detail::clone_reference_with<To>(R), Rep> round(const quantity<R, Rep>& q) noexcept
|
||||
requires((!treat_as_floating_point<Rep>) || requires(Rep v) { round(v); } || requires(Rep v) { std::round(v); }) &&
|
||||
(To == get_unit(R) || requires {
|
||||
::mp_units::floor<To>(q);
|
||||
quantity_values<Rep>::one();
|
||||
})
|
||||
{
|
||||
if constexpr (To == get_unit(R)) {
|
||||
if constexpr (treat_as_floating_point<Rep>) {
|
||||
using std::round;
|
||||
return {static_cast<Rep>(round(q.numerical_value_ref_in(q.unit))), detail::clone_reference_with<To>(R)};
|
||||
} else {
|
||||
return q.force_in(To);
|
||||
}
|
||||
} else {
|
||||
const auto res_low = mp_units::floor<To>(q);
|
||||
const auto res_high = res_low + res_low.one();
|
||||
const auto diff0 = q - res_low;
|
||||
const auto diff1 = res_high - q;
|
||||
if (diff0 == diff1) {
|
||||
if (static_cast<int>(res_low.numerical_value_ref_in(To)) & 1) {
|
||||
return res_high;
|
||||
}
|
||||
return res_low;
|
||||
}
|
||||
if (diff0 < diff1) {
|
||||
return res_low;
|
||||
}
|
||||
return res_high;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Computes the inverse of a quantity in a provided unit
|
||||
*/
|
||||
template<Unit auto To, auto R, typename Rep>
|
||||
[[nodiscard]] constexpr QuantityOf<dimensionless / get_quantity_spec(R)> auto inverse(const quantity<R, Rep>& q)
|
||||
requires requires {
|
||||
quantity_values<Rep>::one();
|
||||
value_cast<To>(1 / q);
|
||||
}
|
||||
{
|
||||
return (quantity_values<Rep>::one() * one).force_in(To * quantity<R, Rep>::unit) / q;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Computes the square root of the sum of the squares of x and y,
|
||||
* without undue overflow or underflow at intermediate stages of the computation
|
||||
*/
|
||||
template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
requires requires(Rep1 v1, Rep2 v2) {
|
||||
common_reference(R1, R2);
|
||||
requires requires { hypot(v1, v2); } || requires { std::hypot(v1, v2); };
|
||||
}
|
||||
[[nodiscard]] constexpr QuantityOf<get_quantity_spec(common_reference(R1, R2))> auto hypot(
|
||||
const quantity<R1, Rep1>& x, const quantity<R2, Rep2>& y) noexcept
|
||||
{
|
||||
constexpr auto ref = common_reference(R1, R2);
|
||||
constexpr auto unit = get_unit(ref);
|
||||
using std::hypot;
|
||||
return quantity{hypot(x.numerical_value_in(unit), y.numerical_value_in(unit)), ref};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Computes the square root of the sum of the squares of x, y, and z,
|
||||
* without undue overflow or underflow at intermediate stages of the computation
|
||||
*/
|
||||
template<auto R1, typename Rep1, auto R2, typename Rep2, auto R3, typename Rep3>
|
||||
requires requires(Rep1 v1, Rep2 v2, Rep3 v3) {
|
||||
common_reference(R1, R2, R3);
|
||||
requires requires { hypot(v1, v2, v3); } || requires { std::hypot(v1, v2, v3); };
|
||||
}
|
||||
[[nodiscard]] constexpr QuantityOf<get_quantity_spec(common_reference(R1, R2, R3))> auto hypot(
|
||||
const quantity<R1, Rep1>& x, const quantity<R2, Rep2>& y, const quantity<R3, Rep3>& z) noexcept
|
||||
{
|
||||
constexpr auto ref = common_reference(R1, R2);
|
||||
constexpr auto unit = get_unit(ref);
|
||||
using std::hypot;
|
||||
return quantity{hypot(x.numerical_value_in(unit), y.numerical_value_in(unit), z.numerical_value_in(unit)), ref};
|
||||
}
|
||||
|
||||
} // namespace mp_units
|
||||
@@ -23,27 +23,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <mp-units/bits/quantity_point_concepts.h>
|
||||
#include <mp-units/compare.h>
|
||||
#include <mp-units/customization_points.h>
|
||||
#include <mp-units/quantity.h>
|
||||
#include <compare>
|
||||
|
||||
namespace mp_units {
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename T>
|
||||
requires requires {
|
||||
{
|
||||
T::zero()
|
||||
} -> std::equality_comparable_with<T>;
|
||||
}
|
||||
[[nodiscard]] constexpr bool is_eq_zero(T v)
|
||||
{
|
||||
return v == T::zero();
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<typename Derived, QuantitySpec auto QS>
|
||||
struct absolute_point_origin {
|
||||
static constexpr QuantitySpec auto quantity_spec = QS;
|
||||
@@ -95,11 +81,9 @@ template<PointOrigin PO1, PointOrigin PO2>
|
||||
else if constexpr (detail::RelativePointOrigin<PO1> && detail::RelativePointOrigin<PO2>)
|
||||
return PO1::quantity_point == PO2::quantity_point;
|
||||
else if constexpr (detail::RelativePointOrigin<PO1>)
|
||||
return detail::same_absolute_point_origins(po1, po2) &&
|
||||
detail::is_eq_zero(PO1::quantity_point.quantity_from_zero());
|
||||
return detail::same_absolute_point_origins(po1, po2) && is_eq_zero(PO1::quantity_point.quantity_from_zero());
|
||||
else if constexpr (detail::RelativePointOrigin<PO2>)
|
||||
return detail::same_absolute_point_origins(po1, po2) &&
|
||||
detail::is_eq_zero(PO2::quantity_point.quantity_from_zero());
|
||||
return detail::same_absolute_point_origins(po1, po2) && is_eq_zero(PO2::quantity_point.quantity_from_zero());
|
||||
}
|
||||
|
||||
template<Reference R>
|
||||
|
||||
@@ -31,8 +31,8 @@
|
||||
#include <mp-units/bits/quantity_spec_concepts.h>
|
||||
#include <mp-units/bits/reference_concepts.h>
|
||||
#include <mp-units/bits/representation_concepts.h>
|
||||
#include <mp-units/compat_macros.h>
|
||||
#include <mp-units/dimension.h>
|
||||
#include <mp-units/quantity_spec_macro.h>
|
||||
#include <tuple>
|
||||
|
||||
namespace mp_units {
|
||||
|
||||
@@ -0,0 +1,574 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <mp-units/quantity.h>
|
||||
#include <functional>
|
||||
#include <random>
|
||||
|
||||
namespace mp_units {
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<Quantity Q, typename InputIt>
|
||||
std::vector<typename Q::rep> i_qty_to_rep(InputIt first, InputIt last)
|
||||
{
|
||||
std::vector<typename Q::rep> intervals_rep;
|
||||
intervals_rep.reserve(static_cast<size_t>(std::distance(first, last)));
|
||||
for (auto itr = first; itr != last; ++itr) {
|
||||
intervals_rep.push_back(itr->numerical_value_ref_in(Q::unit));
|
||||
}
|
||||
return intervals_rep;
|
||||
}
|
||||
|
||||
template<Quantity Q>
|
||||
std::vector<typename Q::rep> bl_qty_to_rep(std::initializer_list<Q>& bl)
|
||||
{
|
||||
std::vector<typename Q::rep> bl_rep;
|
||||
bl_rep.reserve(bl.size());
|
||||
for (const Q& qty : bl) {
|
||||
bl_rep.push_back(qty.numerical_value_ref_in(Q::unit));
|
||||
}
|
||||
return bl_rep;
|
||||
}
|
||||
|
||||
template<Quantity Q, typename UnaryOperation>
|
||||
std::vector<typename Q::rep> fw_bl_pwc(std::initializer_list<Q>& bl, UnaryOperation fw)
|
||||
{
|
||||
using rep = MP_UNITS_TYPENAME Q::rep;
|
||||
std::vector<rep> w_bl;
|
||||
w_bl.reserve(bl.size());
|
||||
for (const Q& qty : bl) {
|
||||
w_bl.push_back(fw(qty));
|
||||
}
|
||||
std::vector<rep> weights;
|
||||
weights.reserve(bl.size());
|
||||
for (size_t i = 0; i < bl.size() - 1; ++i) {
|
||||
weights.push_back(w_bl[i] + w_bl[i + 1]);
|
||||
}
|
||||
weights.push_back(0);
|
||||
return weights;
|
||||
}
|
||||
|
||||
template<Quantity Q, typename UnaryOperation>
|
||||
std::vector<typename Q::rep> fw_bl_pwl(std::initializer_list<Q>& bl, UnaryOperation fw)
|
||||
{
|
||||
std::vector<typename Q::rep> weights;
|
||||
weights.reserve(bl.size());
|
||||
for (const Q& qty : bl) {
|
||||
weights.push_back(fw(qty));
|
||||
}
|
||||
return weights;
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
template<Quantity Q>
|
||||
requires std::integral<typename Q::rep>
|
||||
struct uniform_int_distribution : public std::uniform_int_distribution<typename Q::rep> {
|
||||
using rep = MP_UNITS_TYPENAME Q::rep;
|
||||
using base = MP_UNITS_TYPENAME std::uniform_int_distribution<rep>;
|
||||
|
||||
uniform_int_distribution() : base() {}
|
||||
uniform_int_distribution(const Q& a, const Q& b) :
|
||||
base(a.numerical_value_ref_in(Q::unit), b.numerical_value_ref_in(Q::unit))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Generator>
|
||||
Q operator()(Generator& g)
|
||||
{
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q a() const { return base::a() * Q::reference; }
|
||||
Q b() const { return base::b() * Q::reference; }
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
requires std::floating_point<typename Q::rep>
|
||||
struct uniform_real_distribution : public std::uniform_real_distribution<typename Q::rep> {
|
||||
using rep = MP_UNITS_TYPENAME Q::rep;
|
||||
using base = MP_UNITS_TYPENAME std::uniform_real_distribution<rep>;
|
||||
|
||||
uniform_real_distribution() : base() {}
|
||||
uniform_real_distribution(const Q& a, const Q& b) :
|
||||
base(a.numerical_value_ref_in(Q::unit), b.numerical_value_ref_in(Q::unit))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Generator>
|
||||
Q operator()(Generator& g)
|
||||
{
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q a() const { return base::a() * Q::reference; }
|
||||
Q b() const { return base::b() * Q::reference; }
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
requires std::integral<typename Q::rep>
|
||||
struct binomial_distribution : public std::binomial_distribution<typename Q::rep> {
|
||||
using rep = MP_UNITS_TYPENAME Q::rep;
|
||||
using base = MP_UNITS_TYPENAME std::binomial_distribution<rep>;
|
||||
|
||||
binomial_distribution() : base() {}
|
||||
binomial_distribution(const Q& t, double p) : base(t.numerical_value_ref_in(Q::unit), p) {}
|
||||
|
||||
template<typename Generator>
|
||||
Q operator()(Generator& g)
|
||||
{
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q t() const { return base::t() * Q::reference; }
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
requires std::integral<typename Q::rep>
|
||||
struct negative_binomial_distribution : public std::negative_binomial_distribution<typename Q::rep> {
|
||||
using rep = MP_UNITS_TYPENAME Q::rep;
|
||||
using base = MP_UNITS_TYPENAME std::negative_binomial_distribution<rep>;
|
||||
|
||||
negative_binomial_distribution() : base() {}
|
||||
negative_binomial_distribution(const Q& k, double p) : base(k.numerical_value_ref_in(Q::unit), p) {}
|
||||
|
||||
template<typename Generator>
|
||||
Q operator()(Generator& g)
|
||||
{
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q k() const { return base::k() * Q::reference; }
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
requires std::integral<typename Q::rep>
|
||||
struct geometric_distribution : public std::geometric_distribution<typename Q::rep> {
|
||||
using rep = MP_UNITS_TYPENAME Q::rep;
|
||||
using base = MP_UNITS_TYPENAME std::geometric_distribution<rep>;
|
||||
|
||||
geometric_distribution() : base() {}
|
||||
geometric_distribution(double p) : base(p) {}
|
||||
|
||||
template<typename Generator>
|
||||
Q operator()(Generator& g)
|
||||
{
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
requires std::integral<typename Q::rep>
|
||||
struct poisson_distribution : public std::poisson_distribution<typename Q::rep> {
|
||||
using rep = MP_UNITS_TYPENAME Q::rep;
|
||||
using base = MP_UNITS_TYPENAME std::poisson_distribution<rep>;
|
||||
|
||||
poisson_distribution() : base() {}
|
||||
explicit poisson_distribution(double p) : base(p) {}
|
||||
|
||||
template<typename Generator>
|
||||
Q operator()(Generator& g)
|
||||
{
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
requires std::floating_point<typename Q::rep>
|
||||
struct exponential_distribution : public std::exponential_distribution<typename Q::rep> {
|
||||
using rep = MP_UNITS_TYPENAME Q::rep;
|
||||
using base = MP_UNITS_TYPENAME std::exponential_distribution<rep>;
|
||||
|
||||
exponential_distribution() : base() {}
|
||||
explicit exponential_distribution(const rep& lambda) : base(lambda) {}
|
||||
|
||||
template<typename Generator>
|
||||
Q operator()(Generator& g)
|
||||
{
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
requires std::floating_point<typename Q::rep>
|
||||
struct gamma_distribution : public std::gamma_distribution<typename Q::rep> {
|
||||
using rep = MP_UNITS_TYPENAME Q::rep;
|
||||
using base = MP_UNITS_TYPENAME std::gamma_distribution<rep>;
|
||||
|
||||
gamma_distribution() : base() {}
|
||||
gamma_distribution(const rep& alpha, const rep& beta) : base(alpha, beta) {}
|
||||
|
||||
template<typename Generator>
|
||||
Q operator()(Generator& g)
|
||||
{
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
requires std::floating_point<typename Q::rep>
|
||||
struct weibull_distribution : public std::weibull_distribution<typename Q::rep> {
|
||||
using rep = MP_UNITS_TYPENAME Q::rep;
|
||||
using base = MP_UNITS_TYPENAME std::weibull_distribution<rep>;
|
||||
|
||||
weibull_distribution() : base() {}
|
||||
weibull_distribution(const rep& a, const rep& b) : base(a, b) {}
|
||||
|
||||
template<typename Generator>
|
||||
Q operator()(Generator& g)
|
||||
{
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
requires std::floating_point<typename Q::rep>
|
||||
struct extreme_value_distribution : public std::extreme_value_distribution<typename Q::rep> {
|
||||
using rep = MP_UNITS_TYPENAME Q::rep;
|
||||
using base = MP_UNITS_TYPENAME std::extreme_value_distribution<rep>;
|
||||
|
||||
extreme_value_distribution() : base() {}
|
||||
extreme_value_distribution(const Q& a, const rep& b) : base(a.numerical_value_ref_in(Q::unit), b) {}
|
||||
|
||||
template<typename Generator>
|
||||
Q operator()(Generator& g)
|
||||
{
|
||||
return Q(base::operator()(g));
|
||||
}
|
||||
|
||||
Q a() const { return base::a() * Q::reference; }
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
requires std::floating_point<typename Q::rep>
|
||||
struct normal_distribution : public std::normal_distribution<typename Q::rep> {
|
||||
using rep = MP_UNITS_TYPENAME Q::rep;
|
||||
using base = MP_UNITS_TYPENAME std::normal_distribution<rep>;
|
||||
|
||||
normal_distribution() : base() {}
|
||||
normal_distribution(const Q& mean, const Q& stddev) :
|
||||
base(mean.numerical_value_ref_in(Q::unit), stddev.numerical_value_ref_in(Q::unit))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Generator>
|
||||
Q operator()(Generator& g)
|
||||
{
|
||||
return Q(base::operator()(g));
|
||||
}
|
||||
|
||||
Q mean() const { return base::mean() * Q::reference; }
|
||||
Q stddev() const { return base::stddev() * Q::reference; }
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
requires std::floating_point<typename Q::rep>
|
||||
struct lognormal_distribution : public std::lognormal_distribution<typename Q::rep> {
|
||||
using rep = MP_UNITS_TYPENAME Q::rep;
|
||||
using base = MP_UNITS_TYPENAME std::lognormal_distribution<rep>;
|
||||
|
||||
lognormal_distribution() : base() {}
|
||||
lognormal_distribution(const Q& m, const Q& s) :
|
||||
base(m.numerical_value_ref_in(Q::unit), s.numerical_value_ref_in(Q::unit))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Generator>
|
||||
Q operator()(Generator& g)
|
||||
{
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q m() const { return base::m() * Q::reference; }
|
||||
Q s() const { return base::s() * Q::reference; }
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
requires std::floating_point<typename Q::rep>
|
||||
struct chi_squared_distribution : public std::chi_squared_distribution<typename Q::rep> {
|
||||
using rep = MP_UNITS_TYPENAME Q::rep;
|
||||
using base = MP_UNITS_TYPENAME std::chi_squared_distribution<rep>;
|
||||
|
||||
chi_squared_distribution() : base() {}
|
||||
explicit chi_squared_distribution(const rep& n) : base(n) {}
|
||||
|
||||
template<typename Generator>
|
||||
Q operator()(Generator& g)
|
||||
{
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
requires std::floating_point<typename Q::rep>
|
||||
struct cauchy_distribution : public std::cauchy_distribution<typename Q::rep> {
|
||||
using rep = MP_UNITS_TYPENAME Q::rep;
|
||||
using base = MP_UNITS_TYPENAME std::cauchy_distribution<rep>;
|
||||
|
||||
cauchy_distribution() : base() {}
|
||||
cauchy_distribution(const Q& a, const Q& b) :
|
||||
base(a.numerical_value_ref_in(Q::unit), b.numerical_value_ref_in(Q::unit))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Generator>
|
||||
Q operator()(Generator& g)
|
||||
{
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q a() const { return base::a() * Q::reference; }
|
||||
Q b() const { return base::b() * Q::reference; }
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
requires std::floating_point<typename Q::rep>
|
||||
struct fisher_f_distribution : public std::fisher_f_distribution<typename Q::rep> {
|
||||
using rep = MP_UNITS_TYPENAME Q::rep;
|
||||
using base = MP_UNITS_TYPENAME std::fisher_f_distribution<rep>;
|
||||
|
||||
fisher_f_distribution() : base() {}
|
||||
fisher_f_distribution(const rep& m, const rep& n) : base(m, n) {}
|
||||
|
||||
template<typename Generator>
|
||||
Q operator()(Generator& g)
|
||||
{
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
requires std::floating_point<typename Q::rep>
|
||||
struct student_t_distribution : public std::student_t_distribution<typename Q::rep> {
|
||||
using rep = MP_UNITS_TYPENAME Q::rep;
|
||||
using base = MP_UNITS_TYPENAME std::student_t_distribution<rep>;
|
||||
|
||||
student_t_distribution() : base() {}
|
||||
explicit student_t_distribution(const rep& n) : base(n) {}
|
||||
|
||||
template<typename Generator>
|
||||
Q operator()(Generator& g)
|
||||
{
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
requires std::integral<typename Q::rep>
|
||||
struct discrete_distribution : public std::discrete_distribution<typename Q::rep> {
|
||||
using rep = MP_UNITS_TYPENAME Q::rep;
|
||||
using base = MP_UNITS_TYPENAME std::discrete_distribution<rep>;
|
||||
|
||||
discrete_distribution() : base() {}
|
||||
|
||||
template<typename InputIt>
|
||||
discrete_distribution(InputIt first, InputIt last) : base(first, last)
|
||||
{
|
||||
}
|
||||
|
||||
discrete_distribution(std::initializer_list<double> weights) : base(weights) {}
|
||||
|
||||
template<typename UnaryOperation>
|
||||
discrete_distribution(std::size_t count, double xmin, double xmax, UnaryOperation unary_op) :
|
||||
base(count, xmin, xmax, unary_op)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Generator>
|
||||
Q operator()(Generator& g)
|
||||
{
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
requires std::floating_point<typename Q::rep>
|
||||
class piecewise_constant_distribution : public std::piecewise_constant_distribution<typename Q::rep> {
|
||||
using rep = MP_UNITS_TYPENAME Q::rep;
|
||||
using base = MP_UNITS_TYPENAME std::piecewise_constant_distribution<rep>;
|
||||
|
||||
template<typename InputIt>
|
||||
piecewise_constant_distribution(const std::vector<rep>& i, InputIt first_w) : base(i.cbegin(), i.cend(), first_w)
|
||||
{
|
||||
}
|
||||
|
||||
piecewise_constant_distribution(const std::vector<rep>& bl, const std::vector<rep>& weights) :
|
||||
base(bl.cbegin(), bl.cend(), weights.cbegin())
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
piecewise_constant_distribution() : base() {}
|
||||
|
||||
template<typename InputIt1, typename InputIt2>
|
||||
piecewise_constant_distribution(InputIt1 first_i, InputIt1 last_i, InputIt2 first_w) :
|
||||
piecewise_constant_distribution(detail::i_qty_to_rep<Q>(first_i, last_i), first_w)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename UnaryOperation>
|
||||
piecewise_constant_distribution(std::initializer_list<Q> bl, UnaryOperation fw) :
|
||||
piecewise_constant_distribution(detail::bl_qty_to_rep(bl), detail::fw_bl_pwc(bl, fw))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename UnaryOperation>
|
||||
piecewise_constant_distribution(std::size_t nw, const Q& xmin, const Q& xmax, UnaryOperation fw) :
|
||||
base(nw, xmin.numerical_value_ref_in(Q::unit), xmax.numerical_value_ref_in(Q::unit),
|
||||
[fw](rep val) { return fw(val * Q::reference); })
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Generator>
|
||||
Q operator()(Generator& g)
|
||||
{
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
std::vector<Q> intervals() const
|
||||
{
|
||||
std::vector<rep> intervals_rep = base::intervals();
|
||||
std::vector<Q> intervals_qty;
|
||||
intervals_qty.reserve(intervals_rep.size());
|
||||
for (const rep& val : intervals_rep) {
|
||||
intervals_qty.push_back(val * Q::reference);
|
||||
}
|
||||
return intervals_qty;
|
||||
}
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
requires std::floating_point<typename Q::rep>
|
||||
class piecewise_linear_distribution : public std::piecewise_linear_distribution<typename Q::rep> {
|
||||
using rep = MP_UNITS_TYPENAME Q::rep;
|
||||
using base = MP_UNITS_TYPENAME std::piecewise_linear_distribution<rep>;
|
||||
|
||||
template<typename InputIt>
|
||||
piecewise_linear_distribution(const std::vector<rep>& i, InputIt first_w) : base(i.cbegin(), i.cend(), first_w)
|
||||
{
|
||||
}
|
||||
|
||||
piecewise_linear_distribution(const std::vector<rep>& bl, const std::vector<rep>& weights) :
|
||||
base(bl.cbegin(), bl.cend(), weights.cbegin())
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
piecewise_linear_distribution() : base() {}
|
||||
|
||||
template<typename InputIt1, typename InputIt2>
|
||||
piecewise_linear_distribution(InputIt1 first_i, InputIt1 last_i, InputIt2 first_w) :
|
||||
piecewise_linear_distribution(detail::i_qty_to_rep<Q>(first_i, last_i), first_w)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename UnaryOperation>
|
||||
piecewise_linear_distribution(std::initializer_list<Q> bl, UnaryOperation fw) :
|
||||
piecewise_linear_distribution(detail::bl_qty_to_rep(bl), detail::fw_bl_pwl(bl, fw))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename UnaryOperation>
|
||||
piecewise_linear_distribution(std::size_t nw, const Q& xmin, const Q& xmax, UnaryOperation fw) :
|
||||
base(nw, xmin.numerical_value_ref_in(Q::unit), xmax.numerical_value_ref_in(Q::unit),
|
||||
[fw](rep val) { return fw(val * Q::reference); })
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Generator>
|
||||
Q operator()(Generator& g)
|
||||
{
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
std::vector<Q> intervals() const
|
||||
{
|
||||
std::vector<rep> intervals_rep = base::intervals();
|
||||
std::vector<Q> intervals_qty;
|
||||
intervals_qty.reserve(intervals_rep.size());
|
||||
for (const rep& val : intervals_rep) {
|
||||
intervals_qty.push_back(val * Q::reference);
|
||||
}
|
||||
return intervals_qty;
|
||||
}
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
} // namespace mp_units
|
||||
@@ -0,0 +1,10 @@
|
||||
module;
|
||||
|
||||
#include <mp-units/bits/core_gmf.h>
|
||||
|
||||
export module mp_units.core;
|
||||
|
||||
export
|
||||
{
|
||||
#include <mp-units/core.h>
|
||||
}
|
||||
Reference in new issue
Block a user