merge branch master
This commit is contained in:
1 parent
b7e467ff42
commit
561fbf7c93
68 files changed
+1426
-812
No files matched your search
@@ -23,7 +23,9 @@
|
||||
cmake_minimum_required(VERSION 3.19)
|
||||
|
||||
# find dependencies
|
||||
find_package(gsl-lite CONFIG REQUIRED)
|
||||
if(NOT TARGET gsl::gsl-lite)
|
||||
find_package(gsl-lite CONFIG REQUIRED)
|
||||
endif()
|
||||
|
||||
# check if libc++ is being used
|
||||
include(CheckLibcxxInUse)
|
||||
@@ -81,7 +83,9 @@ target_include_directories(
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
if(${projectPrefix}LIBCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "14")
|
||||
find_package(range-v3 CONFIG REQUIRED)
|
||||
if(NOT TARGET range-v3::range-v3)
|
||||
find_package(range-v3 CONFIG REQUIRED)
|
||||
endif()
|
||||
target_link_libraries(mp-units-core INTERFACE range-v3::range-v3)
|
||||
endif()
|
||||
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
|
||||
+13
-3
@@ -96,7 +96,7 @@
|
||||
#include <compare>
|
||||
#include <concepts>
|
||||
|
||||
#if UNITS_COMP_MSVC || UNITS_COMP_CLANG
|
||||
#if UNITS_COMP_MSVC || (UNITS_COMP_CLANG && UNITS_COMP_CLANG < 16)
|
||||
|
||||
#define TYPENAME typename
|
||||
|
||||
@@ -108,11 +108,21 @@
|
||||
|
||||
#if UNITS_COMP_MSVC
|
||||
|
||||
#define UNITS_MSVC_WORKAROUND(X)
|
||||
#define UNITS_CONSTRAINED_AUTO_WORKAROUND(X)
|
||||
|
||||
#else
|
||||
|
||||
#define UNITS_MSVC_WORKAROUND(X) X
|
||||
#define UNITS_CONSTRAINED_AUTO_WORKAROUND(X) X
|
||||
|
||||
#endif
|
||||
|
||||
#if UNITS_COMP_MSVC || (UNITS_COMP_GCC && UNITS_COMP_GCC < 11)
|
||||
|
||||
#define UNITS_CONSTRAINED_NTTP_WORKAROUND(X)
|
||||
|
||||
#else
|
||||
|
||||
#define UNITS_CONSTRAINED_NTTP_WORKAROUND(X) X
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
#include <cstdint>
|
||||
#include <numbers>
|
||||
#include <optional>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace mp_units {
|
||||
|
||||
@@ -243,10 +242,10 @@ using widen_t = conditional<std::is_arithmetic_v<T>,
|
||||
template<typename T>
|
||||
[[nodiscard]] consteval T int_power(T base, std::integral auto exp)
|
||||
{
|
||||
// As this function should only be called at compile time, the exceptions herein function as
|
||||
// "parameter-compatible static_asserts", and should not result in exceptions at runtime.
|
||||
// As this function should only be called at compile time, the terminations herein function as
|
||||
// "parameter-compatible static_asserts", and should not result in terminations at runtime.
|
||||
if (exp < 0) {
|
||||
throw std::invalid_argument{"int_power only supports positive integer powers"};
|
||||
std::terminate(); // int_power only supports positive integer powers
|
||||
}
|
||||
|
||||
constexpr auto checked_multiply = [](auto a, auto b) {
|
||||
@@ -254,7 +253,7 @@ template<typename T>
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_FLOAT_EQUAL
|
||||
if (result / a != b) {
|
||||
throw std::overflow_error{"Wraparound detected"};
|
||||
std::terminate(); // Wraparound detected
|
||||
}
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
return result;
|
||||
@@ -284,15 +283,15 @@ template<typename T>
|
||||
// need to write a custom function.
|
||||
//
|
||||
// Note that since this function should only be called at compile time, the point of these
|
||||
// exceptions is to act as "static_assert substitutes", not to throw actual exceptions at runtime.
|
||||
// terminations is to act as "static_assert substitutes", not to actually terminate at runtime.
|
||||
const auto exp = get_exponent(el);
|
||||
if (exp.den != 1) {
|
||||
throw std::invalid_argument{"Rational powers not yet supported"};
|
||||
std::terminate(); // Rational powers not yet supported
|
||||
}
|
||||
|
||||
if (exp.num < 0) {
|
||||
if constexpr (std::is_integral_v<T>) {
|
||||
throw std::invalid_argument{"Cannot represent reciprocal as integer"};
|
||||
std::terminate(); // Cannot represent reciprocal as integer
|
||||
} else {
|
||||
return T{1} / compute_base_power<T>(inverse(el));
|
||||
}
|
||||
@@ -311,11 +310,11 @@ template<typename To, typename From>
|
||||
requires(!std::is_integral_v<To> || std::is_integral_v<From>)
|
||||
[[nodiscard]] consteval To checked_static_cast(From x)
|
||||
{
|
||||
// This function should only ever be called at compile time. The purpose of these exceptions is
|
||||
// This function should only ever be called at compile time. The purpose of these terminations is
|
||||
// to produce compiler errors, because we cannot `static_assert` on function arguments.
|
||||
if constexpr (std::is_integral_v<To>) {
|
||||
if (!std::in_range<To>(x)) {
|
||||
throw std::invalid_argument{"Cannot represent magnitude in this type"};
|
||||
std::terminate(); // Cannot represent magnitude in this type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,7 +472,7 @@ void to_base_specialization_of_magnitude(const volatile magnitude<Ms...>*);
|
||||
|
||||
template<typename T>
|
||||
inline constexpr bool is_derived_from_specialization_of_magnitude =
|
||||
requires(T * t) { to_base_specialization_of_magnitude(t); };
|
||||
requires(T* t) { to_base_specialization_of_magnitude(t); };
|
||||
|
||||
template<typename T>
|
||||
requires is_derived_from_specialization_of_magnitude<T>
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace mp_units {
|
||||
*/
|
||||
template<Magnitude auto M, Unit U>
|
||||
struct scaled_unit {
|
||||
static constexpr UNITS_MSVC_WORKAROUND(Magnitude) auto mag = M;
|
||||
static constexpr UNITS_CONSTRAINED_AUTO_WORKAROUND(Magnitude) auto mag = M;
|
||||
static constexpr U reference_unit{};
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user