mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-02 11:54:27 +02:00
refactor: terminate
replaced with abort
and a header file added
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
#include <concepts>
|
#include <concepts>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <cstdlib>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
@@ -38,6 +38,7 @@
|
|||||||
#ifndef MP_UNITS_IN_MODULE_INTERFACE
|
#ifndef MP_UNITS_IN_MODULE_INTERFACE
|
||||||
#include <concepts>
|
#include <concepts>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <cstdlib>
|
||||||
#include <numbers>
|
#include <numbers>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#endif
|
#endif
|
||||||
@@ -278,7 +279,7 @@ template<typename T>
|
|||||||
// As this function should only be called at compile time, the terminations herein function as
|
// 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.
|
// "parameter-compatible static_asserts", and should not result in terminations at runtime.
|
||||||
if (exp < 0) {
|
if (exp < 0) {
|
||||||
std::terminate(); // int_power only supports positive integer powers
|
std::abort(); // int_power only supports positive integer powers
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr auto checked_multiply = [](auto a, auto b) {
|
constexpr auto checked_multiply = [](auto a, auto b) {
|
||||||
@@ -286,7 +287,7 @@ template<typename T>
|
|||||||
MP_UNITS_DIAGNOSTIC_PUSH
|
MP_UNITS_DIAGNOSTIC_PUSH
|
||||||
MP_UNITS_DIAGNOSTIC_IGNORE_FLOAT_EQUAL
|
MP_UNITS_DIAGNOSTIC_IGNORE_FLOAT_EQUAL
|
||||||
if (result / a != b) {
|
if (result / a != b) {
|
||||||
std::terminate(); // Wraparound detected
|
std::abort(); // Wraparound detected
|
||||||
}
|
}
|
||||||
MP_UNITS_DIAGNOSTIC_POP
|
MP_UNITS_DIAGNOSTIC_POP
|
||||||
return result;
|
return result;
|
||||||
@@ -319,12 +320,12 @@ template<typename T>
|
|||||||
// terminations is to act as "static_assert substitutes", not to actually terminate at runtime.
|
// terminations is to act as "static_assert substitutes", not to actually terminate at runtime.
|
||||||
const auto exp = get_exponent(el);
|
const auto exp = get_exponent(el);
|
||||||
if (exp.den != 1) {
|
if (exp.den != 1) {
|
||||||
std::terminate(); // Rational powers not yet supported
|
std::abort(); // Rational powers not yet supported
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exp.num < 0) {
|
if (exp.num < 0) {
|
||||||
if constexpr (std::is_integral_v<T>) {
|
if constexpr (std::is_integral_v<T>) {
|
||||||
std::terminate(); // Cannot represent reciprocal as integer
|
std::abort(); // Cannot represent reciprocal as integer
|
||||||
} else {
|
} else {
|
||||||
return T{1} / compute_base_power<T>(inverse(el));
|
return T{1} / compute_base_power<T>(inverse(el));
|
||||||
}
|
}
|
||||||
@@ -347,7 +348,7 @@ template<typename To, typename From>
|
|||||||
// to produce compiler errors, because we cannot `static_assert` on function arguments.
|
// to produce compiler errors, because we cannot `static_assert` on function arguments.
|
||||||
if constexpr (std::is_integral_v<To>) {
|
if constexpr (std::is_integral_v<To>) {
|
||||||
if (!std::in_range<To>(x)) {
|
if (!std::in_range<To>(x)) {
|
||||||
std::terminate(); // Cannot represent magnitude in this type
|
std::abort(); // Cannot represent magnitude in this type
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user