From a62fdd23317888f2c574488c621f6e917799a852 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Tue, 19 Mar 2024 10:37:01 +0900 Subject: [PATCH] refactor: precondition checks and asserts cleanup --- CMakeLists.txt | 3 --- docs/getting_started/faq.md | 2 +- .../include/mp-units/bits/external/fixed_string.h | 6 +++--- src/core/include/mp-units/bits/symbol_text.h | 8 ++++---- src/core/include/mp-units/quantity.h | 12 ++++++------ 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 772e982a..e5ca6de3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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($<$:gsl_CONFIG_CONTRACT_CHECKING_AUDIT>) - # enable include-what-you-use option(${projectPrefix}IWYU "Enables include-what-you-use" OFF) diff --git a/docs/getting_started/faq.md b/docs/getting_started/faq.md index b08e2aec..38373806 100644 --- a/docs/getting_started/faq.md +++ b/docs/getting_started/faq.md @@ -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(l)); + gsl_Expects(std::in_range(l)); return angular_momentum(static_cast(l)); } diff --git a/src/core/include/mp-units/bits/external/fixed_string.h b/src/core/include/mp-units/bits/external/fixed_string.h index 8eff4aa9..402140c1 100644 --- a/src/core/include/mp-units/bits/external/fixed_string.h +++ b/src/core/include/mp-units/bits/external/fixed_string.h @@ -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, 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]; } diff --git a/src/core/include/mp-units/bits/symbol_text.h b/src/core/include/mp-units/bits/symbol_text.h index 9aba2065..52a94c6a 100644 --- a/src/core/include/mp-units/bits/symbol_text.h +++ b/src/core/include/mp-units/bits/symbol_text.h @@ -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(); } diff --git a/src/core/include/mp-units/quantity.h b/src/core/include/mp-units/quantity.h index 720ee57d..176cccc4 100644 --- a/src/core/include/mp-units/quantity.h +++ b/src/core/include/mp-units/quantity.h @@ -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(lhs); } @@ -391,7 +391,7 @@ public: } friend constexpr decltype(auto) operator/=(Q&& lhs, const Value& v) { - gsl_ExpectsAudit(v != quantity_values::zero()); + gsl_ExpectsDebug(v != quantity_values::zero()); lhs.numerical_value_is_an_implementation_detail_ /= v; return std::forward(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(lhs); } @@ -449,7 +449,7 @@ template detail::CommonlyInvocableQuantities, quantity, quantity> [[nodiscard]] constexpr Quantity auto operator%(const quantity& lhs, const quantity& rhs) { - gsl_ExpectsAudit(rhs != rhs.zero()); + gsl_ExpectsDebug(rhs != rhs.zero()); using ret = detail::common_quantity_for, quantity, quantity>; const ret ret_lhs(lhs); const ret ret_rhs(rhs); @@ -484,7 +484,7 @@ template requires detail::InvocableQuantities, quantity, quantity> [[nodiscard]] constexpr Quantity auto operator/(const quantity& lhs, const quantity& 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 detail::InvokeResultOf, Rep, const Value&> [[nodiscard]] constexpr QuantityOf auto operator/(const quantity& q, const Value& v) { - gsl_ExpectsAudit(v != quantity_values::zero()); + gsl_ExpectsDebug(v != quantity_values::zero()); return quantity{q.numerical_value_ref_in(get_unit(R)) / v, R}; }