From 0ac2b711797d18c7ab234cfe30d1ff95014f70ea Mon Sep 17 00:00:00 2001 From: Christopher Kormanyos Date: Wed, 29 Nov 2023 18:33:17 +0100 Subject: [PATCH] Correct docs and namespaces and linting --- README.md | 42 ++--------------- boost/multiprecision/uintwide_t_backend.hpp | 2 +- math/wide_integer/uintwide_t.h | 50 ++++++++++----------- test/test.hpp | 10 ++--- test/test_arithmetic.hpp | 20 ++++----- test/test_uintwide_t_edge_cases.cpp | 24 +++++----- 6 files changed, 55 insertions(+), 93 deletions(-) diff --git a/README.md b/README.md index fd42090..efaa810 100644 --- a/README.md +++ b/README.md @@ -778,9 +778,9 @@ This preprocessor switch was motivated by the discussion in By default, the preprocessor switch `WIDE_INTEGER_HAS_CLZ_LIMB_OPTIMIZATIONS` is not defined and CLZ-limb optimizations are default-_disabled_. -### C++14, 17, 20 `constexpr` support +### C++14, 17, 20, 23 and beyond `constexpr` support -When using C++20 `uintwide_t` supports compile-time +When using C++14 and beyond, `uintwide_t` supports compile-time `constexpr` construction and evaluation of results of binary arithmetic, comparison operators and various elementary functions. @@ -797,7 +797,7 @@ and its subsequent `return` of the value zero ```cpp #include -// Use (at least) a C++20 compiler for this example. +// Use (at least) a C++14 compiler for this example. using uint256_t = ::math::wide_integer::uintwide_t<256U>; using uint512_t = ::math::wide_integer::uintwide_t<512U>; @@ -823,42 +823,6 @@ auto main() -> int } ``` -The so-called `constexpr`-_ness_ of `uintwide_t` has been checked on GCC 10 and up, -clang 10 and up (with `-std=c++20`) and VC 14.2 (with `/std:c++latest`), -also for various embedded compilers such as `avr-gcc` 10 and up, -`arm-non-eabi-gcc` 10 and up, and more. In addition, -some compilations using compilers having less modern standards -such as C++14, 17, 2a have also been checked -for `constexpr` usage of `uintwide_t`. If you have an older -compiler, you might have to check the compiler's -ability to obtain the entire benefit of `constexpr` with `uintwide_t`. - -If full `constexpr` compliance is not available or its -availability is unknown, the preprocessor symbols below can be useful. -These symbols are defined or set directly within the header(s) -of the wide_integer library. - -```cpp -WIDE_INTEGER_CONSTEXPR -WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST -``` - -The preprocessor symbol `WIDE_INTEGER_CONSTEXPR` acts as either -a synonym for `constexpr` or expands to nothing depending on -whether the availability of `constexpr` support has been automatically -detected or not. -The preprocessor symbol `WIDE_INTEGER_CONSTEXPR_IS_COMPILE_TIME_CONST` -has the value of `0` or `1`, where `1` indicates that `uintwide_t` -values qualified with `WIDE_INTEGER_CONSTEXPR` are actually -compile-time constant (i.e., `constexpr`). - -Detection of availability of `constexpr` support is implemented -[with preprocessor queries in uintwide_t.h](https://github.com/ckormanyos/wide-integer/blob/4ad2cb5e96acc0b326c8fc2bbb74546dc90053ef/math/wide_integer/uintwide_t.h#L36). -These complicated proprocessor queries are not complete (in the sense of -detecting all world-wide compiler/target systems). If you have -a specific compiler/target system needing `constexpr` detection, -please feel free to contact me directly so that this can be implemented. - ### Signed integer support Signed big integers are also supported in the wide_integer library. diff --git a/boost/multiprecision/uintwide_t_backend.hpp b/boost/multiprecision/uintwide_t_backend.hpp index deb3acc..0338a2d 100644 --- a/boost/multiprecision/uintwide_t_backend.hpp +++ b/boost/multiprecision/uintwide_t_backend.hpp @@ -205,7 +205,7 @@ WIDE_INTEGER_CONSTEXPR auto operator=(const std::string& str_rep) -> uintwide_t_backend& { m_value = representation_type(str_rep); return *this; } WIDE_INTEGER_CONSTEXPR auto operator=(const char* char_ptr) -> uintwide_t_backend& { m_value = representation_type(char_ptr); return *this; } - WIDE_INTEGER_CONSTEXPR auto swap(uintwide_t_backend& other) -> void + WIDE_INTEGER_CONSTEXPR auto swap(uintwide_t_backend& other) noexcept -> void { m_value.representation().swap(other.m_value.representation()); } diff --git a/math/wide_integer/uintwide_t.h b/math/wide_integer/uintwide_t.h index deb4eec..2a53adb 100644 --- a/math/wide_integer/uintwide_t.h +++ b/math/wide_integer/uintwide_t.h @@ -247,19 +247,19 @@ private: iterator_type current; // NOLINT(readability-identifier-naming) - friend inline constexpr auto operator< (const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current > y.current); } - friend inline constexpr auto operator<=(const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current >= y.current); } - friend inline constexpr auto operator==(const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current == y.current); } - friend inline constexpr auto operator!=(const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current != y.current); } - friend inline constexpr auto operator>=(const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current <= y.current); } - friend inline constexpr auto operator> (const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current < y.current); } + friend constexpr auto operator< (const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current > y.current); } + friend constexpr auto operator<=(const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current >= y.current); } + friend constexpr auto operator==(const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current == y.current); } + friend constexpr auto operator!=(const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current != y.current); } + friend constexpr auto operator>=(const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current <= y.current); } + friend constexpr auto operator> (const reverse_iterator& x, const reverse_iterator& y) -> bool { return (x.current < y.current); } - friend inline constexpr auto operator-(const reverse_iterator& x, const reverse_iterator& y) -> typename reverse_iterator::difference_type + friend constexpr auto operator-(const reverse_iterator& x, const reverse_iterator& y) -> typename reverse_iterator::difference_type { return (y.current - x.current); } - friend inline constexpr auto operator+(typename reverse_iterator::difference_type n, const reverse_iterator& x) -> reverse_iterator + friend constexpr auto operator+(typename reverse_iterator::difference_type n, const reverse_iterator& x) -> reverse_iterator { return reverse_iterator(x.current - n); } @@ -654,7 +654,7 @@ WIDE_INTEGER_NODISCARD static constexpr auto max_size() -> size_type { return N; } template - constexpr auto swap(array& y) -> void + constexpr auto swap(array& y) noexcept -> void { swap_ranges_unsafe(begin(), end(), y.begin()); } @@ -723,7 +723,7 @@ } template - constexpr auto swap(array& x, array& y) -> void + constexpr auto swap(array& x, array& y) noexcept -> void { swap_ranges_unsafe(x.begin(), x.end(), y.begin()); } @@ -1857,24 +1857,24 @@ }; template - inline WIDE_INTEGER_CONSTEXPR auto lsb_helper(const UnsignedIntegralType& u) -> unsigned_fast_type; + WIDE_INTEGER_CONSTEXPR auto lsb_helper(const UnsignedIntegralType& u) -> unsigned_fast_type; template - inline WIDE_INTEGER_CONSTEXPR auto msb_helper(const UnsignedIntegralType& u) -> unsigned_fast_type; + WIDE_INTEGER_CONSTEXPR auto msb_helper(const UnsignedIntegralType& u) -> unsigned_fast_type; template<> - inline WIDE_INTEGER_CONSTEXPR auto msb_helper(const std::uint32_t& u) -> unsigned_fast_type; + WIDE_INTEGER_CONSTEXPR auto msb_helper(const std::uint32_t& u) -> unsigned_fast_type; template<> - inline WIDE_INTEGER_CONSTEXPR auto msb_helper(const std::uint16_t& u) -> unsigned_fast_type; + WIDE_INTEGER_CONSTEXPR auto msb_helper(const std::uint16_t& u) -> unsigned_fast_type; template<> - inline WIDE_INTEGER_CONSTEXPR auto msb_helper(const std::uint8_t& u) -> unsigned_fast_type; + WIDE_INTEGER_CONSTEXPR auto msb_helper(const std::uint8_t& u) -> unsigned_fast_type; // Use a local implementation of string copy. template - inline WIDE_INTEGER_CONSTEXPR auto strcpy_unsafe(DestinationIterator dst, SourceIterator src) -> DestinationIterator + WIDE_INTEGER_CONSTEXPR auto strcpy_unsafe(DestinationIterator dst, SourceIterator src) -> DestinationIterator { while((*dst++ = *src++) != '\0') { ; } // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) @@ -1882,7 +1882,7 @@ } // Use a local implementation of string length. - inline WIDE_INTEGER_CONSTEXPR auto strlen_unsafe(const char* p_str) -> unsigned_fast_type + WIDE_INTEGER_CONSTEXPR auto strlen_unsafe(const char* p_str) -> unsigned_fast_type { auto str_len_count = static_cast(UINT8_C(0)); @@ -6011,7 +6011,7 @@ #endif // !defined(WIDE_INTEGER_DISABLE_FLOAT_INTEROP) template - inline WIDE_INTEGER_CONSTEXPR auto lsb_helper(const UnsignedIntegralType& u) -> unsigned_fast_type + WIDE_INTEGER_CONSTEXPR auto lsb_helper(const UnsignedIntegralType& u) -> unsigned_fast_type { // Compile-time checks. static_assert(( std::is_integral::value @@ -6041,7 +6041,7 @@ } template - inline WIDE_INTEGER_CONSTEXPR auto msb_helper(const UnsignedIntegralType& u) -> unsigned_fast_type + WIDE_INTEGER_CONSTEXPR auto msb_helper(const UnsignedIntegralType& u) -> unsigned_fast_type { // Compile-time checks. static_assert(( std::is_integral::value @@ -6076,7 +6076,7 @@ } template<> - inline WIDE_INTEGER_CONSTEXPR auto msb_helper(const std::uint32_t& u) -> unsigned_fast_type + WIDE_INTEGER_CONSTEXPR auto msb_helper(const std::uint32_t& u) -> unsigned_fast_type { auto r = static_cast(UINT8_C(0)); auto x = static_cast(u); @@ -6092,7 +6092,7 @@ } template<> - inline WIDE_INTEGER_CONSTEXPR auto msb_helper(const std::uint16_t& u) -> unsigned_fast_type + WIDE_INTEGER_CONSTEXPR auto msb_helper(const std::uint16_t& u) -> unsigned_fast_type { auto r = static_cast(UINT8_C(0)); auto x = static_cast(u); @@ -6107,7 +6107,7 @@ } template<> - inline WIDE_INTEGER_CONSTEXPR auto msb_helper(const std::uint8_t& u) -> unsigned_fast_type + WIDE_INTEGER_CONSTEXPR auto msb_helper(const std::uint8_t& u) -> unsigned_fast_type { auto r = static_cast(UINT8_C(0)); auto x = static_cast(u); @@ -6139,7 +6139,7 @@ typename LimbType, typename AllocatorType, const bool IsSigned> - inline WIDE_INTEGER_CONSTEXPR auto lsb(const uintwide_t& x) -> unsigned_fast_type + WIDE_INTEGER_CONSTEXPR auto lsb(const uintwide_t& x) -> unsigned_fast_type { // Calculate the position of the least-significant bit. // Use a linear search starting from the least significant limbs. @@ -6849,14 +6849,14 @@ result_type param_a; // NOLINT(readability-identifier-naming) result_type param_b; // NOLINT(readability-identifier-naming) - friend inline constexpr auto operator==(const param_type& lhs, + friend constexpr auto operator==(const param_type& lhs, const param_type& rhs) -> bool { return ( (lhs.param_a == rhs.param_a) && (lhs.param_b == rhs.param_b)); } - friend inline constexpr auto operator!=(const param_type& lhs, + friend constexpr auto operator!=(const param_type& lhs, const param_type& rhs) -> bool { return ( (lhs.param_a != rhs.param_a) diff --git a/test/test.hpp b/test/test.hpp index 2a190ef..4524fff 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -18,7 +18,7 @@ namespace detail { template -inline typename std::enable_if::value || boost::multiprecision::is_unsigned_number::value), T>::type +typename std::enable_if::value || boost::multiprecision::is_unsigned_number::value), T>::type abs(const T& a) { return a < 0 ? -a : a; @@ -107,19 +107,19 @@ enum }; template -inline T epsilon_of(const T&) +T epsilon_of(const T&) { static_assert(std::numeric_limits::is_specialized, "No numeric_limits support"); return std::numeric_limits::is_integer ? static_cast(1) : std::numeric_limits::epsilon(); } template -inline int digits_of(const T&) +int digits_of(const T&) { return std::numeric_limits::is_specialized ? std::numeric_limits::digits10 + 3 : std::numeric_limits::digits10 + 3; } -inline std::ostream& report_where(const char* file, int line, const char* function) +std::ostream& report_where(const char* file, int line, const char* function) { if (function) BOOST_LIGHTWEIGHT_TEST_OSTREAM << "In function: " << function << std::endl; @@ -129,7 +129,7 @@ inline std::ostream& report_where(const char* file, int line, const char* functi #define BOOST_MP_REPORT_WHERE report_where(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION) -inline void report_severity(int severity) +void report_severity(int severity) { if (severity == error_on_fail) ++boost::detail::test_errors(); diff --git a/test/test_arithmetic.hpp b/test/test_arithmetic.hpp index e818d86..acec279 100644 --- a/test/test_arithmetic.hpp +++ b/test/test_arithmetic.hpp @@ -36,7 +36,7 @@ struct is_checked_cpp_int : public std::integral_constant // for __int128 and/or __float128: // template -inline const char* name_of() +const char* name_of() { return typeid(T).name(); } @@ -46,12 +46,12 @@ inline const char* name_of() #pragma GCC diagnostic ignored "-Wpedantic" #endif template <> -inline const char* name_of<__int128>() +const char* name_of<__int128>() { return "__int128"; } template <> -inline const char* name_of() +const char* name_of() { return "unsigned __int128"; } @@ -61,7 +61,7 @@ inline const char* name_of() #endif #ifdef BOOST_HAS_FLOAT128 //template <> -//inline const char* name_of<__float128>() +//const char* name_of<__float128>() //{ // return "__float128"; //} @@ -557,12 +557,12 @@ void test_signed_integer_ops(const std::integral_constant&) } template -inline Real negate_if_signed(Real r, const std::integral_constant&) +Real negate_if_signed(Real r, const std::integral_constant&) { return -r; } template -inline Real negate_if_signed(Real r, const std::integral_constant&) +Real negate_if_signed(Real r, const std::integral_constant&) { return r; } @@ -1959,7 +1959,7 @@ void test_mixed(const std::integral_constant&) } template -inline bool check_is_nan(const Real& val, const std::integral_constant&) +bool check_is_nan(const Real& val, const std::integral_constant&) { #ifndef BOOST_MP_STANDALONE return (boost::math::isnan)(val); @@ -1969,17 +1969,17 @@ inline bool check_is_nan(const Real& val, const std::integral_constant -inline bool check_is_nan(const Real&, const std::integral_constant&) +bool check_is_nan(const Real&, const std::integral_constant&) { return false; } template -inline Real negate_value(const Real& val, const std::integral_constant&) +Real negate_value(const Real& val, const std::integral_constant&) { return -val; } template -inline Real negate_value(const Real& val, const std::integral_constant&) +Real negate_value(const Real& val, const std::integral_constant&) { return val; } diff --git a/test/test_uintwide_t_edge_cases.cpp b/test/test_uintwide_t_edge_cases.cpp index 52618ef..702a5f6 100644 --- a/test/test_uintwide_t_edge_cases.cpp +++ b/test/test_uintwide_t_edge_cases.cpp @@ -109,15 +109,13 @@ constexpr auto loop_count_hi = static_cast(UINT16_C(8)); #endif #if defined(WIDE_INTEGER_NAMESPACE) -using local_uintwide_t_small_unsigned_type = - WIDE_INTEGER_NAMESPACE::math::wide_integer::uintwide_t; +using local_uintwide_t_small_unsigned_type = WIDE_INTEGER_NAMESPACE::math::wide_integer::uintwide_t; +using local_uintwide_t_half_unsigned_type = WIDE_INTEGER_NAMESPACE::math::wide_integer::uintwide_t; +using local_uintwide_t_half_signed_type = WIDE_INTEGER_NAMESPACE::math::wide_integer::uintwide_t; #else -using local_uintwide_t_small_unsigned_type = - ::math::wide_integer::uintwide_t; -using local_uintwide_t_half_unsigned_type = - ::math::wide_integer::uintwide_t; -using local_uintwide_t_half_signed_type = - ::math::wide_integer::uintwide_t; +using local_uintwide_t_small_unsigned_type = ::math::wide_integer::uintwide_t; +using local_uintwide_t_half_unsigned_type = ::math::wide_integer::uintwide_t; +using local_uintwide_t_half_signed_type = ::math::wide_integer::uintwide_t; #endif #if defined(WIDE_INTEGER_NAMESPACE) @@ -215,7 +213,7 @@ auto generate_wide_integer_value(bool is_positive = true, static_cast ( static_cast(c + 'A') - - static_cast(10) + - static_cast(INT8_C(10)) ); } } @@ -1453,8 +1451,8 @@ auto test_various_isolated_edge_cases() -> bool // NOLINT(readability-function-c auto dis = std::uniform_real_distribution { - static_cast(1.01F), - static_cast(1.04F) + static_cast(1.01F), // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) + static_cast(1.04F) // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) }; const auto inf_f = ::local_inf_f () * dis(eng_flt); @@ -2451,8 +2449,8 @@ auto test_uintwide_t_edge::zero_as_small_unsigned_type() -> const test_uintwide_ return local_zero_as_small_unsigned_type; } -extern test_uintwide_t_edge::local_uintwide_t_small_unsigned_type local_one_plus_as_small_signed_type; -extern test_uintwide_t_edge::local_uintwide_t_small_signed_type local_one_minus_as_small_signed_type; +extern test_uintwide_t_edge::local_uintwide_t_small_unsigned_type local_one_plus_as_small_signed_type; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables,cert-err58-cpp,) +extern test_uintwide_t_edge::local_uintwide_t_small_signed_type local_one_minus_as_small_signed_type; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables,cert-err58-cpp,) auto test_uintwide_t_edge::one_as_small_unsigned_type() -> const test_uintwide_t_edge::local_uintwide_t_small_unsigned_type& { return local_one_plus_as_small_signed_type; } auto test_uintwide_t_edge::m_one_as_small_signed_type() -> const test_uintwide_t_edge::local_uintwide_t_small_signed_type& { return local_one_minus_as_small_signed_type; }