diff --git a/.clang-tidy b/.clang-tidy index c13ca78ac2..84849db7a0 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -9,43 +9,90 @@ Checks: "-*, cppcoreguidelines-*, -cppcoreguidelines-avoid-c-arrays, + -cppcoreguidelines-avoid-capturing-lambda-coroutines, -cppcoreguidelines-avoid-const-or-ref-data-members, -cppcoreguidelines-avoid-do-while, + -cppcoreguidelines-avoid-goto, -cppcoreguidelines-avoid-magic-numbers, -cppcoreguidelines-avoid-non-const-global-variables, + -cppcoreguidelines-avoid-reference-coroutine-parameters, -cppcoreguidelines-c-copy-assignment-signature, + -cppcoreguidelines-explicit-virtual-functions, -cppcoreguidelines-interfaces-global-init, + -cppcoreguidelines-macro-to-enum, -cppcoreguidelines-macro-usage, -cppcoreguidelines-missing-std-forward, -cppcoreguidelines-narrowing-conversions, + -cppcoreguidelines-no-malloc, + -cppcoreguidelines-noexcept-destructor, -cppcoreguidelines-noexcept-move-operations, + -cppcoreguidelines-noexcept-swap, -cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-owning-memory, + -cppcoreguidelines-prefer-member-initializer, -cppcoreguidelines-pro-bounds-array-to-pointer-decay, -cppcoreguidelines-pro-bounds-avoid-unchecked-container-access, -cppcoreguidelines-pro-bounds-constant-array-index, -cppcoreguidelines-pro-bounds-pointer-arithmetic, + -cppcoreguidelines-pro-type-const-cast, + -cppcoreguidelines-pro-type-cstyle-cast, -cppcoreguidelines-pro-type-reinterpret-cast, -cppcoreguidelines-pro-type-union-access, + -cppcoreguidelines-pro-type-vararg, + -cppcoreguidelines-slicing, -cppcoreguidelines-special-member-functions, llvm-namespace-comment, misc-*, + -misc-anonymous-namespace-in-header, + -misc-confusable-identifiers, + -misc-coroutine-hostile-raii, + -misc-misleading-bidirectional, + -misc-misleading-identifier, -misc-multiple-inheritance, + -misc-new-delete-overloads, -misc-no-recursion, + -misc-non-copyable-objects, -misc-non-private-member-variables-in-classes, -misc-override-with-different-visibility, + -misc-predictable-rand, + -misc-unconventional-assign-operator, + -misc-uniqueptr-reset-release, -misc-unused-parameters, -misc-use-anonymous-namespace, -misc-use-internal-linkage, modernize-*, + -modernize-avoid-bind, -modernize-avoid-c-arrays, -modernize-avoid-c-style-cast, + -modernize-avoid-setjmp-longjmp, + -modernize-avoid-variadic-functions, + -modernize-deprecated-ios-base-aliases, + -modernize-loop-convert, + -modernize-macro-to-enum, + -modernize-min-max-use-initializer-list, + -modernize-raw-string-literal, + -modernize-redundant-void-arg, + -modernize-replace-auto-ptr, + -modernize-replace-disallow-copy-and-assign-macro, + -modernize-replace-random-shuffle, -modernize-return-braced-init-list, + -modernize-shrink-to-fit, + -modernize-unary-static-assert, + -modernize-use-auto, + -modernize-use-bool-literals, + -modernize-use-constraints, + -modernize-use-default-member-init, -modernize-use-integer-sign-comparison, + -modernize-use-noexcept, + -modernize-use-nullptr, + -modernize-use-std-format, + -modernize-use-std-print, -modernize-use-trailing-return-type, + -modernize-use-transparent-functors, + -modernize-use-uncaught-exceptions, performance-*, -performance-avoid-endl, diff --git a/.github/scripts/levelization/results/ordering.txt b/.github/scripts/levelization/results/ordering.txt index aee6f4c579..5cc49dd2f5 100644 --- a/.github/scripts/levelization/results/ordering.txt +++ b/.github/scripts/levelization/results/ordering.txt @@ -72,6 +72,7 @@ test.app > xrpl.server test.app > xrpl.shamap test.app > xrpl.tx test.basics > test.jtx +test.basics > test.unit_test test.basics > xrpl.basics test.basics > xrpl.core test.basics > xrpld.rpc @@ -161,6 +162,9 @@ test.protocol > test.unit_test test.protocol > xrpl.basics test.protocol > xrpl.json test.protocol > xrpl.protocol +test.resource > test.unit_test +test.resource > xrpl.basics +test.resource > xrpl.resource test.rpc > test.jtx test.rpc > xrpl.basics test.rpc > xrpl.config @@ -184,6 +188,12 @@ test.server > xrpld.core test.server > xrpl.json test.server > xrpl.protocol test.server > xrpl.server +test.shamap > test.unit_test +test.shamap > xrpl.basics +test.shamap > xrpl.config +test.shamap > xrpl.nodestore +test.shamap > xrpl.protocol +test.shamap > xrpl.shamap test.unit_test > xrpl.basics test.unit_test > xrpl.protocol tests.libxrpl > xrpl.basics @@ -195,7 +205,6 @@ tests.libxrpl > xrpl.net tests.libxrpl > xrpl.nodestore tests.libxrpl > xrpl.protocol tests.libxrpl > xrpl.protocol_autogen -tests.libxrpl > xrpl.resource tests.libxrpl > xrpl.server tests.libxrpl > xrpl.shamap tests.libxrpl > xrpl.tx diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 910bda8d4c..2e4521870d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -90,19 +90,20 @@ repos: - repo: https://github.com/streetsidesoftware/cspell-cli rev: ea11f9efc0bec520073405bc30552da887ba71bc # frozen: v10.0.1 hooks: - - id: cspell - name: check changed files spelling + - id: cspell # Spell check changed files exclude: | (?x)^( - \.cspell\.config\.yaml| + .config/cspell.config.yaml| include/xrpl/protocol_autogen/(transactions|ledger_entries)/.* )$ - - id: cspell + - id: cspell # Spell check the commit message name: check commit message spelling args: - --no-must-find-files - --no-progress - --no-summary + - --files + - .git/COMMIT_EDITMSG stages: [commit-msg] - repo: local diff --git a/BUILD.md b/BUILD.md index a15c94edc9..6ccdde12d5 100644 --- a/BUILD.md +++ b/BUILD.md @@ -25,7 +25,7 @@ You can verify that the required tools are installed and runnable with: | ----------- | --------------- | | GCC | 15.2 | | Clang | 22 | -| Apple Clang | 21 | +| Apple Clang | 17 | | MSVC | 19.44[^windows] | ## Operating Systems diff --git a/bin/pre-commit/clang_tidy_check.py b/bin/pre-commit/clang_tidy_check.py index 5b5792b405..d074c56acf 100755 --- a/bin/pre-commit/clang_tidy_check.py +++ b/bin/pre-commit/clang_tidy_check.py @@ -17,11 +17,9 @@ import subprocess import sys from pathlib import Path -CLANG_TIDY_VERSION = 22 - def find_run_clang_tidy() -> str | None: - for candidate in (f"run-clang-tidy-{CLANG_TIDY_VERSION}", "run-clang-tidy"): + for candidate in ("run-clang-tidy-21", "run-clang-tidy"): if path := shutil.which(candidate): return path return None @@ -46,8 +44,8 @@ def main(): run_clang_tidy = find_run_clang_tidy() if not run_clang_tidy: print( - f"clang-tidy check failed: TIDY is enabled but neither " - f"'run-clang-tidy-{CLANG_TIDY_VERSION}' nor 'run-clang-tidy' was found in PATH.", + "clang-tidy check failed: TIDY is enabled but neither " + "'run-clang-tidy-21' nor 'run-clang-tidy' was found in PATH.", file=sys.stderr, ) return 1 diff --git a/.cspell.config.yaml b/cspell.config.yaml similarity index 96% rename from .cspell.config.yaml rename to cspell.config.yaml index dc24bf833b..81216e9f29 100644 --- a/.cspell.config.yaml +++ b/cspell.config.yaml @@ -36,7 +36,9 @@ overrides: - /'[^']*'/g # single-quoted strings - /`[^`]*`/g # backtick strings suggestWords: - - unsynched->unsynced + - xprl->xrpl + - xprld->xrpld # cspell: disable-line not sure what this problem is.... + - unsynched->unsynced # cspell: disable-line not sure what this problem is.... - synched->synced - synch->sync words: diff --git a/include/xrpl/basics/Slice.h b/include/xrpl/basics/Slice.h index f87ca063b8..948d012958 100644 --- a/include/xrpl/basics/Slice.h +++ b/include/xrpl/basics/Slice.h @@ -211,17 +211,15 @@ operator<<(Stream& s, Slice const& v) } template -Slice +std::enable_if_t || std::is_same_v, Slice> makeSlice(std::array const& a) - requires(std::is_same_v || std::is_same_v) { return Slice(a.data(), a.size()); } template -Slice +std::enable_if_t || std::is_same_v, Slice> makeSlice(std::vector const& v) - requires(std::is_same_v || std::is_same_v) { return Slice(v.data(), v.size()); } diff --git a/include/xrpl/basics/TaggedCache.h b/include/xrpl/basics/TaggedCache.h index 16c87cf833..71ebfc57a4 100644 --- a/include/xrpl/basics/TaggedCache.h +++ b/include/xrpl/basics/TaggedCache.h @@ -212,13 +212,11 @@ public: */ template auto - insert(key_type const& key, T const& value) -> ReturnType - requires(!IsKeyCache); + insert(key_type const& key, T const& value) -> std::enable_if_t; template auto - insert(key_type const& key) -> ReturnType - requires IsKeyCache; + insert(key_type const& key) -> std::enable_if_t; // VFALCO NOTE It looks like this returns a copy of the data in // the output parameter 'data'. This could be expensive. diff --git a/include/xrpl/basics/TaggedCache.ipp b/include/xrpl/basics/TaggedCache.ipp index b79561c71a..ffcd533216 100644 --- a/include/xrpl/basics/TaggedCache.ipp +++ b/include/xrpl/basics/TaggedCache.ipp @@ -57,10 +57,7 @@ inline TaggedCache< beast::insight::Collector::ptr const& collector) : journal_(journal) , clock_(clock) - , stats_( - name, - [this] { collectMetrics(); }, - collector) + , stats_(name, std::bind(&TaggedCache::collectMetrics, this), collector) , name_(name) , targetSize_(size) , targetAge_(expiration) @@ -503,8 +500,7 @@ template < template inline auto TaggedCache:: - insert(key_type const& key, T const& value) -> ReturnType - requires(!IsKeyCache) + insert(key_type const& key, T const& value) -> std::enable_if_t { static_assert( std::is_same_v, SharedPointerType> || @@ -534,8 +530,7 @@ template < template inline auto TaggedCache:: - insert(key_type const& key) -> ReturnType - requires IsKeyCache + insert(key_type const& key) -> std::enable_if_t { std::scoped_lock const lock(mutex_); clock_type::time_point const now(clock_.now()); diff --git a/include/xrpl/basics/ToString.h b/include/xrpl/basics/ToString.h index e9f8f43633..7764c1e3e3 100644 --- a/include/xrpl/basics/ToString.h +++ b/include/xrpl/basics/ToString.h @@ -12,9 +12,8 @@ namespace xrpl { */ template -std::string +std::enable_if_t, std::string> to_string(T t) // NOLINT(readability-identifier-naming) - requires(std::is_arithmetic_v) { return std::to_string(t); } diff --git a/include/xrpl/basics/base_uint.h b/include/xrpl/basics/base_uint.h index 481a7dbd77..e6ca1993f9 100644 --- a/include/xrpl/basics/base_uint.h +++ b/include/xrpl/basics/base_uint.h @@ -97,7 +97,7 @@ public: // static constexpr std::size_t kBytes = Bits / 8; - static_assert(sizeof(data_) == kBytes); + static_assert(sizeof(data_) == kBytes, ""); using size_type = std::size_t; using difference_type = std::ptrdiff_t; @@ -280,11 +280,12 @@ public: { } - template - explicit BaseUInt(Container const& c) - requires( + template < + class Container, + class = std::enable_if_t< detail::IsContiguousContainer::value && - std::is_trivially_copyable_v) + std::is_trivially_copyable_v>> + explicit BaseUInt(Container const& c) { // Use AlwaysFalseT so the static_assert condition is dependent // and only triggers when this constructor template is instantiated. @@ -294,12 +295,13 @@ public: "Use base_uint::fromRaw instead."); } - template + template < + class Container, + class = std::enable_if_t< + detail::IsContiguousContainer::value && + std::is_trivially_copyable_v>> static BaseUInt fromRaw(Container const& c) - requires( - detail::IsContiguousContainer::value && - std::is_trivially_copyable_v) { BaseUInt result; XRPL_ASSERT( @@ -310,11 +312,11 @@ public: } template - BaseUInt& + std::enable_if_t< + detail::IsContiguousContainer::value && + std::is_trivially_copyable_v, + BaseUInt&> operator=(Container const& c) - requires( - detail::IsContiguousContainer::value && - std::is_trivially_copyable_v) { XRPL_ASSERT( c.size() * sizeof(typename Container::value_type) == size(), diff --git a/include/xrpl/basics/comparators.h b/include/xrpl/basics/comparators.h new file mode 100644 index 0000000000..0e21d38d6b --- /dev/null +++ b/include/xrpl/basics/comparators.h @@ -0,0 +1,54 @@ +#pragma once + +#include + +namespace xrpl { + +#ifdef _MSC_VER + +/* + * MSVC 2019 version 16.9.0 added [[nodiscard]] to the std comparison + * operator() functions. boost::bimap checks that the comparator is a + * BinaryFunction, in part by calling the function and ignoring the value. + * These two things don't play well together. These wrapper classes simply + * strip [[nodiscard]] from operator() for use in boost::bimap. + * + * See also: + * https://www.boost.org/doc/libs/1_75_0/libs/bimap/doc/html/boost_bimap/the_tutorial/controlling_collection_types.html + */ + +template +struct less +{ + using result_type = bool; + + constexpr bool + operator()(T const& left, T const& right) const + { + return std::less()(left, right); + } +}; + +template +struct equal_to +{ + using result_type = bool; + + constexpr bool + operator()(T const& left, T const& right) const + { + return std::equal_to()(left, right); + } +}; + +#else + +template +using less = std::less; + +template +using equal_to = std::equal_to; + +#endif + +} // namespace xrpl diff --git a/include/xrpl/basics/partitioned_unordered_map.h b/include/xrpl/basics/partitioned_unordered_map.h index e78043e252..c2750a5769 100644 --- a/include/xrpl/basics/partitioned_unordered_map.h +++ b/include/xrpl/basics/partitioned_unordered_map.h @@ -138,8 +138,11 @@ public: { } - ConstIterator(Iterator const& orig) : map(orig.map), ait(orig.ait), mit(orig.mit) + ConstIterator(Iterator const& orig) { + map = orig.map; + ait = orig.ait; + mit = orig.mit; } const_reference @@ -228,11 +231,11 @@ private: public: PartitionedUnorderedMap(std::optional partitions = std::nullopt) + { // Set partitions to the number of hardware threads if the parameter // is either empty or set to 0. - : partitions_( - partitions && (*partitions != 0u) ? *partitions : std::thread::hardware_concurrency()) - { + partitions_ = + partitions && (*partitions != 0u) ? *partitions : std::thread::hardware_concurrency(); map_.resize(partitions_); XRPL_ASSERT( partitions_, diff --git a/include/xrpl/basics/random.h b/include/xrpl/basics/random.h index c544e7d0c8..cceaa6f029 100644 --- a/include/xrpl/basics/random.h +++ b/include/xrpl/basics/random.h @@ -91,9 +91,8 @@ defaultPrng() */ /** @{ */ template -Integral +std::enable_if_t && detail::is_engine::value, Integral> randInt(Engine& engine, Integral min, Integral max) - requires(std::is_integral_v && detail::is_engine::value) { XRPL_ASSERT(max > min, "xrpl::randInt : max over min inputs"); @@ -104,41 +103,36 @@ randInt(Engine& engine, Integral min, Integral max) } template -Integral +std::enable_if_t, Integral> randInt(Integral min, Integral max) - requires(std::is_integral_v) { return randInt(defaultPrng(), min, max); } template -Integral +std::enable_if_t && detail::is_engine::value, Integral> randInt(Engine& engine, Integral max) - requires(std::is_integral_v && detail::is_engine::value) { return randInt(engine, Integral(0), max); } template -Integral +std::enable_if_t, Integral> randInt(Integral max) - requires(std::is_integral_v) { return randInt(defaultPrng(), max); } template -Integral +std::enable_if_t && detail::is_engine::value, Integral> randInt(Engine& engine) - requires(std::is_integral_v && detail::is_engine::value) { return randInt(engine, std::numeric_limits::max()); } template -Integral +std::enable_if_t, Integral> randInt() - requires(std::is_integral_v) { return randInt(defaultPrng(), std::numeric_limits::max()); } @@ -147,20 +141,19 @@ randInt() /** Return a random byte */ /** @{ */ template -Byte +std::enable_if_t< + (std::is_same_v || std::is_same_v) && + detail::is_engine::value, + Byte> randByte(Engine& engine) - requires( - (std::is_same_v || std::is_same_v) && - detail::is_engine::value) { return static_cast(randInt( engine, std::numeric_limits::min(), std::numeric_limits::max())); } template -Byte +std::enable_if_t<(std::is_same_v || std::is_same_v), Byte> randByte() - requires(std::is_same_v || std::is_same_v) { return randByte(defaultPrng()); } diff --git a/include/xrpl/basics/safe_cast.h b/include/xrpl/basics/safe_cast.h index 7f2b93a7eb..714146e089 100644 --- a/include/xrpl/basics/safe_cast.h +++ b/include/xrpl/basics/safe_cast.h @@ -1,7 +1,5 @@ #pragma once -#include // IWYU pragma: keep - #include namespace xrpl { @@ -17,9 +15,8 @@ concept SafeToCast = (std::is_integral_v && std::is_integral_v) && : sizeof(Dest) >= sizeof(Src)); template -constexpr Dest +constexpr std::enable_if_t && std::is_integral_v, Dest> safeCast(Src s) noexcept - requires(std::is_integral_v && std::is_integral_v) { static_assert( std::is_signed_v || std::is_unsigned_v, "Cannot cast signed to unsigned"); @@ -31,17 +28,15 @@ safeCast(Src s) noexcept } template -constexpr Dest +constexpr std::enable_if_t && std::is_integral_v, Dest> safeCast(Src s) noexcept - requires(std::is_enum_v && std::is_integral_v) { return static_cast(safeCast>(s)); } template -constexpr Dest +constexpr std::enable_if_t && std::is_enum_v, Dest> safeCast(Src s) noexcept - requires(std::is_integral_v && std::is_enum_v) { return safeCast(static_cast>(s)); } @@ -51,9 +46,8 @@ safeCast(Src s) noexcept // underlying types become safe, it can be converted to a safe_cast. template -constexpr Dest +constexpr std::enable_if_t && std::is_integral_v, Dest> unsafeCast(Src s) noexcept - requires(std::is_integral_v && std::is_integral_v) { static_assert( !SafeToCast, @@ -63,17 +57,15 @@ unsafeCast(Src s) noexcept } template -constexpr Dest +constexpr std::enable_if_t && std::is_integral_v, Dest> unsafeCast(Src s) noexcept - requires(std::is_enum_v && std::is_integral_v) { return static_cast(unsafeCast>(s)); } template -constexpr Dest +constexpr std::enable_if_t && std::is_enum_v, Dest> unsafeCast(Src s) noexcept - requires(std::is_integral_v && std::is_enum_v) { return unsafeCast(static_cast>(s)); } diff --git a/include/xrpl/basics/scope.h b/include/xrpl/basics/scope.h index e63bb69eb5..cfd21e6e30 100644 --- a/include/xrpl/basics/scope.h +++ b/include/xrpl/basics/scope.h @@ -46,9 +46,11 @@ public: operator=(ScopeExit&&) = delete; template - explicit ScopeExit(EFP&& f) noexcept - requires( - !std::is_same_v, ScopeExit> && std::is_constructible_v) + explicit ScopeExit( + EFP&& f, + std::enable_if_t< + !std::is_same_v, ScopeExit> && + std::is_constructible_v>* = 0) noexcept : exitFunction_{std::forward(f)} { static_assert(std::is_nothrow_constructible_v(f))>); @@ -91,9 +93,11 @@ public: operator=(ScopeFail&&) = delete; template - explicit ScopeFail(EFP&& f) noexcept - requires( - !std::is_same_v, ScopeFail> && std::is_constructible_v) + explicit ScopeFail( + EFP&& f, + std::enable_if_t< + !std::is_same_v, ScopeFail> && + std::is_constructible_v>* = 0) noexcept : exitFunction_{std::forward(f)} { static_assert(std::is_nothrow_constructible_v(f))>); @@ -136,11 +140,12 @@ public: operator=(ScopeSuccess&&) = delete; template - explicit ScopeSuccess(EFP&& f) noexcept( - std::is_nothrow_constructible_v || std::is_nothrow_constructible_v) - requires( + explicit ScopeSuccess( + EFP&& f, + std::enable_if_t< !std::is_same_v, ScopeSuccess> && - std::is_constructible_v) + std::is_constructible_v>* = + 0) noexcept(std::is_nothrow_constructible_v || std::is_nothrow_constructible_v) : exitFunction_{std::forward(f)} { } diff --git a/include/xrpl/basics/tagged_integer.h b/include/xrpl/basics/tagged_integer.h index 5a088db863..8fbd2a274b 100644 --- a/include/xrpl/basics/tagged_integer.h +++ b/include/xrpl/basics/tagged_integer.h @@ -43,10 +43,10 @@ public: TaggedInteger() = default; - template - explicit constexpr TaggedInteger(OtherInt value) noexcept - requires(std::is_integral_v && sizeof(OtherInt) <= sizeof(Int)) - : value_(value) + template < + class OtherInt, + class = std::enable_if_t && sizeof(OtherInt) <= sizeof(Int)>> + explicit constexpr TaggedInteger(OtherInt value) noexcept : value_(value) { static_assert(sizeof(TaggedInteger) == sizeof(Int), "tagged_integer is adding padding"); } diff --git a/include/xrpl/beast/container/aged_container_utility.h b/include/xrpl/beast/container/aged_container_utility.h index f43e59b0f7..7cda863fab 100644 --- a/include/xrpl/beast/container/aged_container_utility.h +++ b/include/xrpl/beast/container/aged_container_utility.h @@ -4,14 +4,14 @@ #include #include +#include namespace beast { /** Expire aged container items past the specified age. */ template -std::size_t +std::enable_if_t::value, std::size_t> expire(AgedContainer& c, std::chrono::duration const& age) - requires(IsAgedContainer::value) { std::size_t n(0); auto const expired(c.clock().now() - age); diff --git a/include/xrpl/beast/container/detail/aged_container_iterator.h b/include/xrpl/beast/container/detail/aged_container_iterator.h index d6c061bb86..02fb3927dd 100644 --- a/include/xrpl/beast/container/detail/aged_container_iterator.h +++ b/include/xrpl/beast/container/detail/aged_container_iterator.h @@ -30,19 +30,20 @@ public: // Disable constructing a const_iterator from a non-const_iterator. // Converting between reverse and non-reverse iterators should be explicit. - template - explicit AgedContainerIterator(AgedContainerIterator const& other) - requires( + template < + bool OtherIsConst, + class OtherIterator, + class = std::enable_if_t< (!OtherIsConst || IsConst) && - !static_cast(std::is_same_v)) + !static_cast(std::is_same_v)>> + explicit AgedContainerIterator(AgedContainerIterator const& other) : iter_(other.iter_) { } // Disable constructing a const_iterator from a non-const_iterator. - template + template > AgedContainerIterator(AgedContainerIterator const& other) - requires(!OtherIsConst || IsConst) : iter_(other.iter_) { } @@ -51,8 +52,7 @@ public: template auto operator=(AgedContainerIterator const& other) - -> AgedContainerIterator& - requires(!OtherIsConst || IsConst) + -> std::enable_if_t { iter_ = other.iter_; return *this; diff --git a/include/xrpl/beast/container/detail/aged_ordered_container.h b/include/xrpl/beast/container/detail/aged_ordered_container.h index c98f16022f..0533a51f00 100644 --- a/include/xrpl/beast/container/detail/aged_ordered_container.h +++ b/include/xrpl/beast/container/detail/aged_ordered_container.h @@ -111,9 +111,10 @@ private: { } - template + template < + class... Args, + class = std::enable_if_t>> Element(time_point const& when, Args&&... args) - requires(std::is_constructible_v) : value(std::forward(args)...), when(when) { } @@ -359,7 +360,6 @@ private: deleteElement(Element const* p) { ElementAllocatorTraits::destroy(config_.alloc(), p); - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) ElementAllocatorTraits::deallocate(config_.alloc(), const_cast(p), 1); } @@ -608,25 +608,35 @@ public: // //-------------------------------------------------------------------------- - template + template < + class K, + bool MaybeMulti = IsMulti, + bool MaybeMap = IsMap, + class = std::enable_if_t> std::conditional_t& - at(K const& k) - requires(MaybeMap && !MaybeMulti); + at(K const& k); - template + template < + class K, + bool MaybeMulti = IsMulti, + bool MaybeMap = IsMap, + class = std::enable_if_t> std::conditional::type const& - at(K const& k) const - requires(MaybeMap && !MaybeMulti); + at(K const& k) const; - template + template < + bool MaybeMulti = IsMulti, + bool MaybeMap = IsMap, + class = std::enable_if_t> std::conditional_t& - operator[](Key const& key) - requires(MaybeMap && !MaybeMulti); + operator[](Key const& key); - template + template < + bool MaybeMulti = IsMulti, + bool MaybeMap = IsMap, + class = std::enable_if_t> std::conditional_t& - operator[](Key&& key) - requires(MaybeMap && !MaybeMulti); + operator[](Key&& key); //-------------------------------------------------------------------------- // @@ -760,40 +770,35 @@ public: // map, set template auto - insert(value_type const& value) -> std::pair - requires(!MaybeMulti); + insert(value_type const& value) -> std::enable_if_t>; // multimap, multiset template auto - insert(value_type const& value) -> iterator - requires MaybeMulti; + insert(value_type const& value) -> std::enable_if_t; // set template auto - insert(value_type&& value) -> std::pair - requires(!MaybeMulti && !MaybeMap); + insert(value_type&& value) + -> std::enable_if_t>; // multiset template auto - insert(value_type&& value) -> iterator - requires(MaybeMulti && !MaybeMap); + insert(value_type&& value) -> std::enable_if_t; //--- // map, set template auto - insert(const_iterator hint, value_type const& value) -> iterator - requires(!MaybeMulti); + insert(const_iterator hint, value_type const& value) -> std::enable_if_t; // multimap, multiset template - iterator + std::enable_if_t insert(const_iterator /*hint*/, value_type const& value) - requires MaybeMulti { // VFALCO TODO Figure out how to utilize 'hint' return insert(value); @@ -802,14 +807,12 @@ public: // map, set template auto - insert(const_iterator hint, value_type&& value) -> iterator - requires(!MaybeMulti); + insert(const_iterator hint, value_type&& value) -> std::enable_if_t; // multimap, multiset template - iterator + std::enable_if_t insert(const_iterator /*hint*/, value_type&& value) - requires MaybeMulti { // VFALCO TODO Figure out how to utilize 'hint' return insert(std::move(value)); @@ -817,18 +820,20 @@ public: // map, multimap template - std::conditional_t> + std::enable_if_t< + MaybeMap && std::is_constructible_v, + std::conditional_t>> insert(P&& value) - requires(MaybeMap && std::is_constructible_v) { return emplace(std::forward

(value)); } // map, multimap template - std::conditional_t> + std::enable_if_t< + MaybeMap && std::is_constructible_v, + std::conditional_t>> insert(const_iterator hint, P&& value) - requires(MaybeMap && std::is_constructible_v) { return emplaceHint(hint, std::forward

(value)); } @@ -850,45 +855,46 @@ public: // map, set template auto - emplace(Args&&... args) -> std::pair - requires(!MaybeMulti); + emplace(Args&&... args) -> std::enable_if_t>; // multiset, multimap template auto - emplace(Args&&... args) -> iterator - requires MaybeMulti; + emplace(Args&&... args) -> std::enable_if_t; // map, set template auto - emplaceHint(const_iterator hint, Args&&... args) -> std::pair - requires(!MaybeMulti); + emplaceHint(const_iterator hint, Args&&... args) + -> std::enable_if_t>; // multiset, multimap template - iterator + std::enable_if_t emplaceHint(const_iterator /*hint*/, Args&&... args) - requires MaybeMulti { // VFALCO TODO Figure out how to utilize 'hint' return emplace(std::forward(args)...); } - // The constraint prevents erase (reverse_iterator pos) from compiling - template + // enable_if prevents erase (reverse_iterator pos) from compiling + template < + bool IsConst, + class Iterator, + class = std::enable_if_t::value>> beast::detail::AgedContainerIterator - erase(beast::detail::AgedContainerIterator pos) - requires(!IsBoostReverseIterator::value); + erase(beast::detail::AgedContainerIterator pos); - // The constraint prevents erase (reverse_iterator first, reverse_iterator last) + // enable_if prevents erase (reverse_iterator first, reverse_iterator last) // from compiling - template + template < + bool IsConst, + class Iterator, + class = std::enable_if_t::value>> beast::detail::AgedContainerIterator erase( beast::detail::AgedContainerIterator first, - beast::detail::AgedContainerIterator last) - requires(!IsBoostReverseIterator::value); + beast::detail::AgedContainerIterator last); template auto @@ -899,11 +905,13 @@ public: //-------------------------------------------------------------------------- - // The constraint prevents touch (reverse_iterator pos) from compiling - template + // enable_if prevents touch (reverse_iterator pos) from compiling + template < + bool IsConst, + class Iterator, + class = std::enable_if_t::value>> void touch(beast::detail::AgedContainerIterator pos) - requires(!IsBoostReverseIterator::value) { touch(pos, clock().now()); } @@ -1134,25 +1142,25 @@ public: } private: - // The constraint prevents erase (reverse_iterator pos, now) from compiling - template + // enable_if prevents erase (reverse_iterator pos, now) from compiling + template < + bool IsConst, + class Iterator, + class = std::enable_if_t::value>> void touch( beast::detail::AgedContainerIterator pos, - clock_type::time_point const& now) - requires(!IsBoostReverseIterator::value); + clock_type::time_point const& now); template < bool MaybePropagate = std::allocator_traits::propagate_on_container_swap::value> - void - swapData(AgedOrderedContainer& other) noexcept - requires MaybePropagate; + std::enable_if_t + swapData(AgedOrderedContainer& other) noexcept; template < bool MaybePropagate = std::allocator_traits::propagate_on_container_swap::value> - void - swapData(AgedOrderedContainer& other) noexcept - requires(!MaybePropagate); + std::enable_if_t + swapData(AgedOrderedContainer& other) noexcept; private: ConfigT config_; @@ -1361,10 +1369,9 @@ AgedOrderedContainer::operato //------------------------------------------------------------------------------ template -template +template std::conditional_t& AgedOrderedContainer::at(K const& k) - requires(MaybeMap && !MaybeMulti) { auto const iter(cont_.find(k, std::cref(config_.keyCompare()))); if (iter == cont_.end()) @@ -1373,10 +1380,9 @@ AgedOrderedContainer::at(K co } template -template +template std::conditional::type const& AgedOrderedContainer::at(K const& k) const - requires(MaybeMap && !MaybeMulti) { auto const iter(cont_.find(k, std::cref(config_.keyCompare()))); if (iter == cont_.end()) @@ -1385,10 +1391,9 @@ AgedOrderedContainer::at(K co } template -template +template std::conditional_t& AgedOrderedContainer::operator[](Key const& key) - requires(MaybeMap && !MaybeMulti) { typename cont_type::insert_commit_data d; auto const result(cont_.insert_check(key, std::cref(config_.keyCompare()), d)); @@ -1404,10 +1409,9 @@ AgedOrderedContainer::operato } template -template +template std::conditional_t& AgedOrderedContainer::operator[](Key&& key) - requires(MaybeMap && !MaybeMulti) { typename cont_type::insert_commit_data d; auto const result(cont_.insert_check(key, std::cref(config_.keyCompare()), d)); @@ -1441,8 +1445,7 @@ template auto AgedOrderedContainer::insert( - value_type const& value) -> std::pair - requires(!MaybeMulti) + value_type const& value) -> std::enable_if_t> { typename cont_type::insert_commit_data d; auto const result(cont_.insert_check(extract(value), std::cref(config_.keyCompare()), d)); @@ -1461,8 +1464,7 @@ template auto AgedOrderedContainer::insert( - value_type const& value) -> iterator - requires MaybeMulti + value_type const& value) -> std::enable_if_t { auto const before(cont_.upper_bound(extract(value), std::cref(config_.keyCompare()))); Element* const p(newElement(value)); @@ -1476,8 +1478,7 @@ template auto AgedOrderedContainer::insert(value_type&& value) - -> std::pair - requires(!MaybeMulti && !MaybeMap) + -> std::enable_if_t> { typename cont_type::insert_commit_data d; auto const result(cont_.insert_check(extract(value), std::cref(config_.keyCompare()), d)); @@ -1496,8 +1497,7 @@ template auto AgedOrderedContainer::insert(value_type&& value) - -> iterator - requires(MaybeMulti && !MaybeMap) + -> std::enable_if_t { auto const before(cont_.upper_bound(extract(value), std::cref(config_.keyCompare()))); Element* const p(newElement(std::move(value))); @@ -1514,8 +1514,7 @@ template auto AgedOrderedContainer::insert( const_iterator hint, - value_type const& value) -> iterator - requires(!MaybeMulti) + value_type const& value) -> std::enable_if_t { typename cont_type::insert_commit_data d; auto const result( @@ -1536,8 +1535,7 @@ template auto AgedOrderedContainer::insert( const_iterator hint, - value_type&& value) -> iterator - requires(!MaybeMulti) + value_type&& value) -> std::enable_if_t { typename cont_type::insert_commit_data d; auto const result( @@ -1557,8 +1555,7 @@ template auto AgedOrderedContainer::emplace(Args&&... args) - -> std::pair - requires(!MaybeMulti) + -> std::enable_if_t> { // VFALCO NOTE Its unfortunate that we need to // construct element here @@ -1580,8 +1577,7 @@ template auto AgedOrderedContainer::emplace(Args&&... args) - -> iterator - requires MaybeMulti + -> std::enable_if_t { Element* const p(newElement(std::forward(args)...)); auto const before(cont_.upper_bound(extract(p->value), std::cref(config_.keyCompare()))); @@ -1596,8 +1592,7 @@ template auto AgedOrderedContainer::emplaceHint( const_iterator hint, - Args&&... args) -> std::pair - requires(!MaybeMulti) + Args&&... args) -> std::enable_if_t> { // VFALCO NOTE Its unfortunate that we need to // construct element here @@ -1616,23 +1611,21 @@ AgedOrderedContainer::emplace } template -template +template beast::detail::AgedContainerIterator AgedOrderedContainer::erase( beast::detail::AgedContainerIterator pos) - requires(!IsBoostReverseIterator::value) { unlinkAndDeleteElement(&*((pos++).iterator())); return beast::detail::AgedContainerIterator(pos.iterator()); } template -template +template beast::detail::AgedContainerIterator AgedOrderedContainer::erase( beast::detail::AgedContainerIterator first, beast::detail::AgedContainerIterator last) - requires(!IsBoostReverseIterator::value) { for (; first != last;) unlinkAndDeleteElement(&*((first++).iterator())); @@ -1735,12 +1728,11 @@ AgedOrderedContainer::operato //------------------------------------------------------------------------------ template -template +template void AgedOrderedContainer::touch( beast::detail::AgedContainerIterator pos, clock_type::time_point const& now) - requires(!IsBoostReverseIterator::value) { auto& e(*pos.iterator()); e.when = now; @@ -1750,10 +1742,9 @@ AgedOrderedContainer::touch( template template -void +std::enable_if_t AgedOrderedContainer::swapData( AgedOrderedContainer& other) noexcept - requires MaybePropagate { std::swap(config_.keyCompare(), other.config_.keyCompare()); std::swap(config_.alloc(), other.config_.alloc()); @@ -1762,10 +1753,9 @@ AgedOrderedContainer::swapDat template template -void +std::enable_if_t AgedOrderedContainer::swapData( AgedOrderedContainer& other) noexcept - requires(!MaybePropagate) { std::swap(config_.keyCompare(), other.config_.keyCompare()); std::swap(config_.clock, other.config_.clock); diff --git a/include/xrpl/beast/container/detail/aged_unordered_container.h b/include/xrpl/beast/container/detail/aged_unordered_container.h index 9be9e96ba2..782f36cd52 100644 --- a/include/xrpl/beast/container/detail/aged_unordered_container.h +++ b/include/xrpl/beast/container/detail/aged_unordered_container.h @@ -117,9 +117,10 @@ private: { } - template + template < + class... Args, + class = std::enable_if_t>> Element(time_point const& when, Args&&... args) - requires(std::is_constructible_v) : value(std::forward(args)...), when(when) { } @@ -528,7 +529,6 @@ private: deleteElement(Element const* p) { ElementAllocatorTraits::destroy(config_.alloc(), p); - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) ElementAllocatorTraits::deallocate(config_.alloc(), const_cast(p), 1); } @@ -841,25 +841,35 @@ public: // //-------------------------------------------------------------------------- - template + template < + class K, + bool MaybeMulti = IsMulti, + bool MaybeMap = IsMap, + class = std::enable_if_t> std::conditional_t& - at(K const& k) - requires(MaybeMap && !MaybeMulti); + at(K const& k); - template + template < + class K, + bool MaybeMulti = IsMulti, + bool MaybeMap = IsMap, + class = std::enable_if_t> std::conditional::type const& - at(K const& k) const - requires(MaybeMap && !MaybeMulti); + at(K const& k) const; - template + template < + bool MaybeMulti = IsMulti, + bool MaybeMap = IsMap, + class = std::enable_if_t> std::conditional_t& - operator[](Key const& key) - requires(MaybeMap && !MaybeMulti); + operator[](Key const& key); - template + template < + bool MaybeMulti = IsMulti, + bool MaybeMap = IsMap, + class = std::enable_if_t> std::conditional_t& - operator[](Key&& key) - requires(MaybeMap && !MaybeMulti); + operator[](Key&& key); //-------------------------------------------------------------------------- // @@ -957,32 +967,28 @@ public: // map, set template auto - insert(value_type const& value) -> std::pair - requires(!MaybeMulti); + insert(value_type const& value) -> std::enable_if_t>; // multimap, multiset template auto - insert(value_type const& value) -> iterator - requires MaybeMulti; + insert(value_type const& value) -> std::enable_if_t; // map, set template auto - insert(value_type&& value) -> std::pair - requires(!MaybeMulti && !MaybeMap); + insert(value_type&& value) + -> std::enable_if_t>; // multimap, multiset template auto - insert(value_type&& value) -> iterator - requires(MaybeMulti && !MaybeMap); + insert(value_type&& value) -> std::enable_if_t; // map, set template - iterator + std::enable_if_t insert(const_iterator /*hint*/, value_type const& value) - requires(!MaybeMulti) { // Hint is ignored but we provide the interface so // callers may use ordered and unordered interchangeably. @@ -991,9 +997,8 @@ public: // multimap, multiset template - iterator + std::enable_if_t insert(const_iterator /*hint*/, value_type const& value) - requires MaybeMulti { // VFALCO TODO The hint could be used to let // the client order equal ranges @@ -1002,9 +1007,8 @@ public: // map, set template - iterator + std::enable_if_t insert(const_iterator /*hint*/, value_type&& value) - requires(!MaybeMulti) { // Hint is ignored but we provide the interface so // callers may use ordered and unordered interchangeably. @@ -1013,9 +1017,8 @@ public: // multimap, multiset template - iterator + std::enable_if_t insert(const_iterator /*hint*/, value_type&& value) - requires MaybeMulti { // VFALCO TODO The hint could be used to let // the client order equal ranges @@ -1024,18 +1027,20 @@ public: // map, multimap template - std::conditional_t> + std::enable_if_t< + MaybeMap && std::is_constructible_v, + std::conditional_t>> insert(P&& value) - requires(MaybeMap && std::is_constructible_v) { return emplace(std::forward

(value)); } // map, multimap template - std::conditional_t> + std::enable_if_t< + MaybeMap && std::is_constructible_v, + std::conditional_t>> insert(const_iterator hint, P&& value) - requires(MaybeMap && std::is_constructible_v) { return emplaceHint(hint, std::forward

(value)); } @@ -1056,26 +1061,23 @@ public: // set, map template auto - emplace(Args&&... args) -> std::pair - requires(!MaybeMulti); + emplace(Args&&... args) -> std::enable_if_t>; // multiset, multimap template auto - emplace(Args&&... args) -> iterator - requires MaybeMulti; + emplace(Args&&... args) -> std::enable_if_t; // set, map template auto - emplaceHint(const_iterator /*hint*/, Args&&... args) -> std::pair - requires(!MaybeMulti); + emplaceHint(const_iterator /*hint*/, Args&&... args) + -> std::enable_if_t>; // multiset, multimap template - iterator + std::enable_if_t emplaceHint(const_iterator /*hint*/, Args&&... args) - requires MaybeMulti { // VFALCO TODO The hint could be used for multi, to let // the client order equal ranges @@ -1306,7 +1308,7 @@ public: class OtherHash, class OtherAllocator, bool MaybeMulti = IsMulti> - bool + std::enable_if_t operator==(AgedUnorderedContainer< false, OtherIsMap, @@ -1315,8 +1317,7 @@ public: OtherDuration, OtherHash, KeyEqual, - OtherAllocator> const& other) const - requires(!MaybeMulti); + OtherAllocator> const& other) const; template < bool OtherIsMap, @@ -1326,7 +1327,7 @@ public: class OtherHash, class OtherAllocator, bool MaybeMulti = IsMulti> - bool + std::enable_if_t operator==(AgedUnorderedContainer< true, OtherIsMap, @@ -1335,8 +1336,7 @@ public: OtherDuration, OtherHash, KeyEqual, - OtherAllocator> const& other) const - requires MaybeMulti; + OtherAllocator> const& other) const; template < bool OtherIsMulti, @@ -1381,14 +1381,13 @@ private: // map, set template auto - insertUnchecked(value_type const& value) -> std::pair - requires(!MaybeMulti); + insertUnchecked(value_type const& value) + -> std::enable_if_t>; // multimap, multiset template auto - insertUnchecked(value_type const& value) -> iterator - requires MaybeMulti; + insertUnchecked(value_type const& value) -> std::enable_if_t; template void @@ -1429,9 +1428,8 @@ private: template < bool MaybePropagate = std::allocator_traits::propagate_on_container_swap::value> - void + std::enable_if_t swapData(AgedUnorderedContainer& other) noexcept - requires MaybePropagate { std::swap(config_.hashFunction(), other.config_.hashFunction()); std::swap(config_.keyEq(), other.config_.keyEq()); @@ -1441,9 +1439,8 @@ private: template < bool MaybePropagate = std::allocator_traits::propagate_on_container_swap::value> - void + std::enable_if_t swapData(AgedUnorderedContainer& other) noexcept - requires(!MaybePropagate) { std::swap(config_.hashFunction(), other.config_.hashFunction()); std::swap(config_.keyEq(), other.config_.keyEq()); @@ -2097,10 +2094,9 @@ template < class Hash, class KeyEqual, class Allocator> -template +template std::conditional_t& AgedUnorderedContainer::at(K const& k) - requires(MaybeMap && !MaybeMulti) { auto const iter( cont_.find(k, std::cref(config_.hashFunction()), std::cref(config_.keyValueEqual()))); @@ -2118,11 +2114,10 @@ template < class Hash, class KeyEqual, class Allocator> -template +template std::conditional::type const& AgedUnorderedContainer::at( K const& k) const - requires(MaybeMap && !MaybeMulti) { auto const iter( cont_.find(k, std::cref(config_.hashFunction()), std::cref(config_.keyValueEqual()))); @@ -2140,11 +2135,10 @@ template < class Hash, class KeyEqual, class Allocator> -template +template std::conditional_t& AgedUnorderedContainer::operator[]( Key const& key) - requires(MaybeMap && !MaybeMulti) { maybeRehash(1); typename cont_type::insert_commit_data d; @@ -2170,11 +2164,10 @@ template < class Hash, class KeyEqual, class Allocator> -template +template std::conditional_t& AgedUnorderedContainer::operator[]( Key&& key) - requires(MaybeMap && !MaybeMulti) { maybeRehash(1); typename cont_type::insert_commit_data d; @@ -2227,8 +2220,7 @@ template < template auto AgedUnorderedContainer::insert( - value_type const& value) -> std::pair - requires(!MaybeMulti) + value_type const& value) -> std::enable_if_t> { maybeRehash(1); typename cont_type::insert_commit_data d; @@ -2257,8 +2249,7 @@ template < template auto AgedUnorderedContainer::insert( - value_type const& value) -> iterator - requires MaybeMulti + value_type const& value) -> std::enable_if_t { maybeRehash(1); Element* const p(newElement(value)); @@ -2280,8 +2271,7 @@ template < template auto AgedUnorderedContainer::insert( - value_type&& value) -> std::pair - requires(!MaybeMulti && !MaybeMap) + value_type&& value) -> std::enable_if_t> { maybeRehash(1); typename cont_type::insert_commit_data d; @@ -2310,8 +2300,7 @@ template < template auto AgedUnorderedContainer::insert( - value_type&& value) -> iterator - requires(MaybeMulti && !MaybeMap) + value_type&& value) -> std::enable_if_t { maybeRehash(1); Element* const p(newElement(std::move(value))); @@ -2320,6 +2309,7 @@ AgedUnorderedContainer return iterator(iter); } +#if 1 // Use insert() instead of insert_check() insert_commit() // set, map template < bool IsMulti, @@ -2333,8 +2323,7 @@ template < template auto AgedUnorderedContainer::emplace( - Args&&... args) -> std::pair - requires(!MaybeMulti) + Args&&... args) -> std::enable_if_t> { maybeRehash(1); // VFALCO NOTE Its unfortunate that we need to @@ -2349,6 +2338,42 @@ AgedUnorderedContainer deleteElement(p); return std::make_pair(iterator(result.first), false); } +#else // As original, use insert_check() / insert_commit () pair. +// set, map +template < + bool IsMulti, + bool IsMap, + class Key, + class T, + class Clock, + class Hash, + class KeyEqual, + class Allocator> +template +auto +AgedUnorderedContainer::emplace( + Args&&... args) -> typename std::enable_if>::type +{ + maybe_rehash(1); + // VFALCO NOTE Its unfortunate that we need to + // construct element here + element* const p(new_element(std::forward(args)...)); + typename cont_type::insert_commit_data d; + auto const result(m_cont.insert_check( + extract(p->value), + std::cref(m_config.hashFunction()), + std::cref(m_config.keyValueEqual()), + d)); + if (result.second) + { + auto const iter(m_cont.insert_commit(*p, d)); + chronological.list.push_back(*p); + return std::make_pair(iterator(iter), true); + } + delete_element(p); + return std::make_pair(iterator(result.first), false); +} +#endif // 0 // multiset, multimap template < @@ -2363,8 +2388,7 @@ template < template auto AgedUnorderedContainer::emplace( - Args&&... args) -> iterator - requires MaybeMulti + Args&&... args) -> std::enable_if_t { maybeRehash(1); Element* const p(newElement(std::forward(args)...)); @@ -2387,8 +2411,7 @@ template auto AgedUnorderedContainer::emplaceHint( const_iterator /*hint*/, - Args&&... args) -> std::pair - requires(!MaybeMulti) + Args&&... args) -> std::enable_if_t> { maybeRehash(1); // VFALCO NOTE Its unfortunate that we need to @@ -2539,7 +2562,7 @@ template < class OtherHash, class OtherAllocator, bool MaybeMulti> -bool +std::enable_if_t AgedUnorderedContainer::operator==( AgedUnorderedContainer< false, @@ -2550,7 +2573,6 @@ AgedUnorderedContainer OtherHash, KeyEqual, OtherAllocator> const& other) const - requires(!MaybeMulti) { if (size() != other.size()) return false; @@ -2580,7 +2602,7 @@ template < class OtherHash, class OtherAllocator, bool MaybeMulti> -bool +std::enable_if_t AgedUnorderedContainer::operator==( AgedUnorderedContainer< true, @@ -2591,7 +2613,6 @@ AgedUnorderedContainer OtherHash, KeyEqual, OtherAllocator> const& other) const - requires MaybeMulti { if (size() != other.size()) return false; @@ -2628,8 +2649,7 @@ template < template auto AgedUnorderedContainer::insertUnchecked( - value_type const& value) -> std::pair - requires(!MaybeMulti) + value_type const& value) -> std::enable_if_t> { typename cont_type::insert_commit_data d; auto const result(cont_.insert_check( @@ -2657,8 +2677,7 @@ template < template auto AgedUnorderedContainer::insertUnchecked( - value_type const& value) -> iterator - requires MaybeMulti + value_type const& value) -> std::enable_if_t { Element* const p(newElement(value)); chronological.list_.push_back(*p); diff --git a/include/xrpl/beast/core/LexicalCast.h b/include/xrpl/beast/core/LexicalCast.h index 1162d83078..8faf90f53d 100644 --- a/include/xrpl/beast/core/LexicalCast.h +++ b/include/xrpl/beast/core/LexicalCast.h @@ -29,18 +29,16 @@ struct LexicalCast explicit LexicalCast() = default; template - bool + std::enable_if_t, bool> operator()(std::string& out, Arithmetic in) - requires(std::is_arithmetic_v) { out = std::to_string(in); return true; } template - bool + std::enable_if_t, bool> operator()(std::string& out, Enumeration in) - requires(std::is_enum_v) { out = std::to_string(static_cast>(in)); return true; @@ -58,9 +56,8 @@ struct LexicalCast "beast::LexicalCast can only be used with integral types"); template - bool + std::enable_if_t && !std::is_same_v, bool> operator()(Integral& out, std::string_view in) const - requires(std::is_integral_v && !std::is_same_v) { auto first = in.data(); auto last = in.data() + in.size(); diff --git a/include/xrpl/beast/core/LockFreeStack.h b/include/xrpl/beast/core/LockFreeStack.h index dd135d2d98..19225a4343 100644 --- a/include/xrpl/beast/core/LockFreeStack.h +++ b/include/xrpl/beast/core/LockFreeStack.h @@ -41,7 +41,7 @@ public: operator=(NodePtr node) { node_ = node; - return *this; + return static_cast(*this); } LockFreeStackIterator& diff --git a/include/xrpl/beast/hash/hash_append.h b/include/xrpl/beast/hash/hash_append.h index 3592ffbfe8..0b36d4c983 100644 --- a/include/xrpl/beast/hash/hash_append.h +++ b/include/xrpl/beast/hash/hash_append.h @@ -26,7 +26,7 @@ template inline void reverseBytes(T& t) { - auto* bytes = + unsigned char* bytes = static_cast(std::memmove(std::addressof(t), std::addressof(t), sizeof(T))); for (unsigned i = 0; i < sizeof(T) / 2; ++i) std::swap(bytes[i], bytes[sizeof(T) - 1 - i]); @@ -200,29 +200,26 @@ struct IsContiguouslyHashable // scalars template -inline void +inline std::enable_if_t::value> hash_append(Hasher& h, T const& t) noexcept - requires(IsContiguouslyHashable::value) { // NOLINTNEXTLINE(bugprone-sizeof-expression) h(static_cast(std::addressof(t)), sizeof(t)); } template -inline void +inline std::enable_if_t< + !IsContiguouslyHashable::value && + (std::is_integral_v || std::is_pointer_v || std::is_enum_v)> hash_append(Hasher& h, T t) noexcept - requires( - !IsContiguouslyHashable::value && - (std::is_integral_v || std::is_pointer_v || std::is_enum_v)) { detail::reverseBytes(t); h(std::addressof(t), sizeof(t)); } template -inline void +inline std::enable_if_t> hash_append(Hasher& h, T t) noexcept - requires(std::is_floating_point_v) { if (t == 0) t = 0; @@ -242,44 +239,36 @@ hash_append(Hasher& h, std::nullptr_t) noexcept // Forward declarations for ADL purposes template -void -hash_append(Hasher& h, T (&a)[N]) noexcept - requires(!IsContiguouslyHashable::value); +std::enable_if_t::value> +hash_append(Hasher& h, T (&a)[N]) noexcept; template -void -hash_append(Hasher& h, std::basic_string const& s) noexcept - requires(!IsContiguouslyHashable::value); +std::enable_if_t::value> +hash_append(Hasher& h, std::basic_string const& s) noexcept; template -void -hash_append(Hasher& h, std::basic_string const& s) noexcept - requires(IsContiguouslyHashable::value); +std::enable_if_t::value> +hash_append(Hasher& h, std::basic_string const& s) noexcept; template -void -hash_append(Hasher& h, std::pair const& p) noexcept - requires(!IsContiguouslyHashable, Hasher>::value); +std::enable_if_t, Hasher>::value> +hash_append(Hasher& h, std::pair const& p) noexcept; template -void -hash_append(Hasher& h, std::vector const& v) noexcept - requires(!IsContiguouslyHashable::value); +std::enable_if_t::value> +hash_append(Hasher& h, std::vector const& v) noexcept; template -void -hash_append(Hasher& h, std::vector const& v) noexcept - requires(IsContiguouslyHashable::value); +std::enable_if_t::value> +hash_append(Hasher& h, std::vector const& v) noexcept; template -void -hash_append(Hasher& h, std::array const& a) noexcept - requires(!IsContiguouslyHashable, Hasher>::value); +std::enable_if_t, Hasher>::value> +hash_append(Hasher& h, std::array const& a) noexcept; template -void -hash_append(Hasher& h, std::tuple const& t) noexcept - requires(!IsContiguouslyHashable, Hasher>::value); +std::enable_if_t, Hasher>::value> +hash_append(Hasher& h, std::tuple const& t) noexcept; template void @@ -290,13 +279,11 @@ void hash_append(Hasher& h, std::unordered_set const& s); template -void -hash_append(Hasher& h, boost::container::flat_set const& v) noexcept - requires(!IsContiguouslyHashable::value); +std::enable_if_t::value> +hash_append(Hasher& h, boost::container::flat_set const& v) noexcept; template -void -hash_append(Hasher& h, boost::container::flat_set const& v) noexcept - requires(IsContiguouslyHashable::value); +std::enable_if_t::value> +hash_append(Hasher& h, boost::container::flat_set const& v) noexcept; template void hash_append(Hasher& h, T0 const& t0, T1 const& t1, T const&... t) noexcept; @@ -304,9 +291,8 @@ hash_append(Hasher& h, T0 const& t0, T1 const& t1, T const&... t) noexcept; // c-array template -void +std::enable_if_t::value> hash_append(Hasher& h, T (&a)[N]) noexcept - requires(!IsContiguouslyHashable::value) { for (auto const& t : a) hash_append(h, t); @@ -315,9 +301,8 @@ hash_append(Hasher& h, T (&a)[N]) noexcept // basic_string template -inline void +inline std::enable_if_t::value> hash_append(Hasher& h, std::basic_string const& s) noexcept - requires(!IsContiguouslyHashable::value) { for (auto c : s) hash_append(h, c); @@ -325,9 +310,8 @@ hash_append(Hasher& h, std::basic_string const& s) noexcep } template -inline void +inline std::enable_if_t::value> hash_append(Hasher& h, std::basic_string const& s) noexcept - requires(IsContiguouslyHashable::value) { h(s.data(), s.size() * sizeof(CharT)); hash_append(h, s.size()); @@ -336,9 +320,8 @@ hash_append(Hasher& h, std::basic_string const& s) noexcep // pair template -inline void +inline std::enable_if_t, Hasher>::value> hash_append(Hasher& h, std::pair const& p) noexcept - requires(!IsContiguouslyHashable, Hasher>::value) { hash_append(h, p.first, p.second); } @@ -346,9 +329,8 @@ hash_append(Hasher& h, std::pair const& p) noexcept // vector template -inline void +inline std::enable_if_t::value> hash_append(Hasher& h, std::vector const& v) noexcept - requires(!IsContiguouslyHashable::value) { for (auto const& t : v) hash_append(h, t); @@ -356,9 +338,8 @@ hash_append(Hasher& h, std::vector const& v) noexcept } template -inline void +inline std::enable_if_t::value> hash_append(Hasher& h, std::vector const& v) noexcept - requires(IsContiguouslyHashable::value) { h(v.data(), v.size() * sizeof(T)); hash_append(h, v.size()); @@ -367,37 +348,57 @@ hash_append(Hasher& h, std::vector const& v) noexcept // array template -void +std::enable_if_t, Hasher>::value> hash_append(Hasher& h, std::array const& a) noexcept - requires(!IsContiguouslyHashable, Hasher>::value) { for (auto const& t : a) hash_append(h, t); } template -void +std::enable_if_t::value> hash_append(Hasher& h, boost::container::flat_set const& v) noexcept - requires(!IsContiguouslyHashable::value) { for (auto const& t : v) hash_append(h, t); } template -void +std::enable_if_t::value> hash_append(Hasher& h, boost::container::flat_set const& v) noexcept - requires(IsContiguouslyHashable::value) { h(&(v.begin()), v.size() * sizeof(Key)); } // tuple -template +namespace detail { + inline void -hash_append(Hasher& h, std::tuple const& t) noexcept - requires(!IsContiguouslyHashable, Hasher>::value) +forEachItem(...) noexcept { - std::apply([&h](auto const&... item) { (hash_append(h, item), ...); }, t); +} + +template +inline int +hashOne(Hasher& h, T const& t) noexcept +{ + hash_append(h, t); + return 0; +} + +template +inline void +tuple_hash(Hasher& h, std::tuple const& t, std::index_sequence) noexcept +{ + for_each_item(hash_one(h, std::get(t))...); +} + +} // namespace detail + +template +inline std::enable_if_t, Hasher>::value> +hash_append(Hasher& h, std::tuple const& t) noexcept +{ + detail::tuple_hash(h, t, std::index_sequence_for{}); } // shared_ptr diff --git a/include/xrpl/beast/hash/xxhasher.h b/include/xrpl/beast/hash/xxhasher.h index 73dbb8e8ab..978bbc6917 100644 --- a/include/xrpl/beast/hash/xxhasher.h +++ b/include/xrpl/beast/hash/xxhasher.h @@ -124,18 +124,14 @@ public: } } - template - explicit Xxhasher(Seed seed) - requires(std::is_unsigned_v) - : seed_(seed) + template >* = nullptr> + explicit Xxhasher(Seed seed) : seed_(seed) { resetBuffers(); } - template - Xxhasher(Seed seed, Seed) - requires(std::is_unsigned_v) - : seed_(seed) + template >* = nullptr> + Xxhasher(Seed seed, Seed) : seed_(seed) { resetBuffers(); } diff --git a/include/xrpl/beast/insight/Gauge.h b/include/xrpl/beast/insight/Gauge.h index 9a23ea6665..b24c4366c3 100644 --- a/include/xrpl/beast/insight/Gauge.h +++ b/include/xrpl/beast/insight/Gauge.h @@ -49,11 +49,6 @@ public: impl_->set(value); } - // This is a write-through handle: assignment sets the value of the - // referenced metric. It is const-qualified and returns Gauge const& - // (a non-const Gauge& would require a const_cast), so it does not follow - // the conventional assignment-operator signature. - // NOLINTNEXTLINE(misc-unconventional-assign-operator) Gauge const& operator=(value_type value) const { diff --git a/include/xrpl/beast/type_name.h b/include/xrpl/beast/type_name.h index 85fd9ae6a2..ae7b681af9 100644 --- a/include/xrpl/beast/type_name.h +++ b/include/xrpl/beast/type_name.h @@ -23,7 +23,6 @@ typeName() if (auto s = abi::__cxa_demangle(name.c_str(), nullptr, nullptr, nullptr)) { name = s; - // NOLINTNEXTLINE(cppcoreguidelines-no-malloc) std::free(s); } #endif diff --git a/include/xrpl/beast/unit_test/suite_list.h b/include/xrpl/beast/unit_test/suite_list.h index 7dd0dd80f0..cf9fb9c5b1 100644 --- a/include/xrpl/beast/unit_test/suite_list.h +++ b/include/xrpl/beast/unit_test/suite_list.h @@ -10,9 +10,9 @@ #include #include -#include // IWYU pragma: keep -#include // IWYU pragma: keep -#include // IWYU pragma: keep +#include +#include +#include namespace beast::unit_test { diff --git a/include/xrpl/beast/unit_test/thread.h b/include/xrpl/beast/unit_test/thread.h index 91d8cf3cab..0de039cb89 100644 --- a/include/xrpl/beast/unit_test/thread.h +++ b/include/xrpl/beast/unit_test/thread.h @@ -45,10 +45,7 @@ public: template explicit Thread(Suite& s, F&& f, Args&&... args) : s_(&s) { - std::function b = [f = std::forward(f), - ... args = std::forward(args)]() mutable { - std::invoke(f, args...); - }; + std::function b = std::bind(std::forward(f), std::forward(args)...); t_ = std::thread(&Thread::run, this, std::move(b)); } diff --git a/include/xrpl/beast/utility/Journal.h b/include/xrpl/beast/utility/Journal.h index 3de3cfb0e0..ac08b1384b 100644 --- a/include/xrpl/beast/utility/Journal.h +++ b/include/xrpl/beast/utility/Journal.h @@ -108,12 +108,12 @@ public: }; #ifndef __INTELLISENSE__ - static_assert(!std::is_default_constructible_v); - static_assert(!std::is_copy_constructible_v); - static_assert(!std::is_move_constructible_v); - static_assert(!std::is_copy_assignable_v); - static_assert(!std::is_move_assignable_v); - static_assert(std::is_nothrow_destructible_v); + static_assert(!std::is_default_constructible_v, ""); + static_assert(!std::is_copy_constructible_v, ""); + static_assert(!std::is_move_constructible_v, ""); + static_assert(!std::is_copy_assignable_v, ""); + static_assert(!std::is_move_assignable_v, ""); + static_assert(std::is_nothrow_destructible_v, ""); #endif /** Returns a Sink which does nothing. */ @@ -164,12 +164,12 @@ public: }; #ifndef __INTELLISENSE__ - static_assert(!std::is_default_constructible_v); - static_assert(std::is_copy_constructible_v); - static_assert(std::is_move_constructible_v); - static_assert(!std::is_copy_assignable_v); - static_assert(!std::is_move_assignable_v); - static_assert(std::is_nothrow_destructible_v); + static_assert(!std::is_default_constructible_v, ""); + static_assert(std::is_copy_constructible_v, ""); + static_assert(std::is_move_constructible_v, ""); + static_assert(!std::is_copy_assignable_v, ""); + static_assert(!std::is_move_assignable_v, ""); + static_assert(std::is_nothrow_destructible_v, ""); #endif //-------------------------------------------------------------------------- @@ -246,12 +246,12 @@ public: }; #ifndef __INTELLISENSE__ - static_assert(std::is_default_constructible_v); - static_assert(std::is_copy_constructible_v); - static_assert(std::is_move_constructible_v); - static_assert(!std::is_copy_assignable_v); - static_assert(!std::is_move_assignable_v); - static_assert(std::is_nothrow_destructible_v); + static_assert(std::is_default_constructible_v, ""); + static_assert(std::is_copy_constructible_v, ""); + static_assert(std::is_move_constructible_v, ""); + static_assert(!std::is_copy_assignable_v, ""); + static_assert(!std::is_move_assignable_v, ""); + static_assert(std::is_nothrow_destructible_v, ""); #endif //-------------------------------------------------------------------------- @@ -329,12 +329,12 @@ public: }; #ifndef __INTELLISENSE__ -static_assert(!std::is_default_constructible_v); -static_assert(std::is_copy_constructible_v); -static_assert(std::is_move_constructible_v); -static_assert(std::is_copy_assignable_v); -static_assert(std::is_move_assignable_v); -static_assert(std::is_nothrow_destructible_v); +static_assert(!std::is_default_constructible_v, ""); +static_assert(std::is_copy_constructible_v, ""); +static_assert(std::is_move_constructible_v, ""); +static_assert(std::is_copy_assignable_v, ""); +static_assert(std::is_move_assignable_v, ""); +static_assert(std::is_nothrow_destructible_v, ""); #endif //------------------------------------------------------------------------------ diff --git a/include/xrpl/beast/utility/Zero.h b/include/xrpl/beast/utility/Zero.h index e28589760b..f54345d437 100644 --- a/include/xrpl/beast/utility/Zero.h +++ b/include/xrpl/beast/utility/Zero.h @@ -26,7 +26,9 @@ struct Zero explicit Zero() = default; }; -inline constexpr Zero kZero{}; +namespace { +constexpr Zero kZero{}; +} // namespace /** Default implementation of signum calls the method on the class. */ template diff --git a/include/xrpl/beast/utility/rngfill.h b/include/xrpl/beast/utility/rngfill.h index 5bd9d8bc5c..0fc3ffe0d0 100644 --- a/include/xrpl/beast/utility/rngfill.h +++ b/include/xrpl/beast/utility/rngfill.h @@ -3,6 +3,7 @@ #include #include #include +#include namespace beast { @@ -13,7 +14,7 @@ rngfill(void* const buffer, std::size_t const bytes, Generator& g) using result_type = Generator::result_type; constexpr std::size_t kResultSize = sizeof(result_type); - auto* const bufferStart = static_cast(buffer); + std::uint8_t* const bufferStart = static_cast(buffer); std::size_t const completeIterations = bytes / kResultSize; std::size_t const bytesRemaining = bytes % kResultSize; @@ -32,14 +33,16 @@ rngfill(void* const buffer, std::size_t const bytes, Generator& g) } } -template +template < + class Generator, + std::size_t N, + class = std::enable_if_t> void rngfill(std::array& a, Generator& g) - requires(N % sizeof(typename Generator::result_type) == 0) { using result_type = Generator::result_type; auto i = N / sizeof(result_type); - auto* p = reinterpret_cast(a.data()); + result_type* p = reinterpret_cast(a.data()); while (i--) *p++ = g(); } diff --git a/include/xrpl/core/HashRouter.h b/include/xrpl/core/HashRouter.h index dad1afb405..ef8f24d43c 100644 --- a/include/xrpl/core/HashRouter.h +++ b/include/xrpl/core/HashRouter.h @@ -127,7 +127,7 @@ private: } [[nodiscard]] HashRouterFlags - getFlags() const + getFlags(void) const { return flags_; } diff --git a/include/xrpl/core/JobQueue.h b/include/xrpl/core/JobQueue.h index e4b64546f3..14170a39be 100644 --- a/include/xrpl/core/JobQueue.h +++ b/include/xrpl/core/JobQueue.h @@ -154,14 +154,16 @@ public: @param type The type of job. @param name Name of the job. - @param jobHandler Callable with signature void(). Called when the job is executed. + @param jobHandler Lambda with signature void (Job&). Called when the + job is executed. @return true if jobHandler added to queue. */ - template + template < + typename JobHandler, + typename = std::enable_if_t()()), void>>> bool addJob(JobType type, std::string const& name, JobHandler&& jobHandler) - requires(std::is_void_v>) { if (auto optionalCountedJob = jobCounter_.wrap(std::forward(jobHandler))) { diff --git a/include/xrpl/core/JobTypes.h b/include/xrpl/core/JobTypes.h index cc2f3ecbf5..f338b19f6c 100644 --- a/include/xrpl/core/JobTypes.h +++ b/include/xrpl/core/JobTypes.h @@ -118,7 +118,7 @@ public: [[nodiscard]] JobTypeInfo const& get(JobType jt) const { - auto const iter = map.find(jt); + Map::const_iterator const iter(map.find(jt)); XRPL_ASSERT(iter != map.end(), "xrpl::JobTypes::get : valid input"); if (iter != map.end()) diff --git a/include/xrpl/json/json_reader.h b/include/xrpl/json/json_reader.h index d1e4ada579..c1535bfb55 100644 --- a/include/xrpl/json/json_reader.h +++ b/include/xrpl/json/json_reader.h @@ -154,7 +154,7 @@ private: Location end, unsigned int& unicode); bool - addError(std::string const& message, Token& token, Location extra = nullptr); + addError(std::string const& message, Token& token, Location extra = 0); bool recoverFromError(TokenType skipUntilToken); bool diff --git a/include/xrpl/ledger/ApplyView.h b/include/xrpl/ledger/ApplyView.h index 2aba93d504..35fa059981 100644 --- a/include/xrpl/ledger/ApplyView.h +++ b/include/xrpl/ledger/ApplyView.h @@ -5,7 +5,7 @@ #include #include #include -#include // IWYU pragma: keep +#include #include #include #include diff --git a/include/xrpl/ledger/CachedView.h b/include/xrpl/ledger/CachedView.h index 1da3a67563..f83c3e1297 100644 --- a/include/xrpl/ledger/CachedView.h +++ b/include/xrpl/ledger/CachedView.h @@ -141,7 +141,7 @@ template class CachedView : public detail::CachedViewImpl { private: - static_assert(std::is_base_of_v); + static_assert(std::is_base_of_v, ""); std::shared_ptr sp_; diff --git a/include/xrpl/ledger/OpenView.h b/include/xrpl/ledger/OpenView.h index 875909715c..de81787906 100644 --- a/include/xrpl/ledger/OpenView.h +++ b/include/xrpl/ledger/OpenView.h @@ -82,7 +82,7 @@ private: using txs_map = std::map< key_type, TxData, - std::less<>, + std::less, boost::container::pmr::polymorphic_allocator>>; // monotonic_resource_ must outlive `items_`. Make a pointer so it may be diff --git a/include/xrpl/ledger/ReadView.h b/include/xrpl/ledger/ReadView.h index 2c33c511fd..b47f28d91c 100644 --- a/include/xrpl/ledger/ReadView.h +++ b/include/xrpl/ledger/ReadView.h @@ -7,7 +7,7 @@ #include #include #include -#include // IWYU pragma: keep +#include #include #include #include diff --git a/include/xrpl/ledger/detail/RawStateTable.h b/include/xrpl/ledger/detail/RawStateTable.h index 2e36a42eaf..cfa528d355 100644 --- a/include/xrpl/ledger/detail/RawStateTable.h +++ b/include/xrpl/ledger/detail/RawStateTable.h @@ -105,7 +105,7 @@ private: using items_t = std::map< key_type, SleAction, - std::less<>, + std::less, boost::container::pmr::polymorphic_allocator>>; // monotonic_resource_ must outlive `items_`. Make a pointer so it may be // easily moved. diff --git a/include/xrpl/ledger/detail/ReadViewFwdRange.h b/include/xrpl/ledger/detail/ReadViewFwdRange.h index 19ac0698c2..82d8b59c6a 100644 --- a/include/xrpl/ledger/detail/ReadViewFwdRange.h +++ b/include/xrpl/ledger/detail/ReadViewFwdRange.h @@ -108,8 +108,8 @@ public: std::optional mutable cache_; }; - static_assert(std::is_nothrow_move_constructible{}); - static_assert(std::is_nothrow_move_assignable{}); + static_assert(std::is_nothrow_move_constructible{}, ""); + static_assert(std::is_nothrow_move_assignable{}, ""); using const_iterator = Iterator; diff --git a/include/xrpl/ledger/helpers/DirectoryHelpers.h b/include/xrpl/ledger/helpers/DirectoryHelpers.h index a95b9bc95a..76a5f3bdad 100644 --- a/include/xrpl/ledger/helpers/DirectoryHelpers.h +++ b/include/xrpl/ledger/helpers/DirectoryHelpers.h @@ -19,7 +19,11 @@ namespace xrpl { namespace detail { -template +template < + class V, + class N, + class = std::enable_if_t< + std::is_same_v, SLE> && std::is_base_of_v>> bool internalDirNext( V& view, @@ -27,7 +31,6 @@ internalDirNext( std::shared_ptr& page, unsigned int& index, uint256& entry) - requires(std::is_same_v, SLE> && std::is_base_of_v) { auto const& svIndexes = page->getFieldV256(sfIndexes); XRPL_ASSERT(index <= svIndexes.size(), "xrpl::detail::internalDirNext : index inside range"); @@ -65,7 +68,11 @@ internalDirNext( return true; } -template +template < + class V, + class N, + class = std::enable_if_t< + std::is_same_v, SLE> && std::is_base_of_v>> bool internalDirFirst( V& view, @@ -73,7 +80,6 @@ internalDirFirst( std::shared_ptr& page, unsigned int& index, uint256& entry) - requires(std::is_same_v, SLE> && std::is_base_of_v) { if constexpr (std::is_const_v) { diff --git a/include/xrpl/ledger/helpers/EscrowHelpers.h b/include/xrpl/ledger/helpers/EscrowHelpers.h index b4093d121b..65f19dc3d7 100644 --- a/include/xrpl/ledger/helpers/EscrowHelpers.h +++ b/include/xrpl/ledger/helpers/EscrowHelpers.h @@ -53,7 +53,7 @@ escrowUnlockApplyHelper( bool createAsset, beast::Journal journal) { - auto const& issue = amount.get(); + Issue const& issue = amount.get(); Keylet const trustLineKey = keylet::trustLine(receiver, issue); bool const recvLow = issuer > receiver; bool const senderIssuer = issuer == sender; diff --git a/include/xrpl/ledger/helpers/LendingHelpers.h b/include/xrpl/ledger/helpers/LendingHelpers.h index 873abae272..c21e5bf0ce 100644 --- a/include/xrpl/ledger/helpers/LendingHelpers.h +++ b/include/xrpl/ledger/helpers/LendingHelpers.h @@ -8,7 +8,7 @@ #include #include #include -#include // IWYU pragma: keep +#include #include #include #include diff --git a/include/xrpl/net/AutoSocket.h b/include/xrpl/net/AutoSocket.h index b98885959d..72eaed7439 100644 --- a/include/xrpl/net/AutoSocket.h +++ b/include/xrpl/net/AutoSocket.h @@ -120,9 +120,12 @@ public: socket_->next_layer().async_receive( boost::asio::buffer(buffer_), boost::asio::socket_base::message_peek, - [this, cbFunc](error_code const& ec, size_t bytesTransferred) { - handleAutodetect(cbFunc, ec, bytesTransferred); - }); + std::bind( + &AutoSocket::handleAutodetect, + this, + cbFunc, + std::placeholders::_1, + std::placeholders::_2)); } } diff --git a/include/xrpl/net/HTTPClientSSLContext.h b/include/xrpl/net/HTTPClientSSLContext.h index 51b50a084c..4192455ec9 100644 --- a/include/xrpl/net/HTTPClientSSLContext.h +++ b/include/xrpl/net/HTTPClientSSLContext.h @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -83,12 +84,13 @@ public: * * @return error_code indicating failures, if any */ - template + template < + class T, + class = std::enable_if_t< + std::is_same_v> || + std::is_same_v>>> boost::system::error_code preConnectVerify(T& strm, std::string const& host) - requires( - std::is_same_v> || - std::is_same_v>) { boost::system::error_code ec; if (!SSL_set_tlsext_host_name(strm.native_handle(), host.c_str())) @@ -102,7 +104,11 @@ public: return ec; } - template + template < + class T, + class = std::enable_if_t< + std::is_same_v> || + std::is_same_v>>> /** * @brief invoked after connect/async_connect but before sending data * on an ssl stream - to setup name verification. @@ -112,9 +118,6 @@ public: */ boost::system::error_code postConnectVerify(T& strm, std::string const& host) - requires( - std::is_same_v> || - std::is_same_v>) { boost::system::error_code ec; @@ -124,9 +127,8 @@ public: if (!ec) { strm.set_verify_callback( - [host, j = j_](bool preverified, boost::asio::ssl::verify_context& ctx) { - return rfc6125Verify(host, preverified, ctx, j); - }, + std::bind( + &rfc6125Verify, host, std::placeholders::_1, std::placeholders::_2, j_), ec); } } diff --git a/include/xrpl/nodestore/detail/DecodedBlob.h b/include/xrpl/nodestore/detail/DecodedBlob.h index 02ccd5787a..b2d5fc9c26 100644 --- a/include/xrpl/nodestore/detail/DecodedBlob.h +++ b/include/xrpl/nodestore/detail/DecodedBlob.h @@ -34,11 +34,11 @@ public: createObject(); private: - bool success_{false}; + bool success_; void const* key_; - NodeObjectType objectType_{NodeObjectType::Unknown}; - unsigned char const* objectData_{nullptr}; + NodeObjectType objectType_; + unsigned char const* objectData_; int dataBytes_; }; diff --git a/include/xrpl/nodestore/detail/codec.h b/include/xrpl/nodestore/detail/codec.h index 2f69d532be..56e1fbcf73 100644 --- a/include/xrpl/nodestore/detail/codec.h +++ b/include/xrpl/nodestore/detail/codec.h @@ -62,7 +62,7 @@ lz4Compress(void const* in, std::size_t inSize, BufferFactory&& bf) std::array::kMax> vi{}; auto const n = writeVarint(vi.data(), inSize); auto const outMax = LZ4_compressBound(inSize); - auto* out = reinterpret_cast(bf(n + outMax)); + std::uint8_t* out = reinterpret_cast(bf(n + outMax)); result.first = out; std::memcpy(out, vi.data(), n); auto const outSize = LZ4_compress_default( @@ -90,7 +90,7 @@ nodeobjectDecompress(void const* in, std::size_t inSize, BufferFactory&& bf) { using namespace nudb::detail; - auto const* p = reinterpret_cast(in); + std::uint8_t const* p = reinterpret_cast(in); std::size_t type = 0; auto const vn = readVarint(p, inSize, type); if (vn == 0) @@ -237,7 +237,7 @@ nodeobjectCompress(void const* in, std::size_t inSize, BufferFactory&& bf) auto const vs = sizeVarint(type); result.second = vs + field::size + // mask (n * 32); // hashes - auto* out = reinterpret_cast(bf(result.second)); + std::uint8_t* out = reinterpret_cast(bf(result.second)); result.first = out; ostream os(out, result.second); write(os, type); @@ -249,7 +249,7 @@ nodeobjectCompress(void const* in, std::size_t inSize, BufferFactory&& bf) auto const type = 3U; auto const vs = sizeVarint(type); result.second = vs + (n * 32); // hashes - auto* out = reinterpret_cast(bf(result.second)); + std::uint8_t* out = reinterpret_cast(bf(result.second)); result.first = out; ostream os(out, result.second); write(os, type); diff --git a/include/xrpl/nodestore/detail/varint.h b/include/xrpl/nodestore/detail/varint.h index 5a65545d3a..21a13bd6de 100644 --- a/include/xrpl/nodestore/detail/varint.h +++ b/include/xrpl/nodestore/detail/varint.h @@ -39,7 +39,7 @@ readVarint(void const* buf, std::size_t buflen, std::size_t& t) if (buflen == 0) return 0; t = 0; - auto const* p = reinterpret_cast(buf); + std::uint8_t const* p = reinterpret_cast(buf); std::size_t n = 0; while (p[n] & 0x80) { @@ -68,10 +68,9 @@ readVarint(void const* buf, std::size_t buflen, std::size_t& t) return used; } -template +template >* = nullptr> std::size_t sizeVarint(T v) - requires(std::is_unsigned_v) { std::size_t n = 0; do @@ -87,7 +86,7 @@ std::size_t writeVarint(void* p0, std::size_t v) { // NOLINTNEXTLINE(misc-const-correctness) - auto* p = reinterpret_cast(p0); + std::uint8_t* p = reinterpret_cast(p0); do { std::uint8_t d = v % 127; @@ -101,10 +100,9 @@ writeVarint(void* p0, std::size_t v) // input stream -template +template >* = nullptr> void read(nudb::detail::istream& is, std::size_t& u) - requires(std::is_same_v) { auto p0 = is(1); auto p1 = p0; @@ -115,10 +113,9 @@ read(nudb::detail::istream& is, std::size_t& u) // output stream -template +template >* = nullptr> void write(nudb::detail::ostream& os, std::size_t t) - requires(std::is_same_v) { writeVarint(os.data(sizeVarint(t)), t); } diff --git a/include/xrpl/protocol/AmountConversions.h b/include/xrpl/protocol/AmountConversions.h index 3bcd80e827..66ada68d6f 100644 --- a/include/xrpl/protocol/AmountConversions.h +++ b/include/xrpl/protocol/AmountConversions.h @@ -13,7 +13,7 @@ #include #include -#include // IWYU pragma: keep +#include #include #include diff --git a/include/xrpl/protocol/Quality.h b/include/xrpl/protocol/Quality.h index de61d79ca5..6bb2033dc0 100644 --- a/include/xrpl/protocol/Quality.h +++ b/include/xrpl/protocol/Quality.h @@ -282,7 +282,7 @@ public: auto const maxVMantissa = mantissa(maxV); auto const expDiff = exponent(maxV) - exponent(minV); - auto const minVD = static_cast(minVMantissa); + double const minVD = static_cast(minVMantissa); double const maxVD = (expDiff != 0) ? maxVMantissa * pow(10, expDiff) : static_cast(maxVMantissa); diff --git a/include/xrpl/protocol/STArray.h b/include/xrpl/protocol/STArray.h index 573bb6dad8..ed39e65026 100644 --- a/include/xrpl/protocol/STArray.h +++ b/include/xrpl/protocol/STArray.h @@ -32,13 +32,17 @@ public: STArray() = default; STArray(STArray const&) = default; - template - explicit STArray(Iter first, Iter last) - requires(std::is_convertible_v::reference, STObject>); + template < + class Iter, + class = std::enable_if_t< + std::is_convertible_v::reference, STObject>>> + explicit STArray(Iter first, Iter last); - template - STArray(SField const& f, Iter first, Iter last) - requires(std::is_convertible_v::reference, STObject>); + template < + class Iter, + class = std::enable_if_t< + std::is_convertible_v::reference, STObject>>> + STArray(SField const& f, Iter first, Iter last); STArray& operator=(STArray const&) = default; @@ -166,17 +170,13 @@ private: friend class detail::STVar; }; -template -STArray::STArray(Iter first, Iter last) - requires(std::is_convertible_v::reference, STObject>) - : v_(first, last) +template +STArray::STArray(Iter first, Iter last) : v_(first, last) { } -template -STArray::STArray(SField const& f, Iter first, Iter last) - requires(std::is_convertible_v::reference, STObject>) - : STBase(f), v_(first, last) +template +STArray::STArray(SField const& f, Iter first, Iter last) : STBase(f), v_(first, last) { } diff --git a/include/xrpl/protocol/STBitString.h b/include/xrpl/protocol/STBitString.h index 6f71f48f25..4f25eccca6 100644 --- a/include/xrpl/protocol/STBitString.h +++ b/include/xrpl/protocol/STBitString.h @@ -148,7 +148,7 @@ template bool STBitString::isEquivalent(STBase const& t) const { - auto const* v = dynamic_cast(&t); + STBitString const* v = dynamic_cast(&t); return v && (value_ == v->value_); } diff --git a/include/xrpl/protocol/STInteger.h b/include/xrpl/protocol/STInteger.h index 951c4fc52f..1c7ac98f3e 100644 --- a/include/xrpl/protocol/STInteger.h +++ b/include/xrpl/protocol/STInteger.h @@ -115,7 +115,7 @@ template inline bool STInteger::isEquivalent(STBase const& t) const { - auto const* v = dynamic_cast(&t); + STInteger const* v = dynamic_cast(&t); return v && (value_ == v->value_); } diff --git a/include/xrpl/protocol/STObject.h b/include/xrpl/protocol/STObject.h index 9abf56e91b..b115e5646d 100644 --- a/include/xrpl/protocol/STObject.h +++ b/include/xrpl/protocol/STObject.h @@ -555,14 +555,9 @@ public: ValueProxy& operator=(ValueProxy const&) = delete; - // Write-through proxy: assignment sets the referenced field to the given - // value, so it intentionally takes the assigned value rather than a - // ValueProxy. template - // NOLINTNEXTLINE(misc-unconventional-assign-operator) - ValueProxy& - operator=(U&& u) - requires(std::is_assignable_v); + std::enable_if_t, ValueProxy&> + operator=(U&& u); // Convenience operators for value types supporting // arithmetic operations @@ -696,9 +691,8 @@ public: operator=(optional_type const& v); template - OptionalProxy& - operator=(U&& u) - requires(std::is_assignable_v); + std::enable_if_t, OptionalProxy&> + operator=(U&& u); private: friend class STObject; @@ -804,10 +798,8 @@ STObject::Proxy::assign(U&& u) template template -// NOLINTNEXTLINE(misc-unconventional-assign-operator) -STObject::ValueProxy& +std::enable_if_t, STObject::ValueProxy&> STObject::ValueProxy::operator=(U&& u) - requires(std::is_assignable_v) { this->assign(std::forward(u)); return *this; @@ -910,9 +902,8 @@ STObject::OptionalProxy::operator=(optional_type const& v) -> OptionalProxy& template template -STObject::OptionalProxy& +std::enable_if_t, STObject::OptionalProxy&> STObject::OptionalProxy::operator=(U&& u) - requires(std::is_assignable_v) { this->assign(std::forward(u)); return *this; @@ -1250,7 +1241,7 @@ template void STObject::setFieldUsingSetValue(SField const& field, V value) { - static_assert(!std::is_lvalue_reference_v); + static_assert(!std::is_lvalue_reference_v, ""); STBase* rf = getPField(field, true); diff --git a/include/xrpl/protocol/STPathSet.h b/include/xrpl/protocol/STPathSet.h index 23f4e653c4..f6b0fde7da 100644 --- a/include/xrpl/protocol/STPathSet.h +++ b/include/xrpl/protocol/STPathSet.h @@ -240,9 +240,6 @@ private: inline STPathElement::STPathElement() : type_(TypeNone), isOffer_(true) { - // hashValue_ is derived from the whole object, so it is computed in the body - // once every other member is initialized (as in the other constructors). - // NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer) hashValue_ = getHash(*this); } @@ -318,9 +315,6 @@ inline STPathElement::STPathElement( assetID_.visit( [&](Currency const&) { type_ = type_ & (~Type::TypeMpt); }, [&](MPTID const&) { type_ = type_ & (~Type::TypeCurrency); }); - // hashValue_ must be computed after type_ is adjusted above, so this cannot - // be a member initializer. - // NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer) hashValue_ = getHash(*this); } diff --git a/include/xrpl/protocol/Serializer.h b/include/xrpl/protocol/Serializer.h index 73bd9c8289..1d0453d6aa 100644 --- a/include/xrpl/protocol/Serializer.h +++ b/include/xrpl/protocol/Serializer.h @@ -334,7 +334,7 @@ public: template explicit SerialIter(std::uint8_t const (&data)[N]) : SerialIter(&data[0], N) { - static_assert(N > 0); + static_assert(N > 0, ""); } [[nodiscard]] bool diff --git a/include/xrpl/protocol/TER.h b/include/xrpl/protocol/TER.h index dc8cb31e30..d24e3ee6e9 100644 --- a/include/xrpl/protocol/TER.h +++ b/include/xrpl/protocol/TER.h @@ -413,7 +413,7 @@ TERtoInt(TECcodes v) //------------------------------------------------------------------------------ // Template class that is specific to selected ranges of error codes. The -// Trait tells the requires-clause which ranges are allowed. +// Trait tells std::enable_if which ranges are allowed. template