mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-01 03:14:29 +02:00
refactor: precondition checks and asserts cleanup
This commit is contained in:
@@ -42,9 +42,6 @@ enable_ccache(BASE_DIR ${PROJECT_SOURCE_DIR})
|
||||
include(warnings)
|
||||
set_warnings()
|
||||
|
||||
# set all contracts checking in a Debug build
|
||||
add_compile_definitions($<$<CONFIG:Debug>:gsl_CONFIG_CONTRACT_CHECKING_AUDIT>)
|
||||
|
||||
# enable include-what-you-use
|
||||
option(${projectPrefix}IWYU "Enables include-what-you-use" OFF)
|
||||
|
||||
|
@@ -52,7 +52,7 @@ Many reasons make UDLs a poor choice for a physical units library:
|
||||
```cpp
|
||||
constexpr auto operator"" _q_kg_m2_per_s(unsigned long long l)
|
||||
{
|
||||
gsl_ExpectsAudit(std::in_range<std::int64_t>(l));
|
||||
gsl_Expects(std::in_range<std::int64_t>(l));
|
||||
return angular_momentum<kilogram_metre_sq_per_second, std::int64_t>(static_cast<std::int64_t>(l));
|
||||
}
|
||||
|
||||
|
@@ -61,7 +61,7 @@ struct basic_fixed_string {
|
||||
|
||||
constexpr explicit(false) basic_fixed_string(const CharT (&txt)[N + 1]) noexcept
|
||||
{
|
||||
gsl_ExpectsAudit(txt[N] == CharT{});
|
||||
gsl_Expects(txt[N] == CharT{});
|
||||
for (std::size_t i = 0; i < N; ++i) data_[i] = txt[i];
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ struct basic_fixed_string {
|
||||
requires std::convertible_to<std::iter_value_t<It>, CharT>
|
||||
constexpr explicit basic_fixed_string(It first, S last) noexcept
|
||||
{
|
||||
gsl_ExpectsAudit(std::distance(last, first) == N);
|
||||
gsl_Expects(std::distance(first, last) == N);
|
||||
for (auto it = data_; first != last; ++first, ++it) *it = *first;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ struct basic_fixed_string {
|
||||
[[nodiscard]] constexpr const CharT* c_str() const noexcept { return data(); }
|
||||
[[nodiscard]] constexpr value_type operator[](size_type index) const noexcept
|
||||
{
|
||||
gsl_ExpectsAudit(index < N);
|
||||
gsl_Expects(index < N);
|
||||
return data()[index];
|
||||
}
|
||||
|
||||
|
@@ -91,7 +91,7 @@ struct symbol_text {
|
||||
constexpr explicit(false) symbol_text(const char (&txt)[N + 1]) :
|
||||
unicode_(detail::to_u8string(basic_fixed_string{txt})), ascii_(txt)
|
||||
{
|
||||
gsl_ExpectsAudit(txt[N] == char{});
|
||||
gsl_Expects(txt[N] == char{});
|
||||
gsl_Expects(detail::is_basic_literal_character_set(txt));
|
||||
}
|
||||
|
||||
@@ -102,8 +102,8 @@ struct symbol_text {
|
||||
|
||||
constexpr symbol_text(const char8_t (&u)[N + 1], const char (&a)[M + 1]) : unicode_(u), ascii_(a)
|
||||
{
|
||||
gsl_ExpectsAudit(u[N] == char8_t{});
|
||||
gsl_ExpectsAudit(a[M] == char{});
|
||||
gsl_Expects(u[N] == char8_t{});
|
||||
gsl_Expects(a[M] == char{});
|
||||
gsl_Expects(detail::is_basic_literal_character_set(a));
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ struct symbol_text {
|
||||
|
||||
[[nodiscard]] constexpr bool empty() const
|
||||
{
|
||||
gsl_Expects(unicode().empty() == ascii().empty());
|
||||
gsl_AssertDebug(unicode().empty() == ascii().empty());
|
||||
return unicode().empty();
|
||||
}
|
||||
|
||||
|
@@ -351,7 +351,7 @@ public:
|
||||
friend constexpr decltype(auto) operator%=(Q&& lhs, const quantity& rhs)
|
||||
|
||||
{
|
||||
gsl_ExpectsAudit(rhs != zero());
|
||||
gsl_ExpectsDebug(rhs != zero());
|
||||
lhs.numerical_value_is_an_implementation_detail_ %= rhs.numerical_value_is_an_implementation_detail_;
|
||||
return std::forward<Q>(lhs);
|
||||
}
|
||||
@@ -391,7 +391,7 @@ public:
|
||||
}
|
||||
friend constexpr decltype(auto) operator/=(Q&& lhs, const Value& v)
|
||||
{
|
||||
gsl_ExpectsAudit(v != quantity_values<Value>::zero());
|
||||
gsl_ExpectsDebug(v != quantity_values<Value>::zero());
|
||||
lhs.numerical_value_is_an_implementation_detail_ /= v;
|
||||
return std::forward<Q>(lhs);
|
||||
}
|
||||
@@ -405,7 +405,7 @@ public:
|
||||
}
|
||||
friend constexpr decltype(auto) operator/=(Q1&& lhs, const Q2& rhs)
|
||||
{
|
||||
gsl_ExpectsAudit(rhs != rhs.zero());
|
||||
gsl_ExpectsDebug(rhs != rhs.zero());
|
||||
lhs.numerical_value_is_an_implementation_detail_ /= rhs.numerical_value_is_an_implementation_detail_;
|
||||
return std::forward<Q1>(lhs);
|
||||
}
|
||||
@@ -449,7 +449,7 @@ template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
detail::CommonlyInvocableQuantities<std::modulus<>, quantity<R1, Rep1>, quantity<R2, Rep2>>
|
||||
[[nodiscard]] constexpr Quantity auto operator%(const quantity<R1, Rep1>& lhs, const quantity<R2, Rep2>& rhs)
|
||||
{
|
||||
gsl_ExpectsAudit(rhs != rhs.zero());
|
||||
gsl_ExpectsDebug(rhs != rhs.zero());
|
||||
using ret = detail::common_quantity_for<std::modulus<>, quantity<R1, Rep1>, quantity<R2, Rep2>>;
|
||||
const ret ret_lhs(lhs);
|
||||
const ret ret_rhs(rhs);
|
||||
@@ -484,7 +484,7 @@ template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
requires detail::InvocableQuantities<std::divides<>, quantity<R1, Rep1>, quantity<R2, Rep2>>
|
||||
[[nodiscard]] constexpr Quantity auto operator/(const quantity<R1, Rep1>& lhs, const quantity<R2, Rep2>& rhs)
|
||||
{
|
||||
gsl_ExpectsAudit(rhs != rhs.zero());
|
||||
gsl_ExpectsDebug(rhs != rhs.zero());
|
||||
return quantity{lhs.numerical_value_ref_in(get_unit(R1)) / rhs.numerical_value_ref_in(get_unit(R2)), R1 / R2};
|
||||
}
|
||||
|
||||
@@ -493,7 +493,7 @@ template<auto R, typename Rep, typename Value>
|
||||
detail::InvokeResultOf<get_quantity_spec(R).character, std::divides<>, Rep, const Value&>
|
||||
[[nodiscard]] constexpr QuantityOf<get_quantity_spec(R)> auto operator/(const quantity<R, Rep>& q, const Value& v)
|
||||
{
|
||||
gsl_ExpectsAudit(v != quantity_values<Value>::zero());
|
||||
gsl_ExpectsDebug(v != quantity_values<Value>::zero());
|
||||
return quantity{q.numerical_value_ref_in(get_unit(R)) / v, R};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user