From 4c619e8a85cc1ca162a9d12522548d51c29c8170 Mon Sep 17 00:00:00 2001 From: Timothy Banks Date: Thu, 2 Jul 2026 10:17:32 -0400 Subject: [PATCH 01/19] refactor: Retire DisallowIncomingV1 fix (#7364) --- include/xrpl/protocol/detail/features.macro | 2 +- src/libxrpl/tx/transactors/token/TrustSet.cpp | 18 +---- src/test/app/TrustSet_test.cpp | 69 +++++++++---------- 3 files changed, 37 insertions(+), 52 deletions(-) diff --git a/include/xrpl/protocol/detail/features.macro b/include/xrpl/protocol/detail/features.macro index 7e64a49b0c..a7a62f0322 100644 --- a/include/xrpl/protocol/detail/features.macro +++ b/include/xrpl/protocol/detail/features.macro @@ -60,7 +60,6 @@ XRPL_FEATURE(PriceOracle, Supported::Yes, VoteBehavior::DefaultNo XRPL_FIX (AMMOverflowOffer, Supported::Yes, VoteBehavior::DefaultYes) XRPL_FIX (FillOrKill, Supported::Yes, VoteBehavior::DefaultNo) XRPL_FEATURE(DID, Supported::Yes, VoteBehavior::DefaultNo) -XRPL_FIX (DisallowIncomingV1, Supported::Yes, VoteBehavior::DefaultNo) XRPL_FEATURE(XChainBridge, Supported::Yes, VoteBehavior::DefaultNo) XRPL_FEATURE(AMM, Supported::Yes, VoteBehavior::DefaultNo) XRPL_FEATURE(XRPFees, Supported::Yes, VoteBehavior::DefaultNo) @@ -100,6 +99,7 @@ XRPL_RETIRE_FIX(1623) XRPL_RETIRE_FIX(1781) XRPL_RETIRE_FIX(AmendmentMajorityCalc) XRPL_RETIRE_FIX(CheckThreading) +XRPL_RETIRE_FIX(DisallowIncomingV1) XRPL_RETIRE_FIX(InnerObjTemplate) XRPL_RETIRE_FIX(MasterKeyAsRegularKey) XRPL_RETIRE_FIX(NonFungibleTokensV1_2) diff --git a/src/libxrpl/tx/transactors/token/TrustSet.cpp b/src/libxrpl/tx/transactors/token/TrustSet.cpp index 151e82bab9..e79e3cad5a 100644 --- a/src/libxrpl/tx/transactors/token/TrustSet.cpp +++ b/src/libxrpl/tx/transactors/token/TrustSet.cpp @@ -184,22 +184,10 @@ TrustSet::preclaim(PreclaimContext const& ctx) // If the destination has opted to disallow incoming trustlines // then honour that flag - if (sleDst->isFlag(lsfDisallowIncomingTrustline)) + if (sleDst && sleDst->isFlag(lsfDisallowIncomingTrustline) && + !ctx.view.exists(keylet::trustLine(id, uDstAccountID, currency))) { - // The original implementation of featureDisallowIncoming was - // too restrictive. If - // o fixDisallowIncomingV1 is enabled and - // o The trust line already exists - // Then allow the TrustSet. - if (ctx.view.rules().enabled(fixDisallowIncomingV1) && - ctx.view.exists(keylet::trustLine(id, uDstAccountID, currency))) - { - // pass - } - else - { - return tecNO_PERMISSION; - } + return tecNO_PERMISSION; } // In general, trust lines to pseudo accounts are not permitted, unless diff --git a/src/test/app/TrustSet_test.cpp b/src/test/app/TrustSet_test.cpp index e9f0553840..15abc3bd06 100644 --- a/src/test/app/TrustSet_test.cpp +++ b/src/test/app/TrustSet_test.cpp @@ -474,6 +474,38 @@ public: checkQuality(!createQuality); } + void + testDisallowIncomingWithRequireAuth() + { + testcase("Create trustline with disallow incoming requiring auth"); + + using namespace test::jtx; + + Env env{*this}; + auto const dist = Account("dist"); + auto const gw = Account("gw"); + auto const usd = gw["USD"]; + auto const distUSD = dist["USD"]; + + env.fund(XRP(1000), gw, dist); + env.close(); + + env(fset(gw, asfRequireAuth)); + env.close(); + + env(fset(dist, asfDisallowIncomingTrustline)); + env.close(); + + env(trust(dist, usd(10000))); + env.close(); + + env(trust(gw, distUSD(10000)), Txflags(tfSetfAuth), Ter(tesSUCCESS)); + env.close(); + + env(pay(gw, dist, usd(1000)), Ter(tesSUCCESS)); + env.close(); + } + void testDisallowIncoming(FeatureBitset features) { @@ -481,42 +513,6 @@ public: using namespace test::jtx; - // fixDisallowIncomingV1 - { - for (bool const withFix : {true, false}) - { - auto const amend = withFix ? features : features - fixDisallowIncomingV1; - - Env env{*this, amend}; - auto const dist = Account("dist"); - auto const gw = Account("gw"); - auto const usd = gw["USD"]; - auto const distUSD = dist["USD"]; - - env.fund(XRP(1000), gw, dist); - env.close(); - - env(fset(gw, asfRequireAuth)); - env.close(); - - env(fset(dist, asfDisallowIncomingTrustline)); - env.close(); - - env(trust(dist, usd(10000))); - env.close(); - - // withFix: can set trustline - // withOutFix: cannot set trustline - auto const trustResult = withFix ? Ter(tesSUCCESS) : Ter(tecNO_PERMISSION); - env(trust(gw, distUSD(10000)), Txflags(tfSetfAuth), trustResult); - env.close(); - - auto const txResult = withFix ? Ter(tesSUCCESS) : Ter(tecPATH_DRY); - env(pay(gw, dist, usd(1000)), txResult); - env.close(); - } - } - Env env{*this, features}; auto const gw = Account{"gateway"}; @@ -601,6 +597,7 @@ public: testModifyQualityOfTrustline(features, false, true); testModifyQualityOfTrustline(features, true, false); testModifyQualityOfTrustline(features, true, true); + testDisallowIncomingWithRequireAuth(); testDisallowIncoming(features); testTrustLineResetWithAuthFlag(); testTrustLineDelete(); From 3b9e24e0e0bf3a5941808446ac1fca28bd8e8e69 Mon Sep 17 00:00:00 2001 From: Bart Date: Thu, 2 Jul 2026 11:01:30 -0400 Subject: [PATCH 02/19] chore: Improve pre-commit hooks (#7702) Co-authored-by: Bart <11445373+bthomee@users.noreply.github.com> --- cspell.config.yaml => .cspell.config.yaml | 4 +--- .pre-commit-config.yaml | 9 ++++----- 2 files changed, 5 insertions(+), 8 deletions(-) rename cspell.config.yaml => .cspell.config.yaml (96%) diff --git a/cspell.config.yaml b/.cspell.config.yaml similarity index 96% rename from cspell.config.yaml rename to .cspell.config.yaml index c120c31855..c558fc0984 100644 --- a/cspell.config.yaml +++ b/.cspell.config.yaml @@ -36,9 +36,7 @@ overrides: - /'[^']*'/g # single-quoted strings - /`[^`]*`/g # backtick strings suggestWords: - - xprl->xrpl - - xprld->xrpld # cspell: disable-line not sure what this problem is.... - - unsynched->unsynced # cspell: disable-line not sure what this problem is.... + - unsynched->unsynced - synched->synced - synch->sync words: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2e4521870d..910bda8d4c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -90,20 +90,19 @@ repos: - repo: https://github.com/streetsidesoftware/cspell-cli rev: ea11f9efc0bec520073405bc30552da887ba71bc # frozen: v10.0.1 hooks: - - id: cspell # Spell check changed files + - id: cspell + name: check changed files spelling exclude: | (?x)^( - .config/cspell.config.yaml| + \.cspell\.config\.yaml| include/xrpl/protocol_autogen/(transactions|ledger_entries)/.* )$ - - id: cspell # Spell check the commit message + - id: cspell name: check commit message spelling args: - --no-must-find-files - --no-progress - --no-summary - - --files - - .git/COMMIT_EDITMSG stages: [commit-msg] - repo: local From 6f0f5b8bb36c30c2578a62d1b2a5befa736da4c4 Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Thu, 2 Jul 2026 17:26:09 +0100 Subject: [PATCH 03/19] chore: Make clang-tidy happy on macOS (#7701) --- BUILD.md | 2 +- bin/pre-commit/clang_tidy_check.py | 8 +++++--- include/xrpl/beast/unit_test/suite_list.h | 6 +++--- include/xrpl/ledger/ApplyView.h | 2 +- include/xrpl/ledger/ReadView.h | 2 +- include/xrpl/ledger/helpers/LendingHelpers.h | 2 +- include/xrpl/protocol/AmountConversions.h | 2 +- include/xrpl/tx/paths/detail/EitherAmount.h | 2 +- src/libxrpl/ledger/helpers/NFTokenHelpers.cpp | 2 +- src/libxrpl/ledger/helpers/OfferHelpers.cpp | 2 +- src/libxrpl/ledger/helpers/VaultHelpers.cpp | 2 +- src/libxrpl/protocol/Quality.cpp | 4 ++-- src/libxrpl/protocol/STInteger.cpp | 2 +- src/libxrpl/protocol/STTx.cpp | 1 + src/libxrpl/protocol/STValidation.cpp | 2 +- src/libxrpl/tx/transactors/vault/VaultWithdraw.cpp | 2 +- src/test/app/PayChan_test.cpp | 2 +- src/test/app/Vault_test.cpp | 2 +- src/test/beast/beast_io_latency_probe_test.cpp | 2 +- src/test/jtx/impl/amount.cpp | 2 +- src/test/rpc/DepositAuthorized_test.cpp | 2 +- src/xrpld/app/ledger/detail/BuildLedger.cpp | 4 ++-- src/xrpld/app/ledger/detail/InboundLedger.cpp | 4 ++-- src/xrpld/app/ledger/detail/LedgerPersistence.cpp | 4 ++-- src/xrpld/app/ledger/detail/OpenLedger.cpp | 2 +- src/xrpld/app/main/Application.cpp | 4 ++-- src/xrpld/app/misc/FeeVoteImpl.cpp | 2 +- src/xrpld/overlay/detail/PeerImp.cpp | 1 + 28 files changed, 39 insertions(+), 35 deletions(-) diff --git a/BUILD.md b/BUILD.md index 6ccdde12d5..a15c94edc9 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 | 17 | +| Apple Clang | 21 | | 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 d074c56acf..5b5792b405 100755 --- a/bin/pre-commit/clang_tidy_check.py +++ b/bin/pre-commit/clang_tidy_check.py @@ -17,9 +17,11 @@ import subprocess import sys from pathlib import Path +CLANG_TIDY_VERSION = 22 + def find_run_clang_tidy() -> str | None: - for candidate in ("run-clang-tidy-21", "run-clang-tidy"): + for candidate in (f"run-clang-tidy-{CLANG_TIDY_VERSION}", "run-clang-tidy"): if path := shutil.which(candidate): return path return None @@ -44,8 +46,8 @@ def main(): run_clang_tidy = find_run_clang_tidy() if not run_clang_tidy: print( - "clang-tidy check failed: TIDY is enabled but neither " - "'run-clang-tidy-21' nor 'run-clang-tidy' was found in PATH.", + 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.", file=sys.stderr, ) return 1 diff --git a/include/xrpl/beast/unit_test/suite_list.h b/include/xrpl/beast/unit_test/suite_list.h index cf9fb9c5b1..7dd0dd80f0 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 -#include -#include +#include // IWYU pragma: keep +#include // IWYU pragma: keep +#include // IWYU pragma: keep namespace beast::unit_test { diff --git a/include/xrpl/ledger/ApplyView.h b/include/xrpl/ledger/ApplyView.h index 3bf5d479d1..e519013d9a 100644 --- a/include/xrpl/ledger/ApplyView.h +++ b/include/xrpl/ledger/ApplyView.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include // IWYU pragma: keep #include #include #include diff --git a/include/xrpl/ledger/ReadView.h b/include/xrpl/ledger/ReadView.h index 8bbd3e06cb..724533039b 100644 --- a/include/xrpl/ledger/ReadView.h +++ b/include/xrpl/ledger/ReadView.h @@ -7,7 +7,7 @@ #include #include #include -#include +#include // IWYU pragma: keep #include #include #include diff --git a/include/xrpl/ledger/helpers/LendingHelpers.h b/include/xrpl/ledger/helpers/LendingHelpers.h index c21e5bf0ce..873abae272 100644 --- a/include/xrpl/ledger/helpers/LendingHelpers.h +++ b/include/xrpl/ledger/helpers/LendingHelpers.h @@ -8,7 +8,7 @@ #include #include #include -#include +#include // IWYU pragma: keep #include #include #include diff --git a/include/xrpl/protocol/AmountConversions.h b/include/xrpl/protocol/AmountConversions.h index 66ada68d6f..3bcd80e827 100644 --- a/include/xrpl/protocol/AmountConversions.h +++ b/include/xrpl/protocol/AmountConversions.h @@ -13,7 +13,7 @@ #include #include -#include +#include // IWYU pragma: keep #include #include diff --git a/include/xrpl/tx/paths/detail/EitherAmount.h b/include/xrpl/tx/paths/detail/EitherAmount.h index 68ad90d2d4..bc9488d5db 100644 --- a/include/xrpl/tx/paths/detail/EitherAmount.h +++ b/include/xrpl/tx/paths/detail/EitherAmount.h @@ -6,7 +6,7 @@ #include // IWYU pragma: keep #include -#include +#include // IWYU pragma: keep #include #include diff --git a/src/libxrpl/ledger/helpers/NFTokenHelpers.cpp b/src/libxrpl/ledger/helpers/NFTokenHelpers.cpp index af429358bb..6dca715a8c 100644 --- a/src/libxrpl/ledger/helpers/NFTokenHelpers.cpp +++ b/src/libxrpl/ledger/helpers/NFTokenHelpers.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include // IWYU pragma: keep #include #include #include diff --git a/src/libxrpl/ledger/helpers/OfferHelpers.cpp b/src/libxrpl/ledger/helpers/OfferHelpers.cpp index 5249870143..6e72b71564 100644 --- a/src/libxrpl/ledger/helpers/OfferHelpers.cpp +++ b/src/libxrpl/ledger/helpers/OfferHelpers.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include // IWYU pragma: keep #include #include // IWYU pragma: keep #include diff --git a/src/libxrpl/ledger/helpers/VaultHelpers.cpp b/src/libxrpl/ledger/helpers/VaultHelpers.cpp index 3a3a756499..b5b076d1cb 100644 --- a/src/libxrpl/ledger/helpers/VaultHelpers.cpp +++ b/src/libxrpl/ledger/helpers/VaultHelpers.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include // IWYU pragma: keep #include #include #include diff --git a/src/libxrpl/protocol/Quality.cpp b/src/libxrpl/protocol/Quality.cpp index 7ad426bef7..dde7921a76 100644 --- a/src/libxrpl/protocol/Quality.cpp +++ b/src/libxrpl/protocol/Quality.cpp @@ -1,12 +1,12 @@ #include -#include +#include // IWYU pragma: keep #include #include #include #include -#include +#include // IWYU pragma: keep namespace xrpl { diff --git a/src/libxrpl/protocol/STInteger.cpp b/src/libxrpl/protocol/STInteger.cpp index 5f3fb6ffa4..b65504dd5f 100644 --- a/src/libxrpl/protocol/STInteger.cpp +++ b/src/libxrpl/protocol/STInteger.cpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include // IWYU pragma: keep namespace xrpl { diff --git a/src/libxrpl/protocol/STTx.cpp b/src/libxrpl/protocol/STTx.cpp index cd2da12316..b3de717da8 100644 --- a/src/libxrpl/protocol/STTx.cpp +++ b/src/libxrpl/protocol/STTx.cpp @@ -596,6 +596,7 @@ STTx::getBatchTransactionIDs() const XRPL_ASSERT( batchTxnIds_->size() == getFieldArray(sfRawTransactions).size(), "STTx::getBatchTransactionIDs : batch transaction IDs size mismatch"); + // NOLINTNEXTLINE(bugprone-unchecked-optional-access): guarded by assert above return *batchTxnIds_; } diff --git a/src/libxrpl/protocol/STValidation.cpp b/src/libxrpl/protocol/STValidation.cpp index 5eafb407ec..1656aad3a2 100644 --- a/src/libxrpl/protocol/STValidation.cpp +++ b/src/libxrpl/protocol/STValidation.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include // IWYU pragma: keep #include #include #include diff --git a/src/libxrpl/tx/transactors/vault/VaultWithdraw.cpp b/src/libxrpl/tx/transactors/vault/VaultWithdraw.cpp index 3d30005876..ad91c55723 100644 --- a/src/libxrpl/tx/transactors/vault/VaultWithdraw.cpp +++ b/src/libxrpl/tx/transactors/vault/VaultWithdraw.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include // IWYU pragma: keep #include #include #include diff --git a/src/test/app/PayChan_test.cpp b/src/test/app/PayChan_test.cpp index fd2c7790d5..f1a9506e0c 100644 --- a/src/test/app/PayChan_test.cpp +++ b/src/test/app/PayChan_test.cpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include // IWYU pragma: keep #include #include #include diff --git a/src/test/app/Vault_test.cpp b/src/test/app/Vault_test.cpp index f6574872f9..3877e08f7e 100644 --- a/src/test/app/Vault_test.cpp +++ b/src/test/app/Vault_test.cpp @@ -7542,7 +7542,7 @@ class Vault_test : public beast::unit_test::Suite // Transaction fails if the data field is set, but is empty { testcase("VaultDelete memo data featureLendingProtocolV1_1 enabled data empty"); - delTx[sfMemoData] = strHex(std::string(0, 'A')); + delTx[sfMemoData] = strHex(std::string()); env(delTx, Ter(temMALFORMED)); env.close(); } diff --git a/src/test/beast/beast_io_latency_probe_test.cpp b/src/test/beast/beast_io_latency_probe_test.cpp index 9a93968dab..807ad81c49 100644 --- a/src/test/beast/beast_io_latency_probe_test.cpp +++ b/src/test/beast/beast_io_latency_probe_test.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include // IWYU pragma: keep #include #include // IWYU pragma: keep #include diff --git a/src/test/jtx/impl/amount.cpp b/src/test/jtx/impl/amount.cpp index b07703dace..f90102245a 100644 --- a/src/test/jtx/impl/amount.cpp +++ b/src/test/jtx/impl/amount.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include // IWYU pragma: keep #include #include #include diff --git a/src/test/rpc/DepositAuthorized_test.cpp b/src/test/rpc/DepositAuthorized_test.cpp index e6720602c9..6d6b54d70a 100644 --- a/src/test/rpc/DepositAuthorized_test.cpp +++ b/src/test/rpc/DepositAuthorized_test.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include // IWYU pragma: keep #include #include #include diff --git a/src/xrpld/app/ledger/detail/BuildLedger.cpp b/src/xrpld/app/ledger/detail/BuildLedger.cpp index 038a7be4b7..d11e0610ba 100644 --- a/src/xrpld/app/ledger/detail/BuildLedger.cpp +++ b/src/xrpld/app/ledger/detail/BuildLedger.cpp @@ -13,10 +13,10 @@ #include #include #include -#include +#include // IWYU pragma: keep #include #include -#include +#include // IWYU pragma: keep #include #include diff --git a/src/xrpld/app/ledger/detail/InboundLedger.cpp b/src/xrpld/app/ledger/detail/InboundLedger.cpp index 4affffd1c1..4d34f60374 100644 --- a/src/xrpld/app/ledger/detail/InboundLedger.cpp +++ b/src/xrpld/app/ledger/detail/InboundLedger.cpp @@ -21,11 +21,11 @@ #include #include #include -#include +#include // IWYU pragma: keep #include #include #include -#include +#include // IWYU pragma: keep #include #include #include diff --git a/src/xrpld/app/ledger/detail/LedgerPersistence.cpp b/src/xrpld/app/ledger/detail/LedgerPersistence.cpp index 3561b66951..6baf64e923 100644 --- a/src/xrpld/app/ledger/detail/LedgerPersistence.cpp +++ b/src/xrpld/app/ledger/detail/LedgerPersistence.cpp @@ -8,9 +8,9 @@ #include #include #include -#include +#include // IWYU pragma: keep #include -#include +#include // IWYU pragma: keep #include #include diff --git a/src/xrpld/app/ledger/detail/OpenLedger.cpp b/src/xrpld/app/ledger/detail/OpenLedger.cpp index 60599c80d3..4d8a37cdf1 100644 --- a/src/xrpld/app/ledger/detail/OpenLedger.cpp +++ b/src/xrpld/app/ledger/detail/OpenLedger.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include // IWYU pragma: keep #include #include #include diff --git a/src/xrpld/app/main/Application.cpp b/src/xrpld/app/main/Application.cpp index b99c98afa1..594195b93e 100644 --- a/src/xrpld/app/main/Application.cpp +++ b/src/xrpld/app/main/Application.cpp @@ -79,11 +79,11 @@ #include #include #include -#include +#include // IWYU pragma: keep #include #include #include -#include +#include // IWYU pragma: keep #include #include #include diff --git a/src/xrpld/app/misc/FeeVoteImpl.cpp b/src/xrpld/app/misc/FeeVoteImpl.cpp index 363c17f4fa..76a4d8f186 100644 --- a/src/xrpld/app/misc/FeeVoteImpl.cpp +++ b/src/xrpld/app/misc/FeeVoteImpl.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include // IWYU pragma: keep #include #include // IWYU pragma: keep #include diff --git a/src/xrpld/overlay/detail/PeerImp.cpp b/src/xrpld/overlay/detail/PeerImp.cpp index 5ac61cfd91..83e4d9c851 100644 --- a/src/xrpld/overlay/detail/PeerImp.cpp +++ b/src/xrpld/overlay/detail/PeerImp.cpp @@ -2134,6 +2134,7 @@ PeerImp::onValidatorListMessage( publisherListSequences_[pubKey] = applyResult.sequence; } break; + // NOLINTNEXTLINE(bugprone-branch-clone): identical to the next branch only in Release case ListDisposition::SameSequence: case ListDisposition::KnownSequence: #ifndef NDEBUG From 41622b87aeeb6d5e9f03f12d0a6847e0a04e6174 Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Thu, 2 Jul 2026 19:30:59 +0100 Subject: [PATCH 04/19] chore: Enable modernize-unary-static-assert (#7705) --- .clang-tidy | 1 - include/xrpl/basics/base_uint.h | 2 +- include/xrpl/beast/utility/Journal.h | 48 ++-- include/xrpl/ledger/CachedView.h | 2 +- include/xrpl/ledger/detail/ReadViewFwdRange.h | 4 +- include/xrpl/protocol/STObject.h | 2 +- include/xrpl/protocol/Serializer.h | 2 +- src/libxrpl/protocol/Serializer.cpp | 2 +- src/libxrpl/protocol/digest.cpp | 6 +- src/test/app/PayStrand_test.cpp | 2 +- src/test/basics/Buffer_test.cpp | 4 +- src/test/jtx/Env_test.cpp | 8 +- src/test/protocol/Quality_test.cpp | 4 +- src/test/protocol/STObject_test.cpp | 6 +- src/test/protocol/SeqProxy_test.cpp | 220 +++++++++--------- src/test/shamap/SHAMap_test.cpp | 88 +++---- src/xrpld/app/misc/detail/TxQ.cpp | 8 +- 17 files changed, 203 insertions(+), 206 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 84849db7a0..2b0b7e4418 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -80,7 +80,6 @@ Checks: "-*, -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, diff --git a/include/xrpl/basics/base_uint.h b/include/xrpl/basics/base_uint.h index e6ca1993f9..c60fbf35b4 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; diff --git a/include/xrpl/beast/utility/Journal.h b/include/xrpl/beast/utility/Journal.h index ac08b1384b..3de3cfb0e0 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/ledger/CachedView.h b/include/xrpl/ledger/CachedView.h index f83c3e1297..1da3a67563 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/detail/ReadViewFwdRange.h b/include/xrpl/ledger/detail/ReadViewFwdRange.h index 82d8b59c6a..19ac0698c2 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/protocol/STObject.h b/include/xrpl/protocol/STObject.h index c254a37aaf..a60e8f7fe8 100644 --- a/include/xrpl/protocol/STObject.h +++ b/include/xrpl/protocol/STObject.h @@ -1241,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/Serializer.h b/include/xrpl/protocol/Serializer.h index 1d0453d6aa..73bd9c8289 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/src/libxrpl/protocol/Serializer.cpp b/src/libxrpl/protocol/Serializer.cpp index d500919df9..1eda04705f 100644 --- a/src/libxrpl/protocol/Serializer.cpp +++ b/src/libxrpl/protocol/Serializer.cpp @@ -444,7 +444,7 @@ template T SerialIter::getRawHelper(int size) { - static_assert(std::is_same_v || std::is_same_v, ""); + static_assert(std::is_same_v || std::is_same_v); if (remain_ < size) Throw("invalid SerialIter getRaw"); T result(size); diff --git a/src/libxrpl/protocol/digest.cpp b/src/libxrpl/protocol/digest.cpp index 2e1b2b25cf..1d84f8779e 100644 --- a/src/libxrpl/protocol/digest.cpp +++ b/src/libxrpl/protocol/digest.cpp @@ -9,7 +9,7 @@ namespace xrpl { OpensslRipemd160Hasher::OpensslRipemd160Hasher() { - static_assert(sizeof(decltype(OpensslRipemd160Hasher::ctx_)) == sizeof(RIPEMD160_CTX), ""); + static_assert(sizeof(decltype(OpensslRipemd160Hasher::ctx_)) == sizeof(RIPEMD160_CTX)); auto const ctx = reinterpret_cast(ctx_); RIPEMD160_Init(ctx); } @@ -34,7 +34,7 @@ operator result_type() noexcept OpensslSha512Hasher::OpensslSha512Hasher() { - static_assert(sizeof(decltype(OpensslSha512Hasher::ctx_)) == sizeof(SHA512_CTX), ""); + static_assert(sizeof(decltype(OpensslSha512Hasher::ctx_)) == sizeof(SHA512_CTX)); auto const ctx = reinterpret_cast(ctx_); SHA512_Init(ctx); } @@ -59,7 +59,7 @@ operator result_type() noexcept OpensslSha256Hasher::OpensslSha256Hasher() { - static_assert(sizeof(decltype(OpensslSha256Hasher::ctx_)) == sizeof(SHA256_CTX), ""); + static_assert(sizeof(decltype(OpensslSha256Hasher::ctx_)) == sizeof(SHA256_CTX)); auto const ctx = reinterpret_cast(ctx_); SHA256_Init(ctx); } diff --git a/src/test/app/PayStrand_test.cpp b/src/test/app/PayStrand_test.cpp index 11a0e5bab0..ddbcfe8b70 100644 --- a/src/test/app/PayStrand_test.cpp +++ b/src/test/app/PayStrand_test.cpp @@ -112,7 +112,7 @@ class ElementComboIter }; std::uint16_t state_ = 0; - static_assert(safeCast(SB::Last) <= sizeof(decltype(state_)) * 8, ""); + static_assert(safeCast(SB::Last) <= sizeof(decltype(state_)) * 8); STPathElement const* prev_ = nullptr; // disallow iss and cur to be specified with acc is specified (simplifies // some tests) diff --git a/src/test/basics/Buffer_test.cpp b/src/test/basics/Buffer_test.cpp index 816a697ca4..c748a3f9dd 100644 --- a/src/test/basics/Buffer_test.cpp +++ b/src/test/basics/Buffer_test.cpp @@ -103,8 +103,8 @@ struct Buffer_test : beast::unit_test::Suite { testcase("Move Construction / Assignment"); - static_assert(std::is_nothrow_move_constructible_v, ""); - static_assert(std::is_nothrow_move_assignable_v, ""); + static_assert(std::is_nothrow_move_constructible_v); + static_assert(std::is_nothrow_move_assignable_v); { // Move-construct from empty buf Buffer x; diff --git a/src/test/jtx/Env_test.cpp b/src/test/jtx/Env_test.cpp index d82cb86b36..47cfb604f4 100644 --- a/src/test/jtx/Env_test.cpp +++ b/src/test/jtx/Env_test.cpp @@ -110,10 +110,10 @@ public: PrettyAmount(0u); // NOLINT(bugprone-unused-raii) PrettyAmount(1u); // NOLINT(bugprone-unused-raii) PrettyAmount(-1); // NOLINT(bugprone-unused-raii) - static_assert(!std::is_trivially_constructible_v, ""); - static_assert(!std::is_trivially_constructible_v, ""); - static_assert(!std::is_trivially_constructible_v, ""); - static_assert(!std::is_trivially_constructible_v, ""); + static_assert(!std::is_trivially_constructible_v); + static_assert(!std::is_trivially_constructible_v); + static_assert(!std::is_trivially_constructible_v); + static_assert(!std::is_trivially_constructible_v); try { diff --git a/src/test/protocol/Quality_test.cpp b/src/test/protocol/Quality_test.cpp index df95cea8ef..db81886e94 100644 --- a/src/test/protocol/Quality_test.cpp +++ b/src/test/protocol/Quality_test.cpp @@ -24,7 +24,7 @@ public: static STAmount amount(Integer integer, std::enable_if_t>* = 0) { - static_assert(std::is_integral_v, ""); + static_assert(std::is_integral_v); return STAmount(integer, false); } @@ -32,7 +32,7 @@ public: static STAmount amount(Integer integer, std::enable_if_t>* = 0) { - static_assert(std::is_integral_v, ""); + static_assert(std::is_integral_v); if (integer < 0) return STAmount(-integer, true); return STAmount(integer, false); diff --git a/src/test/protocol/STObject_test.cpp b/src/test/protocol/STObject_test.cpp index b823b24962..8b7db632c5 100644 --- a/src/test/protocol/STObject_test.cpp +++ b/src/test/protocol/STObject_test.cpp @@ -356,8 +356,7 @@ public: { STObject st(sfGeneric); auto const v = ~st[~sf1Outer]; - static_assert( - std::is_same_v, std::optional>, ""); + static_assert(std::is_same_v, std::optional>); } // UDT scalar fields @@ -431,8 +430,7 @@ public: BEAST_EXPECT(cst[~sf]->size() == 2); // NOLINT(bugprone-unchecked-optional-access) BEAST_EXPECT(cst[sf][0] == 1); BEAST_EXPECT(cst[sf][1] == 2); - static_assert( - std::is_same_v const&>, ""); + static_assert(std::is_same_v const&>); } // Default by reference field diff --git a/src/test/protocol/SeqProxy_test.cpp b/src/test/protocol/SeqProxy_test.cpp index 90345ddc22..44aab41992 100644 --- a/src/test/protocol/SeqProxy_test.cpp +++ b/src/test/protocol/SeqProxy_test.cpp @@ -81,128 +81,128 @@ struct SeqProxy_test : public beast::unit_test::Suite static constexpr SeqProxy kTicBig{kTicket, kUintMax}; // Verify operation of value(), isSeq() and isTicket(). - static_assert(expectValues(kSeqZero, 0, kSeq), ""); - static_assert(expectValues(kSeqSmall, 1, kSeq), ""); - static_assert(expectValues(kSeqMiD0, 2, kSeq), ""); - static_assert(expectValues(kSeqMiD1, 2, kSeq), ""); - static_assert(expectValues(kSeqBig, kUintMax, kSeq), ""); + static_assert(expectValues(kSeqZero, 0, kSeq)); + static_assert(expectValues(kSeqSmall, 1, kSeq)); + static_assert(expectValues(kSeqMiD0, 2, kSeq)); + static_assert(expectValues(kSeqMiD1, 2, kSeq)); + static_assert(expectValues(kSeqBig, kUintMax, kSeq)); - static_assert(expectValues(kTicZero, 0, kTicket), ""); - static_assert(expectValues(kTicSmall, 1, kTicket), ""); - static_assert(expectValues(kTicMid0, 2, kTicket), ""); - static_assert(expectValues(kTicMid1, 2, kTicket), ""); - static_assert(expectValues(kTicBig, kUintMax, kTicket), ""); + static_assert(expectValues(kTicZero, 0, kTicket)); + static_assert(expectValues(kTicSmall, 1, kTicket)); + static_assert(expectValues(kTicMid0, 2, kTicket)); + static_assert(expectValues(kTicMid1, 2, kTicket)); + static_assert(expectValues(kTicBig, kUintMax, kTicket)); // Verify expected behavior of comparison operators. - static_assert(expectEq(kSeqZero, kSeqZero), ""); - static_assert(expectLt(kSeqZero, kSeqSmall), ""); - static_assert(expectLt(kSeqZero, kSeqMiD0), ""); - static_assert(expectLt(kSeqZero, kSeqMiD1), ""); - static_assert(expectLt(kSeqZero, kSeqBig), ""); - static_assert(expectLt(kSeqZero, kTicZero), ""); - static_assert(expectLt(kSeqZero, kTicSmall), ""); - static_assert(expectLt(kSeqZero, kTicMid0), ""); - static_assert(expectLt(kSeqZero, kTicMid1), ""); - static_assert(expectLt(kSeqZero, kTicBig), ""); + static_assert(expectEq(kSeqZero, kSeqZero)); + static_assert(expectLt(kSeqZero, kSeqSmall)); + static_assert(expectLt(kSeqZero, kSeqMiD0)); + static_assert(expectLt(kSeqZero, kSeqMiD1)); + static_assert(expectLt(kSeqZero, kSeqBig)); + static_assert(expectLt(kSeqZero, kTicZero)); + static_assert(expectLt(kSeqZero, kTicSmall)); + static_assert(expectLt(kSeqZero, kTicMid0)); + static_assert(expectLt(kSeqZero, kTicMid1)); + static_assert(expectLt(kSeqZero, kTicBig)); - static_assert(expectGt(kSeqSmall, kSeqZero), ""); - static_assert(expectEq(kSeqSmall, kSeqSmall), ""); - static_assert(expectLt(kSeqSmall, kSeqMiD0), ""); - static_assert(expectLt(kSeqSmall, kSeqMiD1), ""); - static_assert(expectLt(kSeqSmall, kSeqBig), ""); - static_assert(expectLt(kSeqSmall, kTicZero), ""); - static_assert(expectLt(kSeqSmall, kTicSmall), ""); - static_assert(expectLt(kSeqSmall, kTicMid0), ""); - static_assert(expectLt(kSeqSmall, kTicMid1), ""); - static_assert(expectLt(kSeqSmall, kTicBig), ""); + static_assert(expectGt(kSeqSmall, kSeqZero)); + static_assert(expectEq(kSeqSmall, kSeqSmall)); + static_assert(expectLt(kSeqSmall, kSeqMiD0)); + static_assert(expectLt(kSeqSmall, kSeqMiD1)); + static_assert(expectLt(kSeqSmall, kSeqBig)); + static_assert(expectLt(kSeqSmall, kTicZero)); + static_assert(expectLt(kSeqSmall, kTicSmall)); + static_assert(expectLt(kSeqSmall, kTicMid0)); + static_assert(expectLt(kSeqSmall, kTicMid1)); + static_assert(expectLt(kSeqSmall, kTicBig)); - static_assert(expectGt(kSeqMiD0, kSeqZero), ""); - static_assert(expectGt(kSeqMiD0, kSeqSmall), ""); - static_assert(expectEq(kSeqMiD0, kSeqMiD0), ""); - static_assert(expectEq(kSeqMiD0, kSeqMiD1), ""); - static_assert(expectLt(kSeqMiD0, kSeqBig), ""); - static_assert(expectLt(kSeqMiD0, kTicZero), ""); - static_assert(expectLt(kSeqMiD0, kTicSmall), ""); - static_assert(expectLt(kSeqMiD0, kTicMid0), ""); - static_assert(expectLt(kSeqMiD0, kTicMid1), ""); - static_assert(expectLt(kSeqMiD0, kTicBig), ""); + static_assert(expectGt(kSeqMiD0, kSeqZero)); + static_assert(expectGt(kSeqMiD0, kSeqSmall)); + static_assert(expectEq(kSeqMiD0, kSeqMiD0)); + static_assert(expectEq(kSeqMiD0, kSeqMiD1)); + static_assert(expectLt(kSeqMiD0, kSeqBig)); + static_assert(expectLt(kSeqMiD0, kTicZero)); + static_assert(expectLt(kSeqMiD0, kTicSmall)); + static_assert(expectLt(kSeqMiD0, kTicMid0)); + static_assert(expectLt(kSeqMiD0, kTicMid1)); + static_assert(expectLt(kSeqMiD0, kTicBig)); - static_assert(expectGt(kSeqMiD1, kSeqZero), ""); - static_assert(expectGt(kSeqMiD1, kSeqSmall), ""); - static_assert(expectEq(kSeqMiD1, kSeqMiD0), ""); - static_assert(expectEq(kSeqMiD1, kSeqMiD1), ""); - static_assert(expectLt(kSeqMiD1, kSeqBig), ""); - static_assert(expectLt(kSeqMiD1, kTicZero), ""); - static_assert(expectLt(kSeqMiD1, kTicSmall), ""); - static_assert(expectLt(kSeqMiD1, kTicMid0), ""); - static_assert(expectLt(kSeqMiD1, kTicMid1), ""); - static_assert(expectLt(kSeqMiD1, kTicBig), ""); + static_assert(expectGt(kSeqMiD1, kSeqZero)); + static_assert(expectGt(kSeqMiD1, kSeqSmall)); + static_assert(expectEq(kSeqMiD1, kSeqMiD0)); + static_assert(expectEq(kSeqMiD1, kSeqMiD1)); + static_assert(expectLt(kSeqMiD1, kSeqBig)); + static_assert(expectLt(kSeqMiD1, kTicZero)); + static_assert(expectLt(kSeqMiD1, kTicSmall)); + static_assert(expectLt(kSeqMiD1, kTicMid0)); + static_assert(expectLt(kSeqMiD1, kTicMid1)); + static_assert(expectLt(kSeqMiD1, kTicBig)); - static_assert(expectGt(kSeqBig, kSeqZero), ""); - static_assert(expectGt(kSeqBig, kSeqSmall), ""); - static_assert(expectGt(kSeqBig, kSeqMiD0), ""); - static_assert(expectGt(kSeqBig, kSeqMiD1), ""); - static_assert(expectEq(kSeqBig, kSeqBig), ""); - static_assert(expectLt(kSeqBig, kTicZero), ""); - static_assert(expectLt(kSeqBig, kTicSmall), ""); - static_assert(expectLt(kSeqBig, kTicMid0), ""); - static_assert(expectLt(kSeqBig, kTicMid1), ""); - static_assert(expectLt(kSeqBig, kTicBig), ""); + static_assert(expectGt(kSeqBig, kSeqZero)); + static_assert(expectGt(kSeqBig, kSeqSmall)); + static_assert(expectGt(kSeqBig, kSeqMiD0)); + static_assert(expectGt(kSeqBig, kSeqMiD1)); + static_assert(expectEq(kSeqBig, kSeqBig)); + static_assert(expectLt(kSeqBig, kTicZero)); + static_assert(expectLt(kSeqBig, kTicSmall)); + static_assert(expectLt(kSeqBig, kTicMid0)); + static_assert(expectLt(kSeqBig, kTicMid1)); + static_assert(expectLt(kSeqBig, kTicBig)); - static_assert(expectGt(kTicZero, kSeqZero), ""); - static_assert(expectGt(kTicZero, kSeqSmall), ""); - static_assert(expectGt(kTicZero, kSeqMiD0), ""); - static_assert(expectGt(kTicZero, kSeqMiD1), ""); - static_assert(expectGt(kTicZero, kSeqBig), ""); - static_assert(expectEq(kTicZero, kTicZero), ""); - static_assert(expectLt(kTicZero, kTicSmall), ""); - static_assert(expectLt(kTicZero, kTicMid0), ""); - static_assert(expectLt(kTicZero, kTicMid1), ""); - static_assert(expectLt(kTicZero, kTicBig), ""); + static_assert(expectGt(kTicZero, kSeqZero)); + static_assert(expectGt(kTicZero, kSeqSmall)); + static_assert(expectGt(kTicZero, kSeqMiD0)); + static_assert(expectGt(kTicZero, kSeqMiD1)); + static_assert(expectGt(kTicZero, kSeqBig)); + static_assert(expectEq(kTicZero, kTicZero)); + static_assert(expectLt(kTicZero, kTicSmall)); + static_assert(expectLt(kTicZero, kTicMid0)); + static_assert(expectLt(kTicZero, kTicMid1)); + static_assert(expectLt(kTicZero, kTicBig)); - static_assert(expectGt(kTicSmall, kSeqZero), ""); - static_assert(expectGt(kTicSmall, kSeqSmall), ""); - static_assert(expectGt(kTicSmall, kSeqMiD0), ""); - static_assert(expectGt(kTicSmall, kSeqMiD1), ""); - static_assert(expectGt(kTicSmall, kSeqBig), ""); - static_assert(expectGt(kTicSmall, kTicZero), ""); - static_assert(expectEq(kTicSmall, kTicSmall), ""); - static_assert(expectLt(kTicSmall, kTicMid0), ""); - static_assert(expectLt(kTicSmall, kTicMid1), ""); - static_assert(expectLt(kTicSmall, kTicBig), ""); + static_assert(expectGt(kTicSmall, kSeqZero)); + static_assert(expectGt(kTicSmall, kSeqSmall)); + static_assert(expectGt(kTicSmall, kSeqMiD0)); + static_assert(expectGt(kTicSmall, kSeqMiD1)); + static_assert(expectGt(kTicSmall, kSeqBig)); + static_assert(expectGt(kTicSmall, kTicZero)); + static_assert(expectEq(kTicSmall, kTicSmall)); + static_assert(expectLt(kTicSmall, kTicMid0)); + static_assert(expectLt(kTicSmall, kTicMid1)); + static_assert(expectLt(kTicSmall, kTicBig)); - static_assert(expectGt(kTicMid0, kSeqZero), ""); - static_assert(expectGt(kTicMid0, kSeqSmall), ""); - static_assert(expectGt(kTicMid0, kSeqMiD0), ""); - static_assert(expectGt(kTicMid0, kSeqMiD1), ""); - static_assert(expectGt(kTicMid0, kSeqBig), ""); - static_assert(expectGt(kTicMid0, kTicZero), ""); - static_assert(expectGt(kTicMid0, kTicSmall), ""); - static_assert(expectEq(kTicMid0, kTicMid0), ""); - static_assert(expectEq(kTicMid0, kTicMid1), ""); - static_assert(expectLt(kTicMid0, kTicBig), ""); + static_assert(expectGt(kTicMid0, kSeqZero)); + static_assert(expectGt(kTicMid0, kSeqSmall)); + static_assert(expectGt(kTicMid0, kSeqMiD0)); + static_assert(expectGt(kTicMid0, kSeqMiD1)); + static_assert(expectGt(kTicMid0, kSeqBig)); + static_assert(expectGt(kTicMid0, kTicZero)); + static_assert(expectGt(kTicMid0, kTicSmall)); + static_assert(expectEq(kTicMid0, kTicMid0)); + static_assert(expectEq(kTicMid0, kTicMid1)); + static_assert(expectLt(kTicMid0, kTicBig)); - static_assert(expectGt(kTicMid1, kSeqZero), ""); - static_assert(expectGt(kTicMid1, kSeqSmall), ""); - static_assert(expectGt(kTicMid1, kSeqMiD0), ""); - static_assert(expectGt(kTicMid1, kSeqMiD1), ""); - static_assert(expectGt(kTicMid1, kSeqBig), ""); - static_assert(expectGt(kTicMid1, kTicZero), ""); - static_assert(expectGt(kTicMid1, kTicSmall), ""); - static_assert(expectEq(kTicMid1, kTicMid0), ""); - static_assert(expectEq(kTicMid1, kTicMid1), ""); - static_assert(expectLt(kTicMid1, kTicBig), ""); + static_assert(expectGt(kTicMid1, kSeqZero)); + static_assert(expectGt(kTicMid1, kSeqSmall)); + static_assert(expectGt(kTicMid1, kSeqMiD0)); + static_assert(expectGt(kTicMid1, kSeqMiD1)); + static_assert(expectGt(kTicMid1, kSeqBig)); + static_assert(expectGt(kTicMid1, kTicZero)); + static_assert(expectGt(kTicMid1, kTicSmall)); + static_assert(expectEq(kTicMid1, kTicMid0)); + static_assert(expectEq(kTicMid1, kTicMid1)); + static_assert(expectLt(kTicMid1, kTicBig)); - static_assert(expectGt(kTicBig, kSeqZero), ""); - static_assert(expectGt(kTicBig, kSeqSmall), ""); - static_assert(expectGt(kTicBig, kSeqMiD0), ""); - static_assert(expectGt(kTicBig, kSeqMiD1), ""); - static_assert(expectGt(kTicBig, kSeqBig), ""); - static_assert(expectGt(kTicBig, kTicZero), ""); - static_assert(expectGt(kTicBig, kTicSmall), ""); - static_assert(expectGt(kTicBig, kTicMid0), ""); - static_assert(expectGt(kTicBig, kTicMid1), ""); - static_assert(expectEq(kTicBig, kTicBig), ""); + static_assert(expectGt(kTicBig, kSeqZero)); + static_assert(expectGt(kTicBig, kSeqSmall)); + static_assert(expectGt(kTicBig, kSeqMiD0)); + static_assert(expectGt(kTicBig, kSeqMiD1)); + static_assert(expectGt(kTicBig, kSeqBig)); + static_assert(expectGt(kTicBig, kTicZero)); + static_assert(expectGt(kTicBig, kTicSmall)); + static_assert(expectGt(kTicBig, kTicMid0)); + static_assert(expectGt(kTicBig, kTicMid1)); + static_assert(expectEq(kTicBig, kTicBig)); // Verify streaming. BEAST_EXPECT(streamTest(kSeqZero)); diff --git a/src/test/shamap/SHAMap_test.cpp b/src/test/shamap/SHAMap_test.cpp index ab7e01e3af..5ff5ef5e05 100644 --- a/src/test/shamap/SHAMap_test.cpp +++ b/src/test/shamap/SHAMap_test.cpp @@ -26,57 +26,57 @@ namespace xrpl::tests { #ifndef __INTELLISENSE__ -static_assert(std::is_nothrow_destructible{}, ""); -static_assert(!std::is_default_constructible{}, ""); -static_assert(!std::is_copy_constructible{}, ""); -static_assert(!std::is_copy_assignable{}, ""); -static_assert(!std::is_move_constructible{}, ""); -static_assert(!std::is_move_assignable{}, ""); +static_assert(std::is_nothrow_destructible{}); +static_assert(!std::is_default_constructible{}); +static_assert(!std::is_copy_constructible{}); +static_assert(!std::is_copy_assignable{}); +static_assert(!std::is_move_constructible{}); +static_assert(!std::is_move_assignable{}); -static_assert(std::is_nothrow_destructible{}, ""); -static_assert(std::is_copy_constructible{}, ""); -static_assert(std::is_copy_assignable{}, ""); -static_assert(std::is_move_constructible{}, ""); -static_assert(std::is_move_assignable{}, ""); +static_assert(std::is_nothrow_destructible{}); +static_assert(std::is_copy_constructible{}); +static_assert(std::is_copy_assignable{}); +static_assert(std::is_move_constructible{}); +static_assert(std::is_move_assignable{}); -static_assert(std::is_nothrow_destructible{}, ""); -static_assert(!std::is_default_constructible{}, ""); -static_assert(!std::is_copy_constructible{}, ""); +static_assert(std::is_nothrow_destructible{}); +static_assert(!std::is_default_constructible{}); +static_assert(!std::is_copy_constructible{}); -static_assert(std::is_nothrow_destructible{}, ""); -static_assert(std::is_default_constructible{}, ""); -static_assert(std::is_copy_constructible{}, ""); -static_assert(std::is_copy_assignable{}, ""); -static_assert(std::is_move_constructible{}, ""); -static_assert(std::is_move_assignable{}, ""); +static_assert(std::is_nothrow_destructible{}); +static_assert(std::is_default_constructible{}); +static_assert(std::is_copy_constructible{}); +static_assert(std::is_copy_assignable{}); +static_assert(std::is_move_constructible{}); +static_assert(std::is_move_assignable{}); -static_assert(std::is_nothrow_destructible{}, ""); -static_assert(std::is_default_constructible{}, ""); -static_assert(std::is_copy_constructible{}, ""); -static_assert(std::is_copy_assignable{}, ""); -static_assert(std::is_move_constructible{}, ""); -static_assert(std::is_move_assignable{}, ""); +static_assert(std::is_nothrow_destructible{}); +static_assert(std::is_default_constructible{}); +static_assert(std::is_copy_constructible{}); +static_assert(std::is_copy_assignable{}); +static_assert(std::is_move_constructible{}); +static_assert(std::is_move_assignable{}); -static_assert(std::is_nothrow_destructible{}, ""); -static_assert(!std::is_default_constructible{}, ""); -static_assert(!std::is_copy_constructible{}, ""); -static_assert(!std::is_copy_assignable{}, ""); -static_assert(!std::is_move_constructible{}, ""); -static_assert(!std::is_move_assignable{}, ""); +static_assert(std::is_nothrow_destructible{}); +static_assert(!std::is_default_constructible{}); +static_assert(!std::is_copy_constructible{}); +static_assert(!std::is_copy_assignable{}); +static_assert(!std::is_move_constructible{}); +static_assert(!std::is_move_assignable{}); -static_assert(std::is_nothrow_destructible{}, ""); -static_assert(!std::is_default_constructible{}, ""); -static_assert(!std::is_copy_constructible{}, ""); -static_assert(!std::is_copy_assignable{}, ""); -static_assert(!std::is_move_constructible{}, ""); -static_assert(!std::is_move_assignable{}, ""); +static_assert(std::is_nothrow_destructible{}); +static_assert(!std::is_default_constructible{}); +static_assert(!std::is_copy_constructible{}); +static_assert(!std::is_copy_assignable{}); +static_assert(!std::is_move_constructible{}); +static_assert(!std::is_move_assignable{}); -static_assert(std::is_nothrow_destructible{}, ""); -static_assert(!std::is_default_constructible{}, ""); -static_assert(!std::is_copy_constructible{}, ""); -static_assert(!std::is_copy_assignable{}, ""); -static_assert(!std::is_move_constructible{}, ""); -static_assert(!std::is_move_assignable{}, ""); +static_assert(std::is_nothrow_destructible{}); +static_assert(!std::is_default_constructible{}); +static_assert(!std::is_copy_constructible{}); +static_assert(!std::is_copy_assignable{}); +static_assert(!std::is_move_constructible{}); +static_assert(!std::is_move_assignable{}); #endif inline bool diff --git a/src/xrpld/app/misc/detail/TxQ.cpp b/src/xrpld/app/misc/detail/TxQ.cpp index 7e57302d23..5d1020d296 100644 --- a/src/xrpld/app/misc/detail/TxQ.cpp +++ b/src/xrpld/app/misc/detail/TxQ.cpp @@ -228,11 +228,11 @@ static_assert(sumOfFirstSquares(1).second == 1); static_assert(sumOfFirstSquares(2).first); static_assert(sumOfFirstSquares(2).second == 5); -static_assert(sumOfFirstSquares(0x1FFFFF).first, ""); -static_assert(sumOfFirstSquares(0x1FFFFF).second == 0x2AAAA8AAAAB00000ul, ""); +static_assert(sumOfFirstSquares(0x1FFFFF).first); +static_assert(sumOfFirstSquares(0x1FFFFF).second == 0x2AAAA8AAAAB00000ul); -static_assert(!sumOfFirstSquares(0x200000).first, ""); -static_assert(sumOfFirstSquares(0x200000).second == std::numeric_limits::max(), ""); +static_assert(!sumOfFirstSquares(0x200000).first); +static_assert(sumOfFirstSquares(0x200000).second == std::numeric_limits::max()); } // namespace detail From 6003fd03fc11c7675a9f03ba791e63aaa0e8265a Mon Sep 17 00:00:00 2001 From: yinyiqian1 Date: Thu, 2 Jul 2026 14:37:37 -0400 Subject: [PATCH 05/19] feat: Enable ConfidentialTransfer and BatchV1_1 (#7698) --- include/xrpl/protocol/detail/features.macro | 4 ++-- src/test/app/Delegate_test.cpp | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/include/xrpl/protocol/detail/features.macro b/include/xrpl/protocol/detail/features.macro index a7a62f0322..3f078561a3 100644 --- a/include/xrpl/protocol/detail/features.macro +++ b/include/xrpl/protocol/detail/features.macro @@ -15,9 +15,9 @@ // Add new amendments to the top of this list. // Keep it sorted in reverse chronological order. -XRPL_FEATURE(BatchV1_1, Supported::No, VoteBehavior::DefaultNo) +XRPL_FEATURE(BatchV1_1, Supported::Yes, VoteBehavior::DefaultNo) XRPL_FEATURE(LendingProtocolV1_1, Supported::No, VoteBehavior::DefaultNo) -XRPL_FEATURE(ConfidentialTransfer, Supported::No, VoteBehavior::DefaultNo) +XRPL_FEATURE(ConfidentialTransfer, Supported::Yes, VoteBehavior::DefaultNo) XRPL_FIX (Cleanup3_3_0, Supported::Yes, VoteBehavior::DefaultNo) XRPL_FIX (Cleanup3_2_0, Supported::Yes, VoteBehavior::DefaultNo) XRPL_FEATURE(MPTokensV2, Supported::No, VoteBehavior::DefaultNo) diff --git a/src/test/app/Delegate_test.cpp b/src/test/app/Delegate_test.cpp index 02ee0750d5..6f1d2ce7de 100644 --- a/src/test/app/Delegate_test.cpp +++ b/src/test/app/Delegate_test.cpp @@ -2747,8 +2747,6 @@ class Delegate_test : public beast::unit_test::Suite // DO NOT modify expectedDelegableCount unless all scenarios, including // edge cases, have been fully tested and verified. // ==================================================================== - // Includes the five confidential MPT transaction types, which are - // explicitly marked Delegable in transactions.macro. std::size_t const expectedDelegableCount = 56; BEAST_EXPECTS( From 3d847f2a6039be6837d7ed8329a9a8496283dc4a Mon Sep 17 00:00:00 2001 From: Bart Date: Thu, 2 Jul 2026 14:46:27 -0400 Subject: [PATCH 06/19] build: Add protobuf dependencies to Nix (#7706) Co-authored-by: Bart <11445373+bthomee@users.noreply.github.com> --- nix/packages.nix | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nix/packages.nix b/nix/packages.nix index 6202168733..bcadfe7456 100644 --- a/nix/packages.nix +++ b/nix/packages.nix @@ -32,6 +32,15 @@ in perl # needed for openssl pkg-config pre-commit + # protoc generates the Go gRPC bindings and embeds its own version string into every committed + # .pb.go file. To allow CI to verify those files with a plain `git diff`, we pin the version to + # `protobuf_34` rather than the rolling `protobuf` to keep regeneration reproducible across the + # Nix frequently changing unstable channel. The protoc-gen-go* plugins have no versioned + # attributes in nixpkgs; protoc-gen-go's version is in turn constrained by the go.mod require + # on google.golang.org/protobuf. + protobuf_34 # provides protoc + protoc-gen-go # protoc plugin for the Go message bindings + protoc-gen-go-grpc # protoc plugin for the Go gRPC service stubs python3 runClangTidy vim From 7ba1d76d0543c94e74df3c634b11448b293cdaf8 Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Thu, 2 Jul 2026 21:02:55 +0100 Subject: [PATCH 07/19] chore: Enable modernize-use-auto (#7707) --- .clang-tidy | 1 - include/xrpl/beast/hash/hash_append.h | 2 +- include/xrpl/beast/utility/rngfill.h | 4 ++-- include/xrpl/core/JobTypes.h | 2 +- include/xrpl/ledger/helpers/EscrowHelpers.h | 2 +- include/xrpl/nodestore/detail/codec.h | 8 ++++---- include/xrpl/nodestore/detail/varint.h | 4 ++-- include/xrpl/protocol/Quality.h | 2 +- include/xrpl/protocol/STBitString.h | 2 +- include/xrpl/protocol/STInteger.h | 2 +- src/libxrpl/basics/Number.cpp | 2 +- src/libxrpl/beast/insight/StatsDCollector.cpp | 4 ++-- src/libxrpl/core/detail/JobQueue.cpp | 10 +++++----- src/libxrpl/crypto/RFC1751.cpp | 2 +- src/libxrpl/json/json_reader.cpp | 2 +- src/libxrpl/json/json_value.cpp | 16 ++++++++-------- src/libxrpl/json/json_writer.cpp | 6 +++--- src/libxrpl/nodestore/DecodedBlob.cpp | 2 +- src/libxrpl/nodestore/backend/MemoryFactory.cpp | 2 +- src/libxrpl/nodestore/backend/NuDBFactory.cpp | 2 +- src/libxrpl/nodestore/backend/RocksDBFactory.cpp | 2 +- src/libxrpl/protocol/IOUAmount.cpp | 2 +- src/libxrpl/protocol/MPTIssue.cpp | 3 +-- src/libxrpl/protocol/NFTokenID.cpp | 3 +-- src/libxrpl/protocol/STAmount.cpp | 2 +- src/libxrpl/protocol/STBlob.cpp | 2 +- src/libxrpl/protocol/STCurrency.cpp | 2 +- src/libxrpl/protocol/STIssue.cpp | 2 +- src/libxrpl/protocol/STNumber.cpp | 2 +- src/libxrpl/protocol/STObject.cpp | 10 +++++----- src/libxrpl/protocol/STPathSet.cpp | 4 ++-- src/libxrpl/protocol/STVector256.cpp | 2 +- src/libxrpl/protocol/STXChainBridge.cpp | 2 +- .../tx/transactors/escrow/EscrowCreate.cpp | 2 +- src/test/app/ConfidentialTransfer_test.cpp | 2 +- src/test/app/Loan_test.cpp | 2 +- src/test/app/Offer_test.cpp | 2 +- src/test/beast/LexicalCast_test.cpp | 6 +++--- .../beast/aged_associative_container_test.cpp | 2 +- src/test/shamap/FetchPack_test.cpp | 2 +- src/xrpld/app/consensus/RCLConsensus.cpp | 2 +- src/xrpld/app/ledger/detail/InboundLedgers.cpp | 2 +- src/xrpld/app/main/Application.cpp | 2 +- src/xrpld/app/misc/NetworkOPs.cpp | 4 ++-- src/xrpld/app/misc/detail/Transaction.cpp | 2 +- src/xrpld/app/misc/detail/TxQ.cpp | 10 +++++----- src/xrpld/app/rdb/backend/detail/Node.cpp | 2 +- src/xrpld/core/detail/Config.cpp | 2 +- src/xrpld/rpc/CTID.h | 6 +++--- src/xrpld/rpc/handlers/orderbook/BookOffers.cpp | 2 +- 50 files changed, 82 insertions(+), 85 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 2b0b7e4418..6a24cbc8d3 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -80,7 +80,6 @@ Checks: "-*, -modernize-replace-random-shuffle, -modernize-return-braced-init-list, -modernize-shrink-to-fit, - -modernize-use-auto, -modernize-use-bool-literals, -modernize-use-constraints, -modernize-use-default-member-init, diff --git a/include/xrpl/beast/hash/hash_append.h b/include/xrpl/beast/hash/hash_append.h index 0b36d4c983..5f77f41e5d 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) { - unsigned char* bytes = + auto* 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]); diff --git a/include/xrpl/beast/utility/rngfill.h b/include/xrpl/beast/utility/rngfill.h index 0fc3ffe0d0..ee7a5e2434 100644 --- a/include/xrpl/beast/utility/rngfill.h +++ b/include/xrpl/beast/utility/rngfill.h @@ -14,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); - std::uint8_t* const bufferStart = static_cast(buffer); + auto* const bufferStart = static_cast(buffer); std::size_t const completeIterations = bytes / kResultSize; std::size_t const bytesRemaining = bytes % kResultSize; @@ -42,7 +42,7 @@ rngfill(std::array& a, Generator& g) { using result_type = Generator::result_type; auto i = N / sizeof(result_type); - result_type* p = reinterpret_cast(a.data()); + auto* p = reinterpret_cast(a.data()); while (i--) *p++ = g(); } diff --git a/include/xrpl/core/JobTypes.h b/include/xrpl/core/JobTypes.h index f338b19f6c..cc2f3ecbf5 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 { - Map::const_iterator const iter(map.find(jt)); + auto const iter = map.find(jt); XRPL_ASSERT(iter != map.end(), "xrpl::JobTypes::get : valid input"); if (iter != map.end()) diff --git a/include/xrpl/ledger/helpers/EscrowHelpers.h b/include/xrpl/ledger/helpers/EscrowHelpers.h index 001dc9cb25..d173c33c56 100644 --- a/include/xrpl/ledger/helpers/EscrowHelpers.h +++ b/include/xrpl/ledger/helpers/EscrowHelpers.h @@ -54,7 +54,7 @@ escrowUnlockApplyHelper( bool createAsset, beast::Journal journal) { - Issue const& issue = amount.get(); + auto 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/nodestore/detail/codec.h b/include/xrpl/nodestore/detail/codec.h index 56e1fbcf73..2f69d532be 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); - std::uint8_t* out = reinterpret_cast(bf(n + outMax)); + auto* 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; - std::uint8_t const* p = reinterpret_cast(in); + auto 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 - std::uint8_t* out = reinterpret_cast(bf(result.second)); + auto* 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 - std::uint8_t* out = reinterpret_cast(bf(result.second)); + auto* 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 21a13bd6de..6102c0cf2d 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; - std::uint8_t const* p = reinterpret_cast(buf); + auto const* p = reinterpret_cast(buf); std::size_t n = 0; while (p[n] & 0x80) { @@ -86,7 +86,7 @@ std::size_t writeVarint(void* p0, std::size_t v) { // NOLINTNEXTLINE(misc-const-correctness) - std::uint8_t* p = reinterpret_cast(p0); + auto* p = reinterpret_cast(p0); do { std::uint8_t d = v % 127; diff --git a/include/xrpl/protocol/Quality.h b/include/xrpl/protocol/Quality.h index 6bb2033dc0..de61d79ca5 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); - double const minVD = static_cast(minVMantissa); + auto const minVD = static_cast(minVMantissa); double const maxVD = (expDiff != 0) ? maxVMantissa * pow(10, expDiff) : static_cast(maxVMantissa); diff --git a/include/xrpl/protocol/STBitString.h b/include/xrpl/protocol/STBitString.h index 4f25eccca6..6f71f48f25 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 { - STBitString const* v = dynamic_cast(&t); + auto 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 1c7ac98f3e..951c4fc52f 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 { - STInteger const* v = dynamic_cast(&t); + auto const* v = dynamic_cast(&t); return v && (value_ == v->value_); } diff --git a/src/libxrpl/basics/Number.cpp b/src/libxrpl/basics/Number.cpp index 23e913bbdc..4d7a821040 100644 --- a/src/libxrpl/basics/Number.cpp +++ b/src/libxrpl/basics/Number.cpp @@ -876,7 +876,7 @@ Number::operator/=(Number const& y) int const ds = (dp ? -1 : 1); // Create the denominator as 128-bit unsigned, since that's what we // need to work with. - uint128_t const dm = static_cast(y.mantissa_); + auto const dm = static_cast(y.mantissa_); auto const de = y.exponent_; auto const& range = kRange.get(); diff --git a/src/libxrpl/beast/insight/StatsDCollector.cpp b/src/libxrpl/beast/insight/StatsDCollector.cpp index 0d0e013274..1da5315de1 100644 --- a/src/libxrpl/beast/insight/StatsDCollector.cpp +++ b/src/libxrpl/beast/insight/StatsDCollector.cpp @@ -640,14 +640,14 @@ StatsDGaugeImpl::doIncrement(GaugeImpl::difference_type amount) if (amount > 0) { - GaugeImpl::value_type const d(static_cast(amount)); + auto const d = static_cast(amount); value += (d >= std::numeric_limits::max() - value_) ? std::numeric_limits::max() - value_ : d; } else if (amount < 0) { - GaugeImpl::value_type const d(static_cast(-amount)); + auto const d = static_cast(-amount); value = (d >= value) ? 0 : value - d; } diff --git a/src/libxrpl/core/detail/JobQueue.cpp b/src/libxrpl/core/detail/JobQueue.cpp index ffb91db72d..f773270af3 100644 --- a/src/libxrpl/core/detail/JobQueue.cpp +++ b/src/libxrpl/core/detail/JobQueue.cpp @@ -122,7 +122,7 @@ JobQueue::getJobCount(JobType t) const { std::scoped_lock const lock(mutex_); - JobDataMap::const_iterator const c = jobData_.find(t); + auto const c = jobData_.find(t); return (c == jobData_.end()) ? 0 : c->second.waiting; } @@ -132,7 +132,7 @@ JobQueue::getJobCountTotal(JobType t) const { std::scoped_lock const lock(mutex_); - JobDataMap::const_iterator const c = jobData_.find(t); + auto const c = jobData_.find(t); return (c == jobData_.end()) ? 0 : (c->second.waiting + c->second.running); } @@ -157,7 +157,7 @@ JobQueue::getJobCountGE(JobType t) const std::unique_ptr JobQueue::makeLoadEvent(JobType t, std::string const& name) { - JobDataMap::iterator const iter(jobData_.find(t)); + auto const iter = jobData_.find(t); XRPL_ASSERT(iter != jobData_.end(), "xrpl::JobQueue::makeLoadEvent : valid job type input"); if (iter == jobData_.end()) @@ -172,7 +172,7 @@ JobQueue::addLoadEvents(JobType t, int count, std::chrono::milliseconds elapsed) if (isStopped()) logicError("JobQueue::addLoadEvents() called after JobQueue stopped"); - JobDataMap::iterator const iter(jobData_.find(t)); + auto const iter = jobData_.find(t); XRPL_ASSERT(iter != jobData_.end(), "xrpl::JobQueue::addLoadEvents : valid job type input"); iter->second.load().addSamples(count, elapsed); } @@ -250,7 +250,7 @@ JobQueue::rendezvous() JobTypeData& JobQueue::getJobTypeData(JobType type) { - JobDataMap::iterator const c(jobData_.find(type)); + auto const c = jobData_.find(type); XRPL_ASSERT(c != jobData_.end(), "xrpl::JobQueue::getJobTypeData : valid job type input"); // NIKB: This is ugly and I hate it. We must remove JtInvalid completely diff --git a/src/libxrpl/crypto/RFC1751.cpp b/src/libxrpl/crypto/RFC1751.cpp index 16482945d2..41e29ee00c 100644 --- a/src/libxrpl/crypto/RFC1751.cpp +++ b/src/libxrpl/crypto/RFC1751.cpp @@ -434,7 +434,7 @@ RFC1751::getWordFromBlob(void const* blob, size_t bytes) // This is a simple implementation of the Jenkins one-at-a-time hash // algorithm: // http://en.wikipedia.org/wiki/Jenkins_hash_function#one-at-a-time - unsigned char const* data = static_cast(blob); + auto const* data = static_cast(blob); std::uint32_t hash = 0; for (size_t i = 0; i < bytes; ++i) diff --git a/src/libxrpl/json/json_reader.cpp b/src/libxrpl/json/json_reader.cpp index 3786f51fdd..45e448c480 100644 --- a/src/libxrpl/json/json_reader.cpp +++ b/src/libxrpl/json/json_reader.cpp @@ -908,7 +908,7 @@ Reader::getFormattedErrorMessages() const { std::string formattedMessage; - for (Errors::const_iterator itError = errors_.begin(); itError != errors_.end(); ++itError) + for (auto itError = errors_.begin(); itError != errors_.end(); ++itError) { ErrorInfo const& error = *itError; formattedMessage += "* " + getLocationLineAndColumn(error.token.start) + "\n"; diff --git a/src/libxrpl/json/json_value.cpp b/src/libxrpl/json/json_value.cpp index 074a88428c..7218b8c6cf 100644 --- a/src/libxrpl/json/json_value.cpp +++ b/src/libxrpl/json/json_value.cpp @@ -802,7 +802,7 @@ Value::size() const case ValueType::Array: // size of the array is highest index + 1 if (!value_.mapVal->empty()) { - ObjectValues::const_iterator itLast = value_.mapVal->end(); + auto itLast = value_.mapVal->end(); --itLast; return (*itLast).first.index() + 1; } @@ -866,7 +866,7 @@ Value::operator[](UInt index) *this = Value(ValueType::Array); CZString const key(index); - ObjectValues::iterator it = value_.mapVal->lower_bound(key); + auto it = value_.mapVal->lower_bound(key); if (it != value_.mapVal->end() && (*it).first == key) return (*it).second; @@ -887,7 +887,7 @@ Value::operator[](UInt index) const return kNull; CZString const key(index); - ObjectValues::const_iterator const it = value_.mapVal->find(key); + auto const it = value_.mapVal->find(key); if (it == value_.mapVal->end()) return kNull; @@ -915,7 +915,7 @@ Value::resolveReference(char const* key, bool isStatic) key, isStatic ? CZString::DuplicationPolicy::NoDuplication : CZString::DuplicationPolicy::DuplicateOnCopy); - ObjectValues::iterator it = value_.mapVal->lower_bound(actualKey); + auto it = value_.mapVal->lower_bound(actualKey); if (it != value_.mapVal->end() && (*it).first == actualKey) return (*it).second; @@ -950,7 +950,7 @@ Value::operator[](char const* key) const return kNull; CZString const actualKey(key, CZString::DuplicationPolicy::NoDuplication); - ObjectValues::const_iterator const it = value_.mapVal->find(actualKey); + auto const it = value_.mapVal->find(actualKey); if (it == value_.mapVal->end()) return kNull; @@ -1018,7 +1018,7 @@ Value::removeMember(char const* key) return kNull; CZString const actualKey(key, CZString::DuplicationPolicy::NoDuplication); - ObjectValues::iterator const it = value_.mapVal->find(actualKey); + auto const it = value_.mapVal->find(actualKey); if (it == value_.mapVal->end()) return kNull; @@ -1068,8 +1068,8 @@ Value::getMemberNames() const Members members; members.reserve(value_.mapVal->size()); - ObjectValues::const_iterator it = value_.mapVal->begin(); - ObjectValues::const_iterator const itEnd = value_.mapVal->end(); + auto it = value_.mapVal->begin(); + auto const itEnd = value_.mapVal->end(); for (; it != itEnd; ++it) members.emplace_back((*it).first.cStr()); diff --git a/src/libxrpl/json/json_writer.cpp b/src/libxrpl/json/json_writer.cpp index 4c38bdcf92..c9f8cb688b 100644 --- a/src/libxrpl/json/json_writer.cpp +++ b/src/libxrpl/json/json_writer.cpp @@ -232,7 +232,7 @@ FastWriter::writeValue(Value const& value) Value::Members members(value.getMemberNames()); document_ += "{"; - for (Value::Members::iterator it = members.begin(); it != members.end(); ++it) + for (auto it = members.begin(); it != members.end(); ++it) { std::string const& name = *it; @@ -310,7 +310,7 @@ StyledWriter::writeValue(Value const& value) { writeWithIndent("{"); indent(); - Value::Members::iterator it = members.begin(); + auto it = members.begin(); while (true) { @@ -545,7 +545,7 @@ StyledStreamWriter::writeValue(Value const& value) { writeWithIndent("{"); indent(); - Value::Members::iterator it = members.begin(); + auto it = members.begin(); while (true) { diff --git a/src/libxrpl/nodestore/DecodedBlob.cpp b/src/libxrpl/nodestore/DecodedBlob.cpp index fb7569bd8c..fe07252f23 100644 --- a/src/libxrpl/nodestore/DecodedBlob.cpp +++ b/src/libxrpl/nodestore/DecodedBlob.cpp @@ -33,7 +33,7 @@ DecodedBlob::DecodedBlob(void const* key, void const* value, int valueBytes) if (valueBytes > 8) { - unsigned char const* byte = static_cast(value); + auto const* byte = static_cast(value); objectType_ = safeCast(byte[8]); } diff --git a/src/libxrpl/nodestore/backend/MemoryFactory.cpp b/src/libxrpl/nodestore/backend/MemoryFactory.cpp index 70578c8613..22557d652e 100644 --- a/src/libxrpl/nodestore/backend/MemoryFactory.cpp +++ b/src/libxrpl/nodestore/backend/MemoryFactory.cpp @@ -136,7 +136,7 @@ public: std::scoped_lock const _(db_->mutex); - Map::iterator const iter = db_->table.find(hash); + auto const iter = db_->table.find(hash); if (iter == db_->table.end()) { pObject->reset(); diff --git a/src/libxrpl/nodestore/backend/NuDBFactory.cpp b/src/libxrpl/nodestore/backend/NuDBFactory.cpp index 749d4020b5..38ea34258f 100644 --- a/src/libxrpl/nodestore/backend/NuDBFactory.cpp +++ b/src/libxrpl/nodestore/backend/NuDBFactory.cpp @@ -367,7 +367,7 @@ private: try { - std::size_t const parsedBlockSize = beast::lexicalCastThrow(blockSizeStr); + auto const parsedBlockSize = beast::lexicalCastThrow(blockSizeStr); // Validate: must be power of 2 between 4K and 32K if (parsedBlockSize < 4096 || parsedBlockSize > 32768 || diff --git a/src/libxrpl/nodestore/backend/RocksDBFactory.cpp b/src/libxrpl/nodestore/backend/RocksDBFactory.cpp index 69a648f2f4..bcf4ba4a49 100644 --- a/src/libxrpl/nodestore/backend/RocksDBFactory.cpp +++ b/src/libxrpl/nodestore/backend/RocksDBFactory.cpp @@ -80,7 +80,7 @@ public: void StartThread(void (*f)(void*), void* a) override { - ThreadParams* const p(new ThreadParams(f, a)); + auto* const p = new ThreadParams(f, a); EnvWrapper::StartThread(&RocksDBEnv::threadEntry, p); } }; diff --git a/src/libxrpl/protocol/IOUAmount.cpp b/src/libxrpl/protocol/IOUAmount.cpp index acbf6724e1..111edbf8b5 100644 --- a/src/libxrpl/protocol/IOUAmount.cpp +++ b/src/libxrpl/protocol/IOUAmount.cpp @@ -181,7 +181,7 @@ mulRatio(IOUAmount const& amt, std::uint32_t num, std::uint32_t den, bool roundU hasRem = bool(sav - low * kPowerTable[mustShrink]); } - std::int64_t mantissa = low.convert_to(); + auto mantissa = low.convert_to(); // normalize before rounding if (neg) diff --git a/src/libxrpl/protocol/MPTIssue.cpp b/src/libxrpl/protocol/MPTIssue.cpp index e9ec852d1d..35ee743b2a 100644 --- a/src/libxrpl/protocol/MPTIssue.cpp +++ b/src/libxrpl/protocol/MPTIssue.cpp @@ -31,8 +31,7 @@ MPTIssue::getIssuer() const // MPTID is concatenation of sequence + account static_assert(sizeof(MPTID) == (sizeof(std::uint32_t) + sizeof(AccountID))); // copy from id skipping the sequence - AccountID const* account = - reinterpret_cast(mptID_.data() + sizeof(std::uint32_t)); + auto const* account = reinterpret_cast(mptID_.data() + sizeof(std::uint32_t)); return *account; } diff --git a/src/libxrpl/protocol/NFTokenID.cpp b/src/libxrpl/protocol/NFTokenID.cpp index cd2c46b66b..729f052101 100644 --- a/src/libxrpl/protocol/NFTokenID.cpp +++ b/src/libxrpl/protocol/NFTokenID.cpp @@ -72,8 +72,7 @@ getNFTokenIDFromPage(TxMeta const& transactionMeta) // However, there will always be NFTs listed in the final fields, // as xrpld outputs all fields in final fields even if they were // not changed. - STObject const& previousFields = - node.peekAtField(sfPreviousFields).downcast(); + auto const& previousFields = node.peekAtField(sfPreviousFields).downcast(); if (!previousFields.isFieldPresent(sfNFTokens)) continue; diff --git a/src/libxrpl/protocol/STAmount.cpp b/src/libxrpl/protocol/STAmount.cpp index 748d00f25a..212c34322b 100644 --- a/src/libxrpl/protocol/STAmount.cpp +++ b/src/libxrpl/protocol/STAmount.cpp @@ -789,7 +789,7 @@ STAmount::add(Serializer& s) const bool STAmount::isEquivalent(STBase const& t) const { - STAmount const* v = dynamic_cast(&t); + auto const* v = dynamic_cast(&t); return (v != nullptr) && (*v == *this); } diff --git a/src/libxrpl/protocol/STBlob.cpp b/src/libxrpl/protocol/STBlob.cpp index 3f44c9b529..14d09b633c 100644 --- a/src/libxrpl/protocol/STBlob.cpp +++ b/src/libxrpl/protocol/STBlob.cpp @@ -53,7 +53,7 @@ STBlob::add(Serializer& s) const bool STBlob::isEquivalent(STBase const& t) const { - STBlob const* v = dynamic_cast(&t); + auto const* v = dynamic_cast(&t); return (v != nullptr) && (value_ == v->value_); } diff --git a/src/libxrpl/protocol/STCurrency.cpp b/src/libxrpl/protocol/STCurrency.cpp index 9b761864d9..fc8bd756ed 100644 --- a/src/libxrpl/protocol/STCurrency.cpp +++ b/src/libxrpl/protocol/STCurrency.cpp @@ -56,7 +56,7 @@ STCurrency::add(Serializer& s) const bool STCurrency::isEquivalent(STBase const& t) const { - STCurrency const* v = dynamic_cast(&t); + auto const* v = dynamic_cast(&t); return (v != nullptr) && (*v == *this); } diff --git a/src/libxrpl/protocol/STIssue.cpp b/src/libxrpl/protocol/STIssue.cpp index c9b8109e32..10403d2c50 100644 --- a/src/libxrpl/protocol/STIssue.cpp +++ b/src/libxrpl/protocol/STIssue.cpp @@ -107,7 +107,7 @@ STIssue::add(Serializer& s) const bool STIssue::isEquivalent(STBase const& t) const { - STIssue const* v = dynamic_cast(&t); + auto const* v = dynamic_cast(&t); return (v != nullptr) && (*v == *this); } diff --git a/src/libxrpl/protocol/STNumber.cpp b/src/libxrpl/protocol/STNumber.cpp index fcc0077f6b..79f7655869 100644 --- a/src/libxrpl/protocol/STNumber.cpp +++ b/src/libxrpl/protocol/STNumber.cpp @@ -142,7 +142,7 @@ STNumber::isEquivalent(STBase const& t) const { XRPL_ASSERT( t.getSType() == this->getSType(), "xrpl::STNumber::isEquivalent : field type match"); - STNumber const& v = dynamic_cast(t); + auto const& v = dynamic_cast(t); return value_ == v; } diff --git a/src/libxrpl/protocol/STObject.cpp b/src/libxrpl/protocol/STObject.cpp index c493ba65af..ea8553dc4f 100644 --- a/src/libxrpl/protocol/STObject.cpp +++ b/src/libxrpl/protocol/STObject.cpp @@ -338,7 +338,7 @@ STObject::getText() const bool STObject::isEquivalent(STBase const& t) const { - STObject const* v = dynamic_cast(&t); + auto const* v = dynamic_cast(&t); if (v == nullptr) return false; @@ -474,7 +474,7 @@ STObject::peekFieldArray(SField const& field) bool STObject::setFlag(std::uint32_t f) { - STUInt32* t = dynamic_cast(getPField(sfFlags, true)); + auto* t = dynamic_cast(getPField(sfFlags, true)); if (t == nullptr) return false; @@ -486,7 +486,7 @@ STObject::setFlag(std::uint32_t f) bool STObject::clearFlag(std::uint32_t f) { - STUInt32* t = dynamic_cast(getPField(sfFlags)); + auto* t = dynamic_cast(getPField(sfFlags)); if (t == nullptr) return false; @@ -504,7 +504,7 @@ STObject::isFlag(std::uint32_t f) const std::uint32_t STObject::getFlags(void) const { - STUInt32 const* t = dynamic_cast(peekAtPField(sfFlags)); + auto const* t = dynamic_cast(peekAtPField(sfFlags)); if (t == nullptr) return 0; @@ -651,7 +651,7 @@ Blob STObject::getFieldVL(SField const& field) const { STBlob const empty; - STBlob const& b = getFieldByConstRef(field, empty); + auto const& b = getFieldByConstRef(field, empty); return Blob(b.data(), b.data() + b.size()); } diff --git a/src/libxrpl/protocol/STPathSet.cpp b/src/libxrpl/protocol/STPathSet.cpp index cb70ac36fe..d61f17ecc6 100644 --- a/src/libxrpl/protocol/STPathSet.cpp +++ b/src/libxrpl/protocol/STPathSet.cpp @@ -127,7 +127,7 @@ STPathSet::assembleAdd(STPath const& base, STPathElement const& tail) { // assemble base+tail and add it to the set if it's not a duplicate value_.push_back(base); - std::vector::reverse_iterator it = value_.rbegin(); + auto it = value_.rbegin(); STPath& newPath = *it; newPath.pushBack(tail); @@ -146,7 +146,7 @@ STPathSet::assembleAdd(STPath const& base, STPathElement const& tail) bool STPathSet::isEquivalent(STBase const& t) const { - STPathSet const* v = dynamic_cast(&t); + auto const* v = dynamic_cast(&t); return (v != nullptr) && (value_ == v->value_); } diff --git a/src/libxrpl/protocol/STVector256.cpp b/src/libxrpl/protocol/STVector256.cpp index 7aca309667..877e34c73c 100644 --- a/src/libxrpl/protocol/STVector256.cpp +++ b/src/libxrpl/protocol/STVector256.cpp @@ -68,7 +68,7 @@ STVector256::add(Serializer& s) const bool STVector256::isEquivalent(STBase const& t) const { - STVector256 const* v = dynamic_cast(&t); + auto const* v = dynamic_cast(&t); return (v != nullptr) && (value_ == v->value_); } diff --git a/src/libxrpl/protocol/STXChainBridge.cpp b/src/libxrpl/protocol/STXChainBridge.cpp index ce6ad2368a..005c9ccbce 100644 --- a/src/libxrpl/protocol/STXChainBridge.cpp +++ b/src/libxrpl/protocol/STXChainBridge.cpp @@ -168,7 +168,7 @@ STXChainBridge::getSType() const bool STXChainBridge::isEquivalent(STBase const& t) const { - STXChainBridge const* v = dynamic_cast(&t); + auto const* v = dynamic_cast(&t); return (v != nullptr) && (*v == *this); } diff --git a/src/libxrpl/tx/transactors/escrow/EscrowCreate.cpp b/src/libxrpl/tx/transactors/escrow/EscrowCreate.cpp index 0d83885349..531098bd1c 100644 --- a/src/libxrpl/tx/transactors/escrow/EscrowCreate.cpp +++ b/src/libxrpl/tx/transactors/escrow/EscrowCreate.cpp @@ -194,7 +194,7 @@ escrowCreatePreclaimHelper( AccountID const& dest, STAmount const& amount) { - Issue const& issue = amount.get(); + auto const& issue = amount.get(); AccountID const& issuer = amount.getIssuer(); // If the issuer is the same as the account, return tecNO_PERMISSION if (issuer == account) diff --git a/src/test/app/ConfidentialTransfer_test.cpp b/src/test/app/ConfidentialTransfer_test.cpp index e6faf0a2ae..d3e0182db5 100644 --- a/src/test/app/ConfidentialTransfer_test.cpp +++ b/src/test/app/ConfidentialTransfer_test.cpp @@ -6920,7 +6920,7 @@ class ConfidentialTransfer_test : public ConfidentialTransferTestBase auto& mptAlice = confEnv.mpt; uint64_t const sendAmount = 10; - uint64_t const negativeRemaining = static_cast(-10); // 0xFFFFFFFFFFFFFFF6 + auto const negativeRemaining = static_cast(-10); // 0xFFFFFFFFFFFFFFF6 ConfidentialSendSetup const setup(mptAlice, bob, carol, alice, sendAmount); diff --git a/src/test/app/Loan_test.cpp b/src/test/app/Loan_test.cpp index 56a7cab47a..3e62af48ff 100644 --- a/src/test/app/Loan_test.cpp +++ b/src/test/app/Loan_test.cpp @@ -8651,7 +8651,7 @@ protected: Account const borrower("borrower"); // Determine all the random parameters at once - AssetType const assetType = static_cast(assetDist_(engine_)); + auto const assetType = static_cast(assetDist_(engine_)); auto const principalRequest = principalDist_(engine_); TenthBips16 const managementFeeRate{managementFeeRateDist_(engine_)}; auto const serviceFee = serviceFeeDist_(engine_); diff --git a/src/test/app/Offer_test.cpp b/src/test/app/Offer_test.cpp index 804bd9b86c..2724a6474b 100644 --- a/src/test/app/Offer_test.cpp +++ b/src/test/app/Offer_test.cpp @@ -2195,7 +2195,7 @@ public: jtx::Account const& account, jtx::PrettyAmount const& expectBalance) { - Issue const& issue = expectBalance.value().get(); + auto const& issue = expectBalance.value().get(); auto const sleTrust = env.le(keylet::trustLine(account.id(), issue)); BEAST_EXPECT(sleTrust); if (sleTrust) diff --git a/src/test/beast/LexicalCast_test.cpp b/src/test/beast/LexicalCast_test.cpp index f988aa03cf..b1d37daab8 100644 --- a/src/test/beast/LexicalCast_test.cpp +++ b/src/test/beast/LexicalCast_test.cpp @@ -24,7 +24,7 @@ public: testInteger(IntType in) { std::string s; - IntType out = static_cast(~in); // Ensure out != in + auto out = static_cast(~in); // Ensure out != in expect(lexicalCastChecked(s, in)); expect(lexicalCastChecked(out, s)); @@ -42,7 +42,7 @@ public: for (int i = 0; i < 1000; ++i) { - IntType const value(nextRandomInt(r)); + auto const value = nextRandomInt(r); testInteger(value); } } @@ -229,7 +229,7 @@ public: while (i <= std::numeric_limits::max()) { - std::int16_t const j = static_cast(i); + auto const j = static_cast(i); auto actual = std::to_string(j); diff --git a/src/test/beast/aged_associative_container_test.cpp b/src/test/beast/aged_associative_container_test.cpp index 3dbaf74040..df61824c99 100644 --- a/src/test/beast/aged_associative_container_test.cpp +++ b/src/test/beast/aged_associative_container_test.cpp @@ -1391,7 +1391,7 @@ AgedAssociativeContainerTestBase::reverseFillAgedContainer(Container& c, Values // c.clock() returns an abstract_clock, so dynamic_cast to ManualClock. // VFALCO NOTE This is sketchy using ManualClock = TestTraitsBase::ManualClock; - ManualClock& clk(dynamic_cast(c.clock())); + auto& clk = dynamic_cast(c.clock()); clk.set(0); Values rev(values); diff --git a/src/test/shamap/FetchPack_test.cpp b/src/test/shamap/FetchPack_test.cpp index b2fc185b31..bcc5129f01 100644 --- a/src/test/shamap/FetchPack_test.cpp +++ b/src/test/shamap/FetchPack_test.cpp @@ -68,7 +68,7 @@ public: [[nodiscard]] std::optional getNode(SHAMapHash const& nodeHash) const override { - Map::iterator const it = map.find(nodeHash); + auto const it = map.find(nodeHash); if (it == map.end()) { JLOG(journal.fatal()) << "Test filter missing node"; diff --git a/src/xrpld/app/consensus/RCLConsensus.cpp b/src/xrpld/app/consensus/RCLConsensus.cpp index a7c2b26c04..2abc881adc 100644 --- a/src/xrpld/app/consensus/RCLConsensus.cpp +++ b/src/xrpld/app/consensus/RCLConsensus.cpp @@ -690,7 +690,7 @@ RCLConsensus::Adaptor::doAccept( JLOG(j_.info()) << "We closed at " << closeTime.time_since_epoch().count(); using usec64_t = std::chrono::duration; - usec64_t closeTotal = std::chrono::duration_cast(closeTime.time_since_epoch()); + auto closeTotal = std::chrono::duration_cast(closeTime.time_since_epoch()); int closeCount = 1; for (auto const& [t, v] : rawCloseTimes.peers) diff --git a/src/xrpld/app/ledger/detail/InboundLedgers.cpp b/src/xrpld/app/ledger/detail/InboundLedgers.cpp index 95e3e46f73..07daa7560e 100644 --- a/src/xrpld/app/ledger/detail/InboundLedgers.cpp +++ b/src/xrpld/app/ledger/detail/InboundLedgers.cpp @@ -378,7 +378,7 @@ public: { ScopedLockType const sl(lock_); - MapType::iterator it(ledgers_.begin()); + auto it = ledgers_.begin(); total = ledgers_.size(); stuffToSweep.reserve(total); diff --git a/src/xrpld/app/main/Application.cpp b/src/xrpld/app/main/Application.cpp index 594195b93e..d329475874 100644 --- a/src/xrpld/app/main/Application.cpp +++ b/src/xrpld/app/main/Application.cpp @@ -2178,7 +2178,7 @@ fixConfigPorts(Config& config, Endpoints const& endpoints) auto const optPort = section.get(Keys::kPort); if (optPort) { - std::uint16_t const port = beast::lexicalCast(*optPort); + auto const port = beast::lexicalCast(*optPort); if (port == 0u) section.set(Keys::kPort, std::to_string(ep.port())); } diff --git a/src/xrpld/app/misc/NetworkOPs.cpp b/src/xrpld/app/misc/NetworkOPs.cpp index 82445f3625..d1f794b74d 100644 --- a/src/xrpld/app/misc/NetworkOPs.cpp +++ b/src/xrpld/app/misc/NetworkOPs.cpp @@ -4392,7 +4392,7 @@ NetworkOPsImp::findRpcSub(std::string const& strUrl) { std::scoped_lock const sl(subLock_); - subRpcMapType::iterator const it = rpcSubMap_.find(strUrl); + auto const it = rpcSubMap_.find(strUrl); if (it != rpcSubMap_.end()) return it->second; @@ -4827,7 +4827,7 @@ NetworkOPsImp::StateAccounting::json(json::Value& obj) const counters[static_cast(mode)].dur += current; obj[jss::state_accounting] = json::ValueType::Object; - for (std::size_t i = static_cast(OperatingMode::DISCONNECTED); + for (auto i = static_cast(OperatingMode::DISCONNECTED); i <= static_cast(OperatingMode::FULL); ++i) { diff --git a/src/xrpld/app/misc/detail/Transaction.cpp b/src/xrpld/app/misc/detail/Transaction.cpp index 2c55c474eb..e29181bfe9 100644 --- a/src/xrpld/app/misc/detail/Transaction.cpp +++ b/src/xrpld/app/misc/detail/Transaction.cpp @@ -103,7 +103,7 @@ Transaction::transactionFromSQL( Blob const& rawTxn, Application& app) { - std::uint32_t const inLedger = rangeCheckedCast(ledgerSeq.value_or(0)); + auto const inLedger = rangeCheckedCast(ledgerSeq.value_or(0)); SerialIter it(makeSlice(rawTxn)); auto txn = std::make_shared(it); diff --git a/src/xrpld/app/misc/detail/TxQ.cpp b/src/xrpld/app/misc/detail/TxQ.cpp index 5d1020d296..f6d00974b4 100644 --- a/src/xrpld/app/misc/detail/TxQ.cpp +++ b/src/xrpld/app/misc/detail/TxQ.cpp @@ -788,7 +788,7 @@ TxQ::apply( std::scoped_lock const lock(mutex_); // accountIter is not const because it may be updated further down. - AccountMap::iterator accountIter = byAccount_.find(account); + auto accountIter = byAccount_.find(account); bool const accountIsInQueue = accountIter != byAccount_.end(); // _If_ the account is in the queue, then ignore any sequence-based @@ -817,7 +817,7 @@ TxQ::apply( // Find the first transaction in the queue that we might apply. TxQAccount::TxMap& acctTxs = accountIter->second.transactions; - TxQAccount::TxMap::iterator const firstIter = acctTxs.lower_bound(acctSeqProx); + auto const firstIter = acctTxs.lower_bound(acctSeqProx); if (firstIter == acctTxs.end()) { @@ -996,7 +996,7 @@ TxQ::apply( // Find the entry in the queue that precedes the new // transaction, if one does. - TxQAccount::TxMap::const_iterator const prevIter = txQAcct.getPrevTx(txSeqProx); + auto const prevIter = txQAcct.getPrevTx(txSeqProx); // Does the new transaction go to the front of the queue? // This can happen if: @@ -1615,7 +1615,7 @@ TxQ::nextQueuableSeqImpl(SLE::const_ref sleAccount, std::scoped_lock // Ignore any sequence-based queued transactions that slipped into the // ledger while we were not watching. This does actually happen in the // wild, but it's uncommon. - TxQAccount::TxMap::const_iterator txIter = acctTxs.lower_bound(acctSeqProx); + auto txIter = acctTxs.lower_bound(acctSeqProx); if (txIter == acctTxs.end() || !txIter->first.isSeq() || txIter->first != acctSeqProx) { @@ -1700,7 +1700,7 @@ TxQ::tryDirectApply( // queue then remove the replaced transaction. std::scoped_lock const lock(mutex_); - AccountMap::iterator const accountIter = byAccount_.find(account); + auto const accountIter = byAccount_.find(account); if (accountIter != byAccount_.end()) { TxQAccount& txQAcct = accountIter->second; diff --git a/src/xrpld/app/rdb/backend/detail/Node.cpp b/src/xrpld/app/rdb/backend/detail/Node.cpp index 6e92a0de60..f8dc4a6981 100644 --- a/src/xrpld/app/rdb/backend/detail/Node.cpp +++ b/src/xrpld/app/rdb/backend/detail/Node.cpp @@ -1273,7 +1273,7 @@ getTransaction( if (!ledgerSeq) return std::pair{std::move(txn), nullptr}; - std::uint32_t const inLedger = rangeCheckedCast(ledgerSeq.value()); + auto const inLedger = rangeCheckedCast(ledgerSeq.value()); auto txMeta = std::make_shared(id, inLedger, rawMeta); diff --git a/src/xrpld/core/detail/Config.cpp b/src/xrpld/core/detail/Config.cpp index 523cde743a..07c780118a 100644 --- a/src/xrpld/core/detail/Config.cpp +++ b/src/xrpld/core/detail/Config.cpp @@ -926,7 +926,7 @@ Config::loadFromString(std::string const& fileContents) ", must be: [0-9]+ [minutes|hours|days|weeks]"); } - std::uint32_t const duration = beast::lexicalCastThrow(match[1].str()); + auto const duration = beast::lexicalCastThrow(match[1].str()); if (boost::iequals(match[2], "minutes")) { diff --git a/src/xrpld/rpc/CTID.h b/src/xrpld/rpc/CTID.h index c2133a19b5..7566e0e143 100644 --- a/src/xrpld/rpc/CTID.h +++ b/src/xrpld/rpc/CTID.h @@ -104,9 +104,9 @@ decodeCTID(T const ctid) noexcept if ((ctidValue & kCtidPrefixMask) != kCtidPrefix) return std::nullopt; - uint32_t const ledgerSeq = static_cast((ctidValue >> 32) & 0x0FFF'FFFF); - uint16_t const txnIndex = static_cast((ctidValue >> 16) & 0xFFFF); - uint16_t const networkID = static_cast(ctidValue & 0xFFFF); + auto const ledgerSeq = static_cast((ctidValue >> 32) & 0x0FFF'FFFF); + auto const txnIndex = static_cast((ctidValue >> 16) & 0xFFFF); + auto const networkID = static_cast(ctidValue & 0xFFFF); return std::make_tuple(ledgerSeq, txnIndex, networkID); } diff --git a/src/xrpld/rpc/handlers/orderbook/BookOffers.cpp b/src/xrpld/rpc/handlers/orderbook/BookOffers.cpp index 5d031c2c74..63dee76f1b 100644 --- a/src/xrpld/rpc/handlers/orderbook/BookOffers.cpp +++ b/src/xrpld/rpc/handlers/orderbook/BookOffers.cpp @@ -107,7 +107,7 @@ parseTakerIssuerJSON( if (taker.isMember(jss::currency)) { - Issue& issue = asset.get(); + auto& issue = asset.get(); if (taker.isMember(jss::issuer)) { From f151293e8a87d192ed1e4f3c95d9782c602a2efb Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Fri, 3 Jul 2026 12:17:03 +0100 Subject: [PATCH 08/19] chore: Enable modernize-avoid-bind (#7711) --- .clang-tidy | 1 - include/xrpl/basics/TaggedCache.ipp | 5 +- include/xrpl/beast/unit_test/thread.h | 5 +- include/xrpl/net/AutoSocket.h | 9 +- include/xrpl/net/HTTPClientSSLContext.h | 6 +- include/xrpl/server/detail/BaseHTTPPeer.h | 74 +++++--------- include/xrpl/server/detail/BasePeer.h | 3 +- include/xrpl/server/detail/BaseWSPeer.h | 66 ++++++------- include/xrpl/server/detail/Door.h | 9 +- include/xrpl/server/detail/PlainHTTPPeer.h | 10 +- include/xrpl/server/detail/SSLHTTPPeer.h | 18 ++-- src/libxrpl/basics/ResolverAsio.cpp | 34 +++---- src/libxrpl/beast/insight/StatsDCollector.cpp | 63 +++++------- src/libxrpl/core/detail/JobQueue.cpp | 3 +- src/libxrpl/net/HTTPClient.cpp | 69 +++++++------ src/test/jtx/impl/WSClient.cpp | 13 +-- src/test/overlay/short_read_test.cpp | 99 +++++++++---------- src/test/resource/Logic_test.cpp | 8 +- src/test/rpc/AccountTx_test.cpp | 3 +- src/test/rpc/LedgerRequest_test.cpp | 3 +- src/test/rpc/RPCCall_test.cpp | 3 +- src/test/rpc/TransactionEntry_test.cpp | 3 +- src/test/rpc/Transaction_test.cpp | 6 +- src/test/shamap/FetchPack_test.cpp | 96 ++++++++---------- src/xrpld/app/ledger/detail/LedgerMaster.cpp | 2 +- src/xrpld/app/misc/NetworkOPs.cpp | 2 +- src/xrpld/app/misc/SHAMapStoreImp.cpp | 8 +- src/xrpld/app/misc/detail/WorkBase.h | 38 +++---- src/xrpld/app/misc/detail/WorkFile.h | 6 +- src/xrpld/app/misc/detail/WorkSSL.cpp | 3 +- .../app/rdb/backend/detail/SQLiteDatabase.cpp | 20 ++-- src/xrpld/overlay/detail/ConnectAttempt.cpp | 20 ++-- src/xrpld/overlay/detail/OverlayImpl.cpp | 10 +- src/xrpld/overlay/detail/OverlayImpl.h | 2 +- src/xrpld/overlay/detail/PeerImp.cpp | 28 +++--- src/xrpld/peerfinder/detail/Checker.h | 3 +- src/xrpld/peerfinder/detail/Logic.h | 10 +- .../peerfinder/detail/PeerfinderManager.cpp | 3 +- src/xrpld/rpc/detail/Pathfinder.cpp | 9 +- src/xrpld/rpc/detail/RPCCall.cpp | 28 +++--- 40 files changed, 356 insertions(+), 445 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 6a24cbc8d3..c5f638b395 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -64,7 +64,6 @@ Checks: "-*, -misc-use-internal-linkage, modernize-*, - -modernize-avoid-bind, -modernize-avoid-c-arrays, -modernize-avoid-c-style-cast, -modernize-avoid-setjmp-longjmp, diff --git a/include/xrpl/basics/TaggedCache.ipp b/include/xrpl/basics/TaggedCache.ipp index ffcd533216..ca50bb64b7 100644 --- a/include/xrpl/basics/TaggedCache.ipp +++ b/include/xrpl/basics/TaggedCache.ipp @@ -57,7 +57,10 @@ inline TaggedCache< beast::insight::Collector::ptr const& collector) : journal_(journal) , clock_(clock) - , stats_(name, std::bind(&TaggedCache::collectMetrics, this), collector) + , stats_( + name, + [this] { collectMetrics(); }, + collector) , name_(name) , targetSize_(size) , targetAge_(expiration) diff --git a/include/xrpl/beast/unit_test/thread.h b/include/xrpl/beast/unit_test/thread.h index 0de039cb89..91d8cf3cab 100644 --- a/include/xrpl/beast/unit_test/thread.h +++ b/include/xrpl/beast/unit_test/thread.h @@ -45,7 +45,10 @@ public: template explicit Thread(Suite& s, F&& f, Args&&... args) : s_(&s) { - std::function b = std::bind(std::forward(f), std::forward(args)...); + std::function b = [f = std::forward(f), + ... args = std::forward(args)]() mutable { + std::invoke(f, args...); + }; t_ = std::thread(&Thread::run, this, std::move(b)); } diff --git a/include/xrpl/net/AutoSocket.h b/include/xrpl/net/AutoSocket.h index 72eaed7439..b98885959d 100644 --- a/include/xrpl/net/AutoSocket.h +++ b/include/xrpl/net/AutoSocket.h @@ -120,12 +120,9 @@ public: socket_->next_layer().async_receive( boost::asio::buffer(buffer_), boost::asio::socket_base::message_peek, - std::bind( - &AutoSocket::handleAutodetect, - this, - cbFunc, - std::placeholders::_1, - std::placeholders::_2)); + [this, cbFunc](error_code const& ec, size_t bytesTransferred) { + handleAutodetect(cbFunc, ec, bytesTransferred); + }); } } diff --git a/include/xrpl/net/HTTPClientSSLContext.h b/include/xrpl/net/HTTPClientSSLContext.h index 4192455ec9..2b26d7e404 100644 --- a/include/xrpl/net/HTTPClientSSLContext.h +++ b/include/xrpl/net/HTTPClientSSLContext.h @@ -13,7 +13,6 @@ #include #include -#include #include #include #include @@ -127,8 +126,9 @@ public: if (!ec) { strm.set_verify_callback( - std::bind( - &rfc6125Verify, host, std::placeholders::_1, std::placeholders::_2, j_), + [host, j = j_](bool preverified, boost::asio::ssl::verify_context& ctx) { + return rfc6125Verify(host, preverified, ctx, j); + }, ec); } } diff --git a/include/xrpl/server/detail/BaseHTTPPeer.h b/include/xrpl/server/detail/BaseHTTPPeer.h index f096d3c5a9..7b35dbd4be 100644 --- a/include/xrpl/server/detail/BaseHTTPPeer.h +++ b/include/xrpl/server/detail/BaseHTTPPeer.h @@ -223,10 +223,7 @@ BaseHTTPPeer::close() { if (!strand_.running_in_this_thread()) { - return post( - strand_, - std::bind( - (void (BaseHTTPPeer::*)(void))&BaseHTTPPeer::close, impl().shared_from_this())); + return post(strand_, [self = impl().shared_from_this()] { self->close(); }); } boost::beast::get_lowest_layer(impl().stream_).close(); } @@ -322,22 +319,18 @@ BaseHTTPPeer::onWrite(error_code const& ec, std::size_t bytesTran v, bind_executor( strand_, - std::bind( - &BaseHTTPPeer::onWrite, - impl().shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + [self = impl().shared_from_this()]( + error_code const& ec, std::size_t bytesTransferred) { + self->onWrite(ec, bytesTransferred); + })); } if (!complete_) return; if (graceful_) return doClose(); - util::spawn( - strand_, - std::bind( - &BaseHTTPPeer::doRead, - impl().shared_from_this(), - std::placeholders::_1)); + util::spawn(strand_, [self = impl().shared_from_this()](yield_context doYield) { + self->doRead(doYield); + }); } template @@ -351,14 +344,9 @@ BaseHTTPPeer::doWriter( { auto const p = impl().shared_from_this(); resume = std::function([this, p, writer, keepAlive]() { - util::spawn( - strand_, - std::bind( - &BaseHTTPPeer::doWriter, - p, - writer, - keepAlive, - std::placeholders::_1)); + util::spawn(strand_, [p, writer, keepAlive](yield_context doYield) { + p->doWriter(writer, keepAlive, doYield); + }); }); } @@ -379,12 +367,9 @@ BaseHTTPPeer::doWriter( if (!keepAlive) return doClose(); - util::spawn( - strand_, - std::bind( - &BaseHTTPPeer::doRead, - impl().shared_from_this(), - std::placeholders::_1)); + util::spawn(strand_, [self = impl().shared_from_this()](yield_context doYield) { + self->doRead(doYield); + }); } //------------------------------------------------------------------------------ @@ -405,8 +390,7 @@ BaseHTTPPeer::write(void const* buf, std::size_t bytes) if (!strand_.running_in_this_thread()) { return post( - strand_, - std::bind(&BaseHTTPPeer::onWrite, impl().shared_from_this(), error_code{}, 0)); + strand_, [self = impl().shared_from_this()] { self->onWrite(error_code{}, 0); }); } return onWrite(error_code{}, 0); } @@ -417,13 +401,9 @@ void BaseHTTPPeer::write(std::shared_ptr const& writer, bool keepAlive) { util::spawn( - strand_, - std::bind( - &BaseHTTPPeer::doWriter, - impl().shared_from_this(), - writer, - keepAlive, - std::placeholders::_1)); + strand_, [self = impl().shared_from_this(), writer, keepAlive](yield_context doYield) { + self->doWriter(writer, keepAlive, doYield); + }); } // DEPRECATED @@ -443,8 +423,7 @@ BaseHTTPPeer::complete() { if (!strand_.running_in_this_thread()) { - return post( - strand_, std::bind(&BaseHTTPPeer::complete, impl().shared_from_this())); + return post(strand_, [self = impl().shared_from_this()] { self->complete(); }); } message_ = {}; @@ -457,12 +436,9 @@ BaseHTTPPeer::complete() } // keep-alive - util::spawn( - strand_, - std::bind( - &BaseHTTPPeer::doRead, - impl().shared_from_this(), - std::placeholders::_1)); + util::spawn(strand_, [self = impl().shared_from_this()](yield_context doYield) { + self->doRead(doYield); + }); } // DEPRECATED @@ -474,11 +450,7 @@ BaseHTTPPeer::close(bool graceful) if (!strand_.running_in_this_thread()) { return post( - strand_, - std::bind( - (void (BaseHTTPPeer::*)(bool))&BaseHTTPPeer::close, - impl().shared_from_this(), - graceful)); + strand_, [self = impl().shared_from_this(), graceful] { self->close(graceful); }); } complete_ = true; diff --git a/include/xrpl/server/detail/BasePeer.h b/include/xrpl/server/detail/BasePeer.h index 5301a2f018..84aa1e0da9 100644 --- a/include/xrpl/server/detail/BasePeer.h +++ b/include/xrpl/server/detail/BasePeer.h @@ -10,7 +10,6 @@ #include #include -#include #include #include @@ -84,7 +83,7 @@ void BasePeer::close() { if (!strand_.running_in_this_thread()) - return post(strand_, std::bind(&BasePeer::close, impl().shared_from_this())); + return post(strand_, [self = impl().shared_from_this()] { self->close(); }); error_code ec; xrpl::getLowestLayer(impl().ws_).socket().close(ec); } diff --git a/include/xrpl/server/detail/BaseWSPeer.h b/include/xrpl/server/detail/BaseWSPeer.h index 1b6a9faca3..d557140bd4 100644 --- a/include/xrpl/server/detail/BaseWSPeer.h +++ b/include/xrpl/server/detail/BaseWSPeer.h @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -180,12 +181,13 @@ void BaseWSPeer::run() { if (!strand_.running_in_this_thread()) - return post(strand_, std::bind(&BaseWSPeer::run, impl().shared_from_this())); + return post(strand_, [self = impl().shared_from_this()] { self->run(); }); impl().ws_.set_option(port().pmdOptions); // Must manage the control callback memory outside of the `control_callback` // function - controlCallback_ = - std::bind(&BaseWSPeer::onPingPong, this, std::placeholders::_1, std::placeholders::_2); + controlCallback_ = [this]( + boost::beast::websocket::frame_type kind, + boost::beast::string_view payload) { onPingPong(kind, payload); }; impl().ws_.control_callback(controlCallback_); startTimer(); closeOnTimer_ = true; @@ -193,11 +195,9 @@ BaseWSPeer::run() res.set(boost::beast::http::field::server, BuildInfo::getFullVersionString()); })); impl().ws_.async_accept( - request_, - bind_executor( - strand_, - std::bind( - &BaseWSPeer::onWsHandshake, impl().shared_from_this(), std::placeholders::_1))); + request_, bind_executor(strand_, [self = impl().shared_from_this()](error_code const& ec) { + self->onWsHandshake(ec); + })); } template @@ -205,7 +205,10 @@ void BaseWSPeer::send(std::shared_ptr w) { if (!strand_.running_in_this_thread()) - return post(strand_, std::bind(&BaseWSPeer::send, impl().shared_from_this(), std::move(w))); + { + return post( + strand_, [self = impl().shared_from_this(), w = std::move(w)] { self->send(w); }); + } if (doClose_) return; if (wq_.size() > port().wsQueueLimit) @@ -258,7 +261,7 @@ void BaseWSPeer::complete() { if (!strand_.running_in_this_thread()) - return post(strand_, std::bind(&BaseWSPeer::complete, impl().shared_from_this())); + return post(strand_, [self = impl().shared_from_this()] { self->complete(); }); doRead(); } @@ -277,7 +280,7 @@ void BaseWSPeer::doWrite() { if (!strand_.running_in_this_thread()) - return post(strand_, std::bind(&BaseWSPeer::doWrite, impl().shared_from_this())); + return post(strand_, [self = impl().shared_from_this()] { self->doWrite(); }); onWrite({}); } @@ -288,8 +291,7 @@ BaseWSPeer::onWrite(error_code const& ec) if (ec) return fail(ec, "write"); auto& w = *wq_.front(); - auto const result = - w.prepare(65536, std::bind(&BaseWSPeer::doWrite, impl().shared_from_this())); + auto const result = w.prepare(65536, [self = impl().shared_from_this()] { self->doWrite(); }); if (boost::indeterminate(result.first)) return; startTimer(); @@ -299,8 +301,9 @@ BaseWSPeer::onWrite(error_code const& ec) static_cast(result.first), result.second, bind_executor( - strand_, - std::bind(&BaseWSPeer::onWrite, impl().shared_from_this(), std::placeholders::_1))); + strand_, [self = impl().shared_from_this()](error_code const& ec, std::size_t) { + self->onWrite(ec); + })); } else { @@ -308,9 +311,9 @@ BaseWSPeer::onWrite(error_code const& ec) static_cast(result.first), result.second, bind_executor( - strand_, - std::bind( - &BaseWSPeer::onWriteFin, impl().shared_from_this(), std::placeholders::_1))); + strand_, [self = impl().shared_from_this()](error_code const& ec, std::size_t) { + self->onWriteFin(ec); + })); } } @@ -324,10 +327,9 @@ BaseWSPeer::onWriteFin(error_code const& ec) if (doClose_) { impl().ws_.async_close( - cr_, - bind_executor( - strand_, - std::bind(&BaseWSPeer::onClose, impl().shared_from_this(), std::placeholders::_1))); + cr_, bind_executor(strand_, [self = impl().shared_from_this()](error_code const& ec) { + self->onClose(ec); + })); } else if (!wq_.empty()) { @@ -340,12 +342,13 @@ void BaseWSPeer::doRead() { if (!strand_.running_in_this_thread()) - return post(strand_, std::bind(&BaseWSPeer::doRead, impl().shared_from_this())); + return post(strand_, [self = impl().shared_from_this()] { self->doRead(); }); impl().ws_.async_read( rb_, bind_executor( - strand_, - std::bind(&BaseWSPeer::onRead, impl().shared_from_this(), std::placeholders::_1))); + strand_, [self = impl().shared_from_this()](error_code const& ec, std::size_t) { + self->onRead(ec); + })); } template @@ -389,11 +392,7 @@ BaseWSPeer::startTimer() } timer_.async_wait(bind_executor( - strand_, - std::bind( - &BaseWSPeer::onTimer, - impl().shared_from_this(), - std::placeholders::_1))); + strand_, [self = impl().shared_from_this()](error_code const& ec) { self->onTimer(ec); })); } // Convenience for discarding the error code @@ -461,10 +460,9 @@ BaseWSPeer::onTimer(error_code ec) beast::rngfill(payload_.begin(), payload_.size(), cryptoPrng()); impl().ws_.async_ping( payload_, - bind_executor( - strand_, - std::bind( - &BaseWSPeer::onPing, impl().shared_from_this(), std::placeholders::_1))); + bind_executor(strand_, [self = impl().shared_from_this()](error_code const& ec) { + self->onPing(ec); + })); JLOG(this->j_.trace()) << "sent ping"; return; } diff --git a/include/xrpl/server/detail/Door.h b/include/xrpl/server/detail/Door.h index 09b0adc5f2..d2d7a7baf4 100644 --- a/include/xrpl/server/detail/Door.h +++ b/include/xrpl/server/detail/Door.h @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -182,7 +181,7 @@ void Door::Detector::run() { util::spawn( - strand_, std::bind(&Detector::doDetect, this->shared_from_this(), std::placeholders::_1)); + strand_, [self = this->shared_from_this()](yield_context yield) { self->doDetect(yield); }); } template @@ -297,8 +296,7 @@ void Door::run() { util::spawn( - strand_, - std::bind(&Door::doAccept, this->shared_from_this(), std::placeholders::_1)); + strand_, [self = this->shared_from_this()](yield_context yield) { self->doAccept(yield); }); } template @@ -307,8 +305,7 @@ Door::close() { if (!strand_.running_in_this_thread()) { - return boost::asio::post( - strand_, std::bind(&Door::close, this->shared_from_this())); + return boost::asio::post(strand_, [self = this->shared_from_this()] { self->close(); }); } backoffTimer_.cancel(); error_code ec; diff --git a/include/xrpl/server/detail/PlainHTTPPeer.h b/include/xrpl/server/detail/PlainHTTPPeer.h index b89272fe9e..688fbbd425 100644 --- a/include/xrpl/server/detail/PlainHTTPPeer.h +++ b/include/xrpl/server/detail/PlainHTTPPeer.h @@ -9,7 +9,6 @@ #include -#include #include #include @@ -89,7 +88,9 @@ PlainHTTPPeer::run() { if (!this->handler_.onAccept(this->session(), this->remoteAddress_)) { - util::spawn(this->strand_, std::bind(&PlainHTTPPeer::doClose, this->shared_from_this())); + util::spawn(this->strand_, [self = this->shared_from_this()](boost::asio::yield_context) { + self->doClose(); + }); return; } @@ -97,8 +98,9 @@ PlainHTTPPeer::run() return; util::spawn( - this->strand_, - std::bind(&PlainHTTPPeer::doRead, this->shared_from_this(), std::placeholders::_1)); + this->strand_, [self = this->shared_from_this()](boost::asio::yield_context doYield) { + self->doRead(doYield); + }); } template diff --git a/include/xrpl/server/detail/SSLHTTPPeer.h b/include/xrpl/server/detail/SSLHTTPPeer.h index ea2108b917..7fe21ed6b5 100644 --- a/include/xrpl/server/detail/SSLHTTPPeer.h +++ b/include/xrpl/server/detail/SSLHTTPPeer.h @@ -13,7 +13,6 @@ #include #include -#include #include #include @@ -99,14 +98,15 @@ SSLHTTPPeer::run() { if (!this->handler_.onAccept(this->session(), this->remoteAddress_)) { - util::spawn(this->strand_, std::bind(&SSLHTTPPeer::doClose, this->shared_from_this())); + util::spawn( + this->strand_, [self = this->shared_from_this()](yield_context) { self->doClose(); }); return; } if (!socket_.is_open()) return; - util::spawn( - this->strand_, - std::bind(&SSLHTTPPeer::doHandshake, this->shared_from_this(), std::placeholders::_1)); + util::spawn(this->strand_, [self = this->shared_from_this()](yield_context doYield) { + self->doHandshake(doYield); + }); } template @@ -142,9 +142,9 @@ SSLHTTPPeer::doHandshake(yield_context doYield) this->port().protocol.count("https") > 0; if (http) { - util::spawn( - this->strand_, - std::bind(&SSLHTTPPeer::doRead, this->shared_from_this(), std::placeholders::_1)); + util::spawn(this->strand_, [self = this->shared_from_this()](yield_context doYield) { + self->doRead(doYield); + }); return; } // `this` will be destroyed @@ -172,7 +172,7 @@ SSLHTTPPeer::doClose() this->startTimer(); stream_.async_shutdown(bind_executor( this->strand_, - std::bind(&SSLHTTPPeer::onShutdown, this->shared_from_this(), std::placeholders::_1))); + [self = this->shared_from_this()](error_code const& ec) { self->onShutdown(ec); })); } template diff --git a/src/libxrpl/basics/ResolverAsio.cpp b/src/libxrpl/basics/ResolverAsio.cpp index ddf006b681..7e1b56f87a 100644 --- a/src/libxrpl/basics/ResolverAsio.cpp +++ b/src/libxrpl/basics/ResolverAsio.cpp @@ -192,7 +192,7 @@ public: boost::asio::dispatch( ioContext, boost::asio::bind_executor( - strand, std::bind(&ResolverAsioImpl::doStop, this, CompletionCounter(this)))); + strand, [this, counter = CompletionCounter(this)] { doStop(counter); })); JLOG(journal.debug()) << "Queued a stop request"; } @@ -221,9 +221,9 @@ public: boost::asio::dispatch( ioContext, boost::asio::bind_executor( - strand, - std::bind( - &ResolverAsioImpl::doResolve, this, names, handler, CompletionCounter(this)))); + strand, [this, names, handler, counter = CompletionCounter(this)] { + doResolve(names, handler, counter); + })); } //------------------------------------------------------------------------- @@ -272,7 +272,7 @@ public: boost::asio::post( ioContext, boost::asio::bind_executor( - strand, std::bind(&ResolverAsioImpl::doWork, this, CompletionCounter(this)))); + strand, [this, counter = CompletionCounter(this)] { doWork(counter); })); } static HostAndPort @@ -291,8 +291,10 @@ public: // a port separator // Attempt to find the first and last non-whitespace - auto const findWhitespace = - std::bind(&std::isspace, std::placeholders::_1, std::locale()); + std::locale const loc; + auto const findWhitespace = [&loc](std::string::value_type c) { + return std::isspace(c, loc); + }; auto hostFirst = std::ranges::find_if_not(str, findWhitespace); @@ -348,7 +350,7 @@ public: boost::asio::post( ioContext, boost::asio::bind_executor( - strand, std::bind(&ResolverAsioImpl::doWork, this, CompletionCounter(this)))); + strand, [this, counter = CompletionCounter(this)] { doWork(counter); })); return; } @@ -356,14 +358,11 @@ public: resolver.async_resolve( host, port, - std::bind( - &ResolverAsioImpl::doFinish, - this, - name, - std::placeholders::_1, - handler, - std::placeholders::_2, - CompletionCounter(this))); + [this, name, handler, counter = CompletionCounter(this)]( + boost::system::error_code const& ec, + boost::asio::ip::tcp::resolver::results_type results) { + doFinish(name, ec, handler, results, counter); + }); } void @@ -383,8 +382,7 @@ public: boost::asio::post( ioContext, boost::asio::bind_executor( - strand, - std::bind(&ResolverAsioImpl::doWork, this, CompletionCounter(this)))); + strand, [this, counter = CompletionCounter(this)] { doWork(counter); })); } } } diff --git a/src/libxrpl/beast/insight/StatsDCollector.cpp b/src/libxrpl/beast/insight/StatsDCollector.cpp index 1da5315de1..3cff5d93b5 100644 --- a/src/libxrpl/beast/insight/StatsDCollector.cpp +++ b/src/libxrpl/beast/insight/StatsDCollector.cpp @@ -325,9 +325,9 @@ public: postBuffer(std::string&& buffer) { boost::asio::dispatch( - ioContext_, - boost::asio::bind_executor( - strand_, std::bind(&StatsDCollectorImp::doPostBuffer, this, std::move(buffer)))); + ioContext_, boost::asio::bind_executor(strand_, [this, buffer = std::move(buffer)] { + doPostBuffer(buffer); + })); } // The keepAlive parameter makes sure the buffers sent to @@ -392,12 +392,10 @@ public: log(buffers); socket_.async_send( buffers, - std::bind( - &StatsDCollectorImp::onSend, - this, - keepAlive, - std::placeholders::_1, - std::placeholders::_2)); + [this, keepAlive]( + boost::system::error_code const& ec, std::size_t bytesTransferred) { + onSend(keepAlive, ec, bytesTransferred); + }); buffers.clear(); size = 0; } @@ -411,12 +409,10 @@ public: log(buffers); socket_.async_send( buffers, - std::bind( - &StatsDCollectorImp::onSend, - this, - keepAlive, - std::placeholders::_1, - std::placeholders::_2)); + [this, keepAlive]( + boost::system::error_code const& ec, std::size_t bytesTransferred) { + onSend(keepAlive, ec, bytesTransferred); + }); } } @@ -425,7 +421,7 @@ public: { using namespace std::chrono_literals; timer_.expires_after(1s); - timer_.async_wait(std::bind(&StatsDCollectorImp::onTimer, this, std::placeholders::_1)); + timer_.async_wait([this](boost::system::error_code const& ec) { onTimer(ec); }); } void @@ -513,10 +509,9 @@ StatsDCounterImpl::increment(CounterImpl::value_type amount) { boost::asio::dispatch( impl_->getIoContext(), - std::bind( - &StatsDCounterImpl::doIncrement, - std::static_pointer_cast(shared_from_this()), - amount)); + [self = std::static_pointer_cast(shared_from_this()), amount] { + self->doIncrement(amount); + }); } void @@ -558,10 +553,9 @@ StatsDEventImpl::notify(EventImpl::value_type const& value) { boost::asio::dispatch( impl_->getIoContext(), - std::bind( - &StatsDEventImpl::doNotify, - std::static_pointer_cast(shared_from_this()), - value)); + [self = std::static_pointer_cast(shared_from_this()), value] { + self->doNotify(value); + }); } void @@ -591,10 +585,9 @@ StatsDGaugeImpl::set(GaugeImpl::value_type value) { boost::asio::dispatch( impl_->getIoContext(), - std::bind( - &StatsDGaugeImpl::doSet, - std::static_pointer_cast(shared_from_this()), - value)); + [self = std::static_pointer_cast(shared_from_this()), value] { + self->doSet(value); + }); } void @@ -602,10 +595,9 @@ StatsDGaugeImpl::increment(GaugeImpl::difference_type amount) { boost::asio::dispatch( impl_->getIoContext(), - std::bind( - &StatsDGaugeImpl::doIncrement, - std::static_pointer_cast(shared_from_this()), - amount)); + [self = std::static_pointer_cast(shared_from_this()), amount] { + self->doIncrement(amount); + }); } void @@ -678,10 +670,9 @@ StatsDMeterImpl::increment(MeterImpl::value_type amount) { boost::asio::dispatch( impl_->getIoContext(), - std::bind( - &StatsDMeterImpl::doIncrement, - std::static_pointer_cast(shared_from_this()), - amount)); + [self = std::static_pointer_cast(shared_from_this()), amount] { + self->doIncrement(amount); + }); } void diff --git a/src/libxrpl/core/detail/JobQueue.cpp b/src/libxrpl/core/detail/JobQueue.cpp index f773270af3..8f95a8a5fa 100644 --- a/src/libxrpl/core/detail/JobQueue.cpp +++ b/src/libxrpl/core/detail/JobQueue.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include #include @@ -36,7 +35,7 @@ JobQueue::JobQueue( { JLOG(journal_.info()) << "Using " << threadCount << " threads"; - hook_ = collector_->makeHook(std::bind(&JobQueue::collect, this)); + hook_ = collector_->makeHook([this] { collect(); }); jobCount_ = collector_->makeGauge("job_count"); { diff --git a/src/libxrpl/net/HTTPClient.cpp b/src/libxrpl/net/HTTPClient.cpp index 4b9cc9d6e6..7294633964 100644 --- a/src/libxrpl/net/HTTPClient.cpp +++ b/src/libxrpl/net/HTTPClient.cpp @@ -134,12 +134,10 @@ public: request( bSSL, deqSites, - std::bind( - &HTTPClientImp::makeGet, - shared_from_this(), - strPath, - std::placeholders::_1, - std::placeholders::_2), + [self = shared_from_this(), strPath]( + boost::asio::streambuf& sb, std::string const& strHost) { + self->makeGet(strPath, sb, strHost); + }, timeout, complete); } @@ -166,9 +164,9 @@ public: shutdown_ = e.code(); JLOG(j_.trace()) << "expires_after: " << shutdown_.message(); - deadline_.async_wait( - std::bind( - &HTTPClientImp::handleDeadline, shared_from_this(), std::placeholders::_1)); + deadline_.async_wait([self = shared_from_this()](boost::system::error_code const& ec) { + self->handleDeadline(ec); + }); } if (!shutdown_) @@ -179,11 +177,11 @@ public: query_->host, query_->port, query_->flags, - std::bind( - &HTTPClientImp::handleResolve, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2)); + [self = shared_from_this()]( + boost::system::error_code const& ecResult, + boost::asio::ip::tcp::resolver::results_type results) { + self->handleResolve(ecResult, results); + }); } if (shutdown_) @@ -220,9 +218,9 @@ public: resolver_.cancel(); // Stop the transaction. - socket_.asyncShutdown( - std::bind( - &HTTPClientImp::handleShutdown, shared_from_this(), std::placeholders::_1)); + socket_.asyncShutdown([self = shared_from_this()](boost::system::error_code const& ec) { + self->handleShutdown(ec); + }); } } @@ -262,8 +260,9 @@ public: boost::asio::async_connect( socket_.lowestLayer(), result, - std::bind( - &HTTPClientImp::handleConnect, shared_from_this(), std::placeholders::_1)); + [self = shared_from_this()]( + boost::system::error_code const& ecResult, + boost::asio::ip::tcp::endpoint const&) { self->handleConnect(ecResult); }); } } @@ -301,8 +300,9 @@ public: { socket_.asyncHandshake( AutoSocket::ssl_socket::client, - std::bind( - &HTTPClientImp::handleRequest, shared_from_this(), std::placeholders::_1)); + [self = shared_from_this()](boost::system::error_code const& ec) { + self->handleRequest(ec); + }); } else { @@ -330,11 +330,10 @@ public: socket_.asyncWrite( request_, - std::bind( - &HTTPClientImp::handleWrite, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2)); + [self = shared_from_this()]( + boost::system::error_code const& ecResult, std::size_t bytesTransferred) { + self->handleWrite(ecResult, bytesTransferred); + }); } } @@ -357,11 +356,10 @@ public: socket_.asyncReadUntil( header_, "\r\n\r\n", - std::bind( - &HTTPClientImp::handleHeader, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2)); + [self = shared_from_this()]( + boost::system::error_code const& ecResult, std::size_t bytesTransferred) { + self->handleHeader(ecResult, bytesTransferred); + }); } } @@ -424,11 +422,10 @@ public: socket_.asyncRead( response_.prepare(responseSize - body_.size()), boost::asio::transfer_all(), - std::bind( - &HTTPClientImp::handleData, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2)); + [self = shared_from_this()]( + boost::system::error_code const& ecResult, std::size_t bytesTransferred) { + self->handleData(ecResult, bytesTransferred); + }); } } diff --git a/src/test/jtx/impl/WSClient.cpp b/src/test/jtx/impl/WSClient.cpp index c00a88f270..ca322415fb 100644 --- a/src/test/jtx/impl/WSClient.cpp +++ b/src/test/jtx/impl/WSClient.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -172,9 +173,9 @@ public: })); ws_.handshake(ep.address().to_string() + ":" + std::to_string(ep.port()), "/"); ws_.async_read( - rb_, - boost::asio::bind_executor( - strand_, std::bind(&WSClientImpl::onReadMsg, this, std::placeholders::_1))); + rb_, boost::asio::bind_executor(strand_, [this](error_code const& ec, std::size_t) { + onReadMsg(ec); + })); } catch (std::exception&) { @@ -310,9 +311,9 @@ private: cv_.notify_all(); } ws_.async_read( - rb_, - boost::asio::bind_executor( - strand_, std::bind(&WSClientImpl::onReadMsg, this, std::placeholders::_1))); + rb_, boost::asio::bind_executor(strand_, [this](error_code const& ec, std::size_t) { + onReadMsg(ec); + })); } // Called when the read op terminates diff --git a/src/test/overlay/short_read_test.cpp b/src/test/overlay/short_read_test.cpp index 9af632d65c..f235008d89 100644 --- a/src/test/overlay/short_read_test.cpp +++ b/src/test/overlay/short_read_test.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -199,7 +198,7 @@ private: { if (!strand.running_in_this_thread()) { - post(strand, std::bind(&Acceptor::close, shared_from_this())); + post(strand, [self = shared_from_this()] { self->close(); }); return; } acceptor.close(); @@ -210,9 +209,9 @@ private: { acceptor.async_accept( socket, - bind_executor( - strand, - std::bind(&Acceptor::onAccept, shared_from_this(), std::placeholders::_1))); + bind_executor(strand, [self = shared_from_this()](error_code const& ec) { + self->onAccept(ec); + })); } void @@ -239,9 +238,9 @@ private: p->run(); acceptor.async_accept( socket, - bind_executor( - strand, - std::bind(&Acceptor::onAccept, shared_from_this(), std::placeholders::_1))); + bind_executor(strand, [self = shared_from_this()](error_code const& ec) { + self->onAccept(ec); + })); } }; @@ -271,7 +270,7 @@ private: { if (!strand.running_in_this_thread()) { - post(strand, std::bind(&Connection::close, shared_from_this())); + post(strand, [self = shared_from_this()] { self->close(); }); return; } if (socket.is_open()) @@ -287,13 +286,12 @@ private: timer.expires_after(std::chrono::seconds(3)); timer.async_wait(bind_executor( strand, - std::bind(&Connection::onTimer, shared_from_this(), std::placeholders::_1))); + [self = shared_from_this()](error_code const& ec) { self->onTimer(ec); })); stream.async_handshake( stream_type::server, - bind_executor( - strand, - std::bind( - &Connection::onHandshake, shared_from_this(), std::placeholders::_1))); + bind_executor(strand, [self = shared_from_this()](error_code const& ec) { + self->onHandshake(ec); + })); } void @@ -337,11 +335,10 @@ private: "\n", bind_executor( strand, - std::bind( - &Connection::onRead, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + [self = shared_from_this()]( + error_code const& ec, std::size_t bytesTransferred) { + self->onRead(ec, bytesTransferred); + })); #else close(); #endif @@ -353,10 +350,10 @@ private: if (ec == boost::asio::error::eof) { server.test_.log << "[server] read: EOF" << std::endl; - stream.async_shutdown(bind_executor( - strand, - std::bind( - &Connection::onShutdown, shared_from_this(), std::placeholders::_1))); + stream.async_shutdown( + bind_executor(strand, [self = shared_from_this()](error_code const& ec) { + self->onShutdown(ec); + })); return; } if (ec) @@ -373,11 +370,10 @@ private: buf.data(), bind_executor( strand, - std::bind( - &Connection::onWrite, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + [self = shared_from_this()]( + error_code const& ec, std::size_t bytesTransferred) { + self->onWrite(ec, bytesTransferred); + })); } void @@ -391,7 +387,7 @@ private: } stream.async_shutdown(bind_executor( strand, - std::bind(&Connection::onShutdown, shared_from_this(), std::placeholders::_1))); + [self = shared_from_this()](error_code const& ec) { self->onShutdown(ec); })); } void @@ -463,7 +459,7 @@ private: { if (!strand.running_in_this_thread()) { - post(strand, std::bind(&Connection::close, shared_from_this())); + post(strand, [self = shared_from_this()] { self->close(); }); return; } if (socket.is_open()) @@ -479,13 +475,11 @@ private: timer.expires_after(std::chrono::seconds(3)); timer.async_wait(bind_executor( strand, - std::bind(&Connection::onTimer, shared_from_this(), std::placeholders::_1))); + [self = shared_from_this()](error_code const& ec) { self->onTimer(ec); })); socket.async_connect( - ep, - bind_executor( - strand, - std::bind( - &Connection::onConnect, shared_from_this(), std::placeholders::_1))); + ep, bind_executor(strand, [self = shared_from_this()](error_code const& ec) { + self->onConnect(ec); + })); } void @@ -524,10 +518,9 @@ private: } stream.async_handshake( stream_type::client, - bind_executor( - strand, - std::bind( - &Connection::onHandshake, shared_from_this(), std::placeholders::_1))); + bind_executor(strand, [self = shared_from_this()](error_code const& ec) { + self->onHandshake(ec); + })); } void @@ -546,16 +539,14 @@ private: buf.data(), bind_executor( strand, - std::bind( - &Connection::onWrite, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + [self = shared_from_this()]( + error_code const& ec, std::size_t bytesTransferred) { + self->onWrite(ec, bytesTransferred); + })); #else stream_.async_shutdown(bind_executor( strand_, - std::bind( - &Connection::on_shutdown, shared_from_this(), std::placeholders::_1))); + [self = shared_from_this()](error_code const& ec) { self->on_shutdown(ec); })); #endif } @@ -575,16 +566,14 @@ private: "\n", bind_executor( strand, - std::bind( - &Connection::onRead, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + [self = shared_from_this()]( + error_code const& ec, std::size_t bytesTransferred) { + self->onRead(ec, bytesTransferred); + })); #else stream_.async_shutdown(bind_executor( strand_, - std::bind( - &Connection::on_shutdown, shared_from_this(), std::placeholders::_1))); + [self = shared_from_this()](error_code const& ec) { self->on_shutdown(ec); })); #endif } @@ -599,7 +588,7 @@ private: buf.commit(bytesTransferred); stream.async_shutdown(bind_executor( strand, - std::bind(&Connection::onShutdown, shared_from_this(), std::placeholders::_1))); + [self = shared_from_this()](error_code const& ec) { self->onShutdown(ec); })); } void diff --git a/src/test/resource/Logic_test.cpp b/src/test/resource/Logic_test.cpp index de4575cb16..f6b4875356 100644 --- a/src/test/resource/Logic_test.cpp +++ b/src/test/resource/Logic_test.cpp @@ -89,9 +89,11 @@ public: Charge const fee(kDropThreshold + 1); beast::IP::Endpoint const addr(beast::IP::Endpoint::fromString("192.0.2.2")); - std::function const ep = limited - ? std::bind(&TestLogic::newInboundEndpoint, &logic, std::placeholders::_1) - : std::bind(&TestLogic::newUnlimitedEndpoint, &logic, std::placeholders::_1); + std::function const ep = + [&logic, limited](beast::IP::Endpoint const& address) { + return limited ? logic.newInboundEndpoint(address) + : logic.newUnlimitedEndpoint(address); + }; { Consumer c(ep(addr)); diff --git a/src/test/rpc/AccountTx_test.cpp b/src/test/rpc/AccountTx_test.cpp index bd7b07e936..ace8743e1e 100644 --- a/src/test/rpc/AccountTx_test.cpp +++ b/src/test/rpc/AccountTx_test.cpp @@ -41,7 +41,6 @@ #include #include #include -#include #include #include #include @@ -893,7 +892,7 @@ public: void run() override { - forAllApiVersions(std::bind_front(&AccountTx_test::testParameters, this)); + forAllApiVersions([this](unsigned apiVersion) { testParameters(apiVersion); }); testContents(); testAccountDelete(); testMPT(); diff --git a/src/test/rpc/LedgerRequest_test.cpp b/src/test/rpc/LedgerRequest_test.cpp index 4759256b96..93feee9497 100644 --- a/src/test/rpc/LedgerRequest_test.cpp +++ b/src/test/rpc/LedgerRequest_test.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include #include @@ -350,7 +349,7 @@ public: { testLedgerRequest(); testEvolution(); - forAllApiVersions(std::bind_front(&LedgerRequest_test::testBadInput, this)); + forAllApiVersions([this](unsigned apiVersion) { testBadInput(apiVersion); }); testMoreThan256Closed(); testNonAdmin(); } diff --git a/src/test/rpc/RPCCall_test.cpp b/src/test/rpc/RPCCall_test.cpp index cd3cd3cb41..4b5ab1f230 100644 --- a/src/test/rpc/RPCCall_test.cpp +++ b/src/test/rpc/RPCCall_test.cpp @@ -14,7 +14,6 @@ #include #include -#include #include #include #include @@ -5927,7 +5926,7 @@ public: void run() override { - forAllApiVersions(std::bind_front(&RPCCall_test::testRPCCall, this)); + forAllApiVersions([this](unsigned apiVersion) { testRPCCall(apiVersion); }); } }; diff --git a/src/test/rpc/TransactionEntry_test.cpp b/src/test/rpc/TransactionEntry_test.cpp index 8724e2974d..38a95e84f8 100644 --- a/src/test/rpc/TransactionEntry_test.cpp +++ b/src/test/rpc/TransactionEntry_test.cpp @@ -17,7 +17,6 @@ #include #include -#include #include #include #include @@ -353,7 +352,7 @@ public: run() override { testBadInput(); - forAllApiVersions(std::bind_front(&TransactionEntry_test::testRequest, this)); + forAllApiVersions([this](unsigned apiVersion) { testRequest(apiVersion); }); } }; diff --git a/src/test/rpc/Transaction_test.cpp b/src/test/rpc/Transaction_test.cpp index 8c50736b85..c3bf707ec4 100644 --- a/src/test/rpc/Transaction_test.cpp +++ b/src/test/rpc/Transaction_test.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -886,7 +885,7 @@ public: run() override { using namespace test::jtx; - forAllApiVersions(std::bind_front(&Transaction_test::testBinaryRequest, this)); + forAllApiVersions([this](unsigned apiVersion) { testBinaryRequest(apiVersion); }); FeatureBitset const all{testableAmendments()}; testWithFeats(all); @@ -899,7 +898,8 @@ public: testRangeCTIDRequest(features); testCTIDValidation(features); testRPCsForCTID(features); - forAllApiVersions(std::bind_front(&Transaction_test::testRequest, this, features)); + forAllApiVersions( + [this, features](unsigned apiVersion) { testRequest(features, apiVersion); }); } }; diff --git a/src/test/shamap/FetchPack_test.cpp b/src/test/shamap/FetchPack_test.cpp index bcc5129f01..f2e7578ee2 100644 --- a/src/test/shamap/FetchPack_test.cpp +++ b/src/test/shamap/FetchPack_test.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -26,7 +25,6 @@ #include #include #include -#include namespace xrpl::tests { @@ -40,15 +38,6 @@ public: using Table = SHAMap; using Item = SHAMapItem; - struct Handler - { - void - operator()(std::uint32_t refNum) const - { - Throw("missing node"); - } - }; - struct TestFilter : SHAMapSyncFilter { TestFilter(Map& map, beast::Journal journal) : map(map), journal(journal) @@ -93,7 +82,7 @@ public: static void addRandomItems(std::size_t n, Table& t, beast::xor_shift_engine& r) { - while ((n--) != 0u) + for (std::size_t i = 0; i < n; ++i) { auto const result(t.addItem(SHAMapNodeType::TnAccountState, makeRandomItemMember(r))); assert(result); @@ -111,56 +100,51 @@ public: void run() override { - using beast::Severity; + testFetchPack(); + } + + // Exercises a fetch-pack round trip: build a SHAMap, serialize every node + // into a pack keyed by node hash, then rebuild the map in a fresh SHAMap by + // sourcing every node from the pack through a SHAMapSyncFilter and comparing + // the result. This covers the filter-based reconstruction path (fetchRoot + + // getMissingNodes with a SHAMapSyncFilter), complementing SHAMapSync_test, + // which drives the getNodeFat/addKnownNode path. + void + testFetchPack() + { test::SuiteJournal journal("FetchPack_test", *this); + TestNodeFamily f(journal), f2(journal); + beast::xor_shift_engine r; - TestNodeFamily f(journal); - std::shared_ptr const t1(std::make_shared
(SHAMapType::FREE, f)); + // Build a source map. getHash() unshares the tree and computes every + // node hash; this must happen before serializing nodes below, otherwise + // inner nodes still carry stale cached hashes. + auto const source = std::make_shared
(SHAMapType::FREE, f); + addRandomItems(kTableItems + kTableItemsExtra, *source, r); + source->setImmutable(); + auto const rootHash = source->getHash(); - pass(); + // Turn the source into a fetch pack: node hash -> serialized node. + Map map; + source->visitNodes([this, &map](SHAMapTreeNode& node) { + Serializer s; + node.serializeWithPrefix(s); + onFetch(map, node.getHash(), s.getData()); + return true; + }); - // beast::Random r; - // add_random_items_ (tableItems, *t1, r); - // std::shared_ptr
t2 (t1->snapShot (true)); - // - // add_random_items_ (tableItemsExtra, *t1, r); - // add_random_items_ (tableItemsExtra, *t2, r); + // Rebuild the map in a fresh family, sourcing every node from the pack + // through the SHAMapSyncFilter. + auto const rebuilt = std::make_shared
(SHAMapType::FREE, rootHash.asUInt256(), f2); + TestFilter filter(map, journal); + rebuilt->setSynching(); + BEAST_EXPECT(rebuilt->fetchRoot(rootHash, &filter)); - // turn t1 into t2 - // Map map; - // t2->getFetchPack (t1.get(), true, 1000000, std::bind ( - // &FetchPack_test::on_fetch, this, std::ref (map), - // std::placeholders::_1, std::placeholders::_2)); - // t1->getFetchPack (nullptr, true, 1000000, std::bind ( - // &FetchPack_test::on_fetch, this, std::ref (map), - // std::placeholders::_1, std::placeholders::_2)); + // Everything should be in the pack, so no nodes should be missing. + BEAST_EXPECT(rebuilt->getMissingNodes(2048, &filter).empty()); + rebuilt->clearSynching(); - // try to rebuild t2 from the fetch pack - // std::shared_ptr
t3; - // try - // { - // TestFilter filter (map, beast::Journal()); - // - // t3 = std::make_shared
(SHAMapType::FREE, - // t2->getHash (), - // fullBelowCache); - // - // BEAST_EXPECT(t3->fetchRoot (t2->getHash (), &filter), - // "unable to get root"); - // - // // everything should be in the pack, no hashes should be - // needed std::vector hashes = - // t3->getNeededHashes(1, &filter); - // BEAST_EXPECT(hashes.empty(), "missing hashes"); - // - // BEAST_EXPECT(t3->getHash () == t2->getHash (), "root - // hashes do not match"); BEAST_EXPECT(t3->deepCompare - // (*t2), "failed compare"); - // } - // catch (std::exception const&) - // { - // fail ("unhandled exception"); - // } + BEAST_EXPECT(rebuilt->deepCompare(*source)); } }; diff --git a/src/xrpld/app/ledger/detail/LedgerMaster.cpp b/src/xrpld/app/ledger/detail/LedgerMaster.cpp index 3fcac03ed5..bab0dca827 100644 --- a/src/xrpld/app/ledger/detail/LedgerMaster.cpp +++ b/src/xrpld/app/ledger/detail/LedgerMaster.cpp @@ -137,7 +137,7 @@ LedgerMaster::LedgerMaster( std::chrono::seconds{45}, stopwatch, app_.getJournal("TaggedCache")) - , stats_(std::bind(&LedgerMaster::collectMetrics, this), collector) + , stats_([this] { collectMetrics(); }, collector) { } diff --git a/src/xrpld/app/misc/NetworkOPs.cpp b/src/xrpld/app/misc/NetworkOPs.cpp index d1f794b74d..4d40247a29 100644 --- a/src/xrpld/app/misc/NetworkOPs.cpp +++ b/src/xrpld/app/misc/NetworkOPs.cpp @@ -330,7 +330,7 @@ public: , jobQueue_(jobQueue) , standalone_(standalone) , minPeerCount_(startValid ? 0 : minPeerCount) - , stats_(std::bind(&NetworkOPsImp::collectMetrics, this), collector) + , stats_([this] { collectMetrics(); }, collector) { } diff --git a/src/xrpld/app/misc/SHAMapStoreImp.cpp b/src/xrpld/app/misc/SHAMapStoreImp.cpp index 0389130f7a..0e0099cdbf 100644 --- a/src/xrpld/app/misc/SHAMapStoreImp.cpp +++ b/src/xrpld/app/misc/SHAMapStoreImp.cpp @@ -331,11 +331,9 @@ SHAMapStoreImp::run() try { validatedLedger->stateMap().snapShot(false)->visitNodes( - std::bind( - &SHAMapStoreImp::copyNode, - this, - std::ref(nodeCount), - std::placeholders::_1)); + [this, &nodeCount](SHAMapTreeNode const& node) { + return copyNode(nodeCount, node); + }); } catch (SHAMapMissingNode const& e) { diff --git a/src/xrpld/app/misc/detail/WorkBase.h b/src/xrpld/app/misc/detail/WorkBase.h index 5f5fdd28b7..73e5081036 100644 --- a/src/xrpld/app/misc/detail/WorkBase.h +++ b/src/xrpld/app/misc/detail/WorkBase.h @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -138,9 +139,9 @@ WorkBase::run() if (!strand_.running_in_this_thread()) { return boost::asio::post( - ios_, - boost::asio::bind_executor( - strand_, std::bind(&WorkBase::run, impl().shared_from_this()))); + ios_, boost::asio::bind_executor(strand_, [self = impl().shared_from_this()] { + self->run(); + })); } resolver_.async_resolve( @@ -148,11 +149,9 @@ WorkBase::run() port_, boost::asio::bind_executor( strand_, - std::bind( - &WorkBase::onResolve, - impl().shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + [self = impl().shared_from_this()](error_code const& ec, results_type results) { + self->onResolve(ec, results); + })); } template @@ -165,7 +164,7 @@ WorkBase::cancel() ios_, boost::asio::bind_executor( - strand_, std::bind(&WorkBase::cancel, impl().shared_from_this()))); + strand_, [self = impl().shared_from_this()] { self->cancel(); })); } error_code ec; @@ -196,11 +195,12 @@ WorkBase::onResolve(error_code const& ec, results_type results) results, boost::asio::bind_executor( strand_, - std::bind( - &WorkBase::onConnect, - impl().shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + [self = impl().shared_from_this()]( + error_code const& ec, endpoint_type const& endpoint) { + // Call the base-class overload explicitly: the derived Impl + // hides it with its own single-argument onConnect(ec). + self->WorkBase::onConnect(ec, endpoint); + })); } template @@ -229,8 +229,9 @@ WorkBase::onStart() impl().stream(), req_, boost::asio::bind_executor( - strand_, - std::bind(&WorkBase::onRequest, impl().shared_from_this(), std::placeholders::_1))); + strand_, [self = impl().shared_from_this()](error_code const& ec, std::size_t) { + self->onRequest(ec); + })); } template @@ -245,8 +246,9 @@ WorkBase::onRequest(error_code const& ec) readBuf_, res_, boost::asio::bind_executor( - strand_, - std::bind(&WorkBase::onResponse, impl().shared_from_this(), std::placeholders::_1))); + strand_, [self = impl().shared_from_this()](error_code const& ec, std::size_t) { + self->onResponse(ec); + })); } template diff --git a/src/xrpld/app/misc/detail/WorkFile.h b/src/xrpld/app/misc/detail/WorkFile.h index 2fc7ab952d..eb42d14db4 100644 --- a/src/xrpld/app/misc/detail/WorkFile.h +++ b/src/xrpld/app/misc/detail/WorkFile.h @@ -63,9 +63,9 @@ WorkFile::run() { if (!strand_.running_in_this_thread()) { - boost::asio::post( - ios_, - boost::asio::bind_executor(strand_, std::bind(&WorkFile::run, shared_from_this()))); + boost::asio::post(ios_, boost::asio::bind_executor(strand_, [self = shared_from_this()] { + self->run(); + })); return; } diff --git a/src/xrpld/app/misc/detail/WorkSSL.cpp b/src/xrpld/app/misc/detail/WorkSSL.cpp index e1b864e81f..e8d24b55d6 100644 --- a/src/xrpld/app/misc/detail/WorkSSL.cpp +++ b/src/xrpld/app/misc/detail/WorkSSL.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include @@ -55,7 +54,7 @@ WorkSSL::onConnect(error_code const& ec) stream_.async_handshake( boost::asio::ssl::stream_base::client, boost::asio::bind_executor( - strand_, std::bind(&WorkSSL::onHandshake, shared_from_this(), std::placeholders::_1))); + strand_, [self = shared_from_this()](error_code const& ec) { self->onHandshake(ec); })); } void diff --git a/src/xrpld/app/rdb/backend/detail/SQLiteDatabase.cpp b/src/xrpld/app/rdb/backend/detail/SQLiteDatabase.cpp index fd1298516f..338a3a33df 100644 --- a/src/xrpld/app/rdb/backend/detail/SQLiteDatabase.cpp +++ b/src/xrpld/app/rdb/backend/detail/SQLiteDatabase.cpp @@ -421,8 +421,9 @@ SQLiteDatabase::oldestAccountTxPage(AccountTxPageOptions const& options) return {}; static std::uint32_t const kPageLength(200); - auto onUnsavedLedger = - std::bind(saveLedgerAsync, std::ref(registry_.get().getApp()), std::placeholders::_1); + auto onUnsavedLedger = [&app = registry_.get().getApp()](std::uint32_t seq) { + saveLedgerAsync(app, seq); + }; AccountTxs ret; auto onTransaction = [&ret, &app = registry_.get().getApp()]( std::uint32_t ledgerIndex, @@ -451,8 +452,9 @@ SQLiteDatabase::newestAccountTxPage(AccountTxPageOptions const& options) return {}; static std::uint32_t const kPageLength(200); - auto onUnsavedLedger = - std::bind(saveLedgerAsync, std::ref(registry_.get().getApp()), std::placeholders::_1); + auto onUnsavedLedger = [&app = registry_.get().getApp()](std::uint32_t seq) { + saveLedgerAsync(app, seq); + }; AccountTxs ret; auto onTransaction = [&ret, &app = registry_.get().getApp()]( std::uint32_t ledgerIndex, @@ -481,8 +483,9 @@ SQLiteDatabase::oldestAccountTxPageB(AccountTxPageOptions const& options) return {}; static std::uint32_t const kPageLength(500); - auto onUnsavedLedger = - std::bind(saveLedgerAsync, std::ref(registry_.get().getApp()), std::placeholders::_1); + auto onUnsavedLedger = [&app = registry_.get().getApp()](std::uint32_t seq) { + saveLedgerAsync(app, seq); + }; MetaTxsList ret; auto onTransaction = [&ret]( @@ -509,8 +512,9 @@ SQLiteDatabase::newestAccountTxPageB(AccountTxPageOptions const& options) return {}; static std::uint32_t const kPageLength(500); - auto onUnsavedLedger = - std::bind(saveLedgerAsync, std::ref(registry_.get().getApp()), std::placeholders::_1); + auto onUnsavedLedger = [&app = registry_.get().getApp()](std::uint32_t seq) { + saveLedgerAsync(app, seq); + }; MetaTxsList ret; auto onTransaction = [&ret]( diff --git a/src/xrpld/overlay/detail/ConnectAttempt.cpp b/src/xrpld/overlay/detail/ConnectAttempt.cpp index 295f4f5497..064b4ecd3e 100644 --- a/src/xrpld/overlay/detail/ConnectAttempt.cpp +++ b/src/xrpld/overlay/detail/ConnectAttempt.cpp @@ -35,8 +35,8 @@ #include #include +#include #include -#include #include #include #include @@ -86,7 +86,7 @@ ConnectAttempt::stop() { if (!strand_.running_in_this_thread()) { - boost::asio::post(strand_, std::bind(&ConnectAttempt::stop, shared_from_this())); + boost::asio::post(strand_, [self = shared_from_this()] { self->stop(); }); return; } if (socket_.is_open()) @@ -104,8 +104,7 @@ ConnectAttempt::run() stream_.next_layer().async_connect( remoteEndpoint_, boost::asio::bind_executor( - strand_, - std::bind(&ConnectAttempt::onConnect, shared_from_this(), std::placeholders::_1))); + strand_, [self = shared_from_this()](error_code const& ec) { self->onConnect(ec); })); } //------------------------------------------------------------------------------ @@ -160,8 +159,7 @@ ConnectAttempt::setTimer() timer_.async_wait( boost::asio::bind_executor( - strand_, - std::bind(&ConnectAttempt::onTimer, shared_from_this(), std::placeholders::_1))); + strand_, [self = shared_from_this()](error_code const& ec) { self->onTimer(ec); })); } void @@ -228,8 +226,7 @@ ConnectAttempt::onConnect(error_code ec) stream_.async_handshake( boost::asio::ssl::stream_base::client, boost::asio::bind_executor( - strand_, - std::bind(&ConnectAttempt::onHandshake, shared_from_this(), std::placeholders::_1))); + strand_, [self = shared_from_this()](error_code const& ec) { self->onHandshake(ec); })); } void @@ -290,7 +287,7 @@ ConnectAttempt::onHandshake(error_code ec) req_, boost::asio::bind_executor( strand_, - std::bind(&ConnectAttempt::onWrite, shared_from_this(), std::placeholders::_1))); + [self = shared_from_this()](error_code const& ec, std::size_t) { self->onWrite(ec); })); } void @@ -316,7 +313,7 @@ ConnectAttempt::onWrite(error_code ec) response_, boost::asio::bind_executor( strand_, - std::bind(&ConnectAttempt::onRead, shared_from_this(), std::placeholders::_1))); + [self = shared_from_this()](error_code const& ec, std::size_t) { self->onRead(ec); })); } void @@ -339,8 +336,7 @@ ConnectAttempt::onRead(error_code ec) stream_.async_shutdown( boost::asio::bind_executor( strand_, - std::bind( - &ConnectAttempt::onShutdown, shared_from_this(), std::placeholders::_1))); + [self = shared_from_this()](error_code const& ec) { self->onShutdown(ec); })); return; } diff --git a/src/xrpld/overlay/detail/OverlayImpl.cpp b/src/xrpld/overlay/detail/OverlayImpl.cpp index 89c7dfe5eb..b7af3b6ace 100644 --- a/src/xrpld/overlay/detail/OverlayImpl.cpp +++ b/src/xrpld/overlay/detail/OverlayImpl.cpp @@ -133,7 +133,7 @@ OverlayImpl::Timer::asyncWait() timer.async_wait( boost::asio::bind_executor( overlay_.strand_, - std::bind(&Timer::onTimer, shared_from_this(), std::placeholders::_1))); + [self = shared_from_this()](error_code const& ec) { self->onTimer(ec); })); } void @@ -190,7 +190,7 @@ OverlayImpl::OverlayImpl( , nextId_(1) , slots_(app, *this, app.config()) , stats_( - std::bind(&OverlayImpl::collectMetrics, this), + [this] { collectMetrics(); }, collector, [counts = traffic_.getCounts(), collector]() { std::unordered_map ret; @@ -593,7 +593,7 @@ OverlayImpl::start() void OverlayImpl::stop() { - boost::asio::dispatch(strand_, std::bind(&OverlayImpl::stopChildren, this)); + boost::asio::dispatch(strand_, [this] { stopChildren(); }); { std::unique_lock lock(mutex_); cond_.wait(lock, [this] { return list_.empty(); }); @@ -1490,7 +1490,7 @@ OverlayImpl::deletePeer(Peer::id_t id) { if (!strand_.running_in_this_thread()) { - post(strand_, std::bind(&OverlayImpl::deletePeer, this, id)); + post(strand_, [this, id] { deletePeer(id); }); return; } @@ -1502,7 +1502,7 @@ OverlayImpl::deleteIdlePeers() { if (!strand_.running_in_this_thread()) { - post(strand_, std::bind(&OverlayImpl::deleteIdlePeers, this)); + post(strand_, [this] { deleteIdlePeers(); }); return; } diff --git a/src/xrpld/overlay/detail/OverlayImpl.h b/src/xrpld/overlay/detail/OverlayImpl.h index 7db32c0d23..83d5a81a89 100644 --- a/src/xrpld/overlay/detail/OverlayImpl.h +++ b/src/xrpld/overlay/detail/OverlayImpl.h @@ -427,7 +427,7 @@ public: addTxMetrics(Args... args) { if (!strand_.running_in_this_thread()) - return post(strand_, std::bind(&OverlayImpl::addTxMetrics, this, args...)); + return post(strand_, [this, args...] { addTxMetrics(args...); }); txMetrics_.addMetrics(args...); } diff --git a/src/xrpld/overlay/detail/PeerImp.cpp b/src/xrpld/overlay/detail/PeerImp.cpp index 83e4d9c851..4e42d46f46 100644 --- a/src/xrpld/overlay/detail/PeerImp.cpp +++ b/src/xrpld/overlay/detail/PeerImp.cpp @@ -321,9 +321,9 @@ PeerImp::send(std::shared_ptr const& m) self->stream_, boost::asio::buffer(self->sendQueue_.front()->getBuffer(self->compressionEnabled_)), bind_executor( - self->strand_, - std::bind( - &PeerImp::onWriteMessage, self, std::placeholders::_1, std::placeholders::_2))); + self->strand_, [self](error_code const& ec, std::size_t bytesTransferred) { + self->onWriteMessage(ec, bytesTransferred); + })); }); } @@ -650,7 +650,7 @@ PeerImp::gracefulClose() return; setTimer(); stream_.async_shutdown(bind_executor( - strand_, std::bind(&PeerImp::onShutdown, shared_from_this(), std::placeholders::_1))); + strand_, [self = shared_from_this()](error_code const& ec) { self->onShutdown(ec); })); } void @@ -666,7 +666,7 @@ PeerImp::setTimer() return; } timer_.async_wait(bind_executor( - strand_, std::bind(&PeerImp::onTimer, shared_from_this(), std::placeholders::_1))); + strand_, [self = shared_from_this()](error_code const& ec) { self->onTimer(ec); })); } // convenience for ignoring the error code @@ -975,11 +975,9 @@ PeerImp::onReadMessage(error_code ec, std::size_t bytesTransferred) readBuffer_.prepare(std::max(Tuning::kReadBufferBytes, hint)), bind_executor( strand_, - std::bind( - &PeerImp::onReadMessage, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + [self = shared_from_this()](error_code const& ec, std::size_t bytesTransferred) { + self->onReadMessage(ec, bytesTransferred); + })); } void @@ -1014,18 +1012,16 @@ PeerImp::onWriteMessage(error_code ec, std::size_t bytesTransferred) boost::asio::buffer(sendQueue_.front()->getBuffer(compressionEnabled_)), bind_executor( strand_, - std::bind( - &PeerImp::onWriteMessage, - shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); + [self = shared_from_this()](error_code const& ec, std::size_t bytesTransferred) { + self->onWriteMessage(ec, bytesTransferred); + })); return; } if (gracefulClose_) { stream_.async_shutdown(bind_executor( - strand_, std::bind(&PeerImp::onShutdown, shared_from_this(), std::placeholders::_1))); + strand_, [self = shared_from_this()](error_code const& ec) { self->onShutdown(ec); })); return; } } diff --git a/src/xrpld/peerfinder/detail/Checker.h b/src/xrpld/peerfinder/detail/Checker.h index 20687448df..208bad390c 100644 --- a/src/xrpld/peerfinder/detail/Checker.h +++ b/src/xrpld/peerfinder/detail/Checker.h @@ -8,7 +8,6 @@ #include #include -#include #include #include @@ -183,7 +182,7 @@ Checker::asyncConnect(beast::IP::Endpoint const& endpoint, Handler&& h } op->socket.async_connect( beast::IPAddressConversion::toAsioEndpoint(endpoint), - std::bind(&BasicAsyncOp::operator(), op, std::placeholders::_1)); + [op](error_code const& ec) { (*op)(ec); }); } template diff --git a/src/xrpld/peerfinder/detail/Logic.h b/src/xrpld/peerfinder/detail/Logic.h index 7d10f7f516..8ea348f560 100644 --- a/src/xrpld/peerfinder/detail/Logic.h +++ b/src/xrpld/peerfinder/detail/Logic.h @@ -802,12 +802,10 @@ public: // checker.asyncConnect( ep.address, - std::bind( - &Logic::checkComplete, - this, - slot->remoteEndpoint(), - ep.address, - std::placeholders::_1)); + [this, remoteAddress = slot->remoteEndpoint(), checkedAddress = ep.address]( + boost::system::error_code const& ec) { + checkComplete(remoteAddress, checkedAddress, ec); + }); // Note that we simply discard the first Endpoint // that the neighbor sends when we perform the diff --git a/src/xrpld/peerfinder/detail/PeerfinderManager.cpp b/src/xrpld/peerfinder/detail/PeerfinderManager.cpp index 9dbedfe4f1..2727a03013 100644 --- a/src/xrpld/peerfinder/detail/PeerfinderManager.cpp +++ b/src/xrpld/peerfinder/detail/PeerfinderManager.cpp @@ -20,7 +20,6 @@ #include #include -#include #include #include #include @@ -61,7 +60,7 @@ public: , checker_(io_context_) , logic_(clock, store_, checker_, journal) , config_(config) - , stats_(std::bind(&ManagerImp::collectMetrics, this), collector) + , stats_([this] { collectMetrics(); }, collector) { } diff --git a/src/xrpld/rpc/detail/Pathfinder.cpp b/src/xrpld/rpc/detail/Pathfinder.cpp index fc788dea7d..5b7f1415a2 100644 --- a/src/xrpld/rpc/detail/Pathfinder.cpp +++ b/src/xrpld/rpc/detail/Pathfinder.cpp @@ -1158,11 +1158,10 @@ Pathfinder::addLink( { std::ranges::sort( candidates, - std::bind( - compareAccountCandidate, - ledger_->seq(), - std::placeholders::_1, - std::placeholders::_2)); + [seq = ledger_->seq()]( + AccountCandidate const& first, AccountCandidate const& second) { + return compareAccountCandidate(seq, first, second); + }); int count = candidates.size(); // allow more paths from source diff --git a/src/xrpld/rpc/detail/RPCCall.cpp b/src/xrpld/rpc/detail/RPCCall.cpp index 123b9fc7a5..af5677008d 100644 --- a/src/xrpld/rpc/detail/RPCCall.cpp +++ b/src/xrpld/rpc/detail/RPCCall.cpp @@ -1745,7 +1745,9 @@ rpcClient( static_cast(setup.client.secure) != 0, // Use SSL config.quiet(), logs, - std::bind(RPCCallImp::callRPCHandler, &jvOutput, std::placeholders::_1), + [&jvOutput](json::Value const& jvInput) { + RPCCallImp::callRPCHandler(&jvOutput, jvInput); + }, headers); isService.run(); // This blocks until there are no more // outstanding async calls. @@ -1870,24 +1872,16 @@ fromNetwork( ioContext, strIp, iPort, - std::bind( - &RPCCallImp::onRequest, - strMethod, - jvParams, - headers, - strPath, - std::placeholders::_1, - std::placeholders::_2, - j), + [strMethod, jvParams, headers, strPath, j]( + boost::asio::streambuf& sb, std::string const& strHost) { + RPCCallImp::onRequest(strMethod, jvParams, headers, strPath, sb, strHost, j); + }, kRpcReplyMaxBytes, kRpcWebhookTimeout, - std::bind( - &RPCCallImp::onResponse, - callbackFuncP, - std::placeholders::_1, - std::placeholders::_2, - std::placeholders::_3, - j), + [callbackFuncP, j]( + boost::system::error_code const& ecResult, int iStatus, std::string const& strData) { + return RPCCallImp::onResponse(callbackFuncP, ecResult, iStatus, strData, j); + }, j); } From 53649cc298c5a7c23aa75cb09b66b62431a28c69 Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Fri, 3 Jul 2026 15:28:15 +0100 Subject: [PATCH 09/19] chore: Enable modernize-use-constraints (#7715) --- .clang-tidy | 1 - include/xrpl/basics/Slice.h | 6 +- include/xrpl/basics/TaggedCache.h | 6 +- include/xrpl/basics/TaggedCache.ipp | 6 +- include/xrpl/basics/ToString.h | 3 +- include/xrpl/basics/base_uint.h | 26 ++- include/xrpl/basics/random.h | 29 ++- include/xrpl/basics/safe_cast.h | 18 +- include/xrpl/basics/scope.h | 25 +-- include/xrpl/basics/tagged_integer.h | 8 +- .../beast/container/aged_container_utility.h | 4 +- .../detail/aged_container_iterator.h | 16 +- .../container/detail/aged_ordered_container.h | 189 +++++++++--------- .../detail/aged_unordered_container.h | 158 ++++++++------- include/xrpl/beast/core/LexicalCast.h | 9 +- include/xrpl/beast/hash/hash_append.h | 93 +++++---- include/xrpl/beast/hash/xxhasher.h | 12 +- include/xrpl/beast/utility/rngfill.h | 7 +- include/xrpl/core/JobQueue.h | 8 +- .../xrpl/ledger/helpers/DirectoryHelpers.h | 14 +- include/xrpl/net/HTTPClientSSLContext.h | 18 +- include/xrpl/nodestore/detail/varint.h | 9 +- include/xrpl/protocol/STArray.h | 28 +-- include/xrpl/protocol/STObject.h | 16 +- include/xrpl/protocol/TER.h | 59 +++--- include/xrpl/server/Manifest.h | 5 +- src/libxrpl/protocol/STParsedJSON.cpp | 6 +- src/libxrpl/protocol/STTx.cpp | 2 +- src/libxrpl/protocol/tokens.cpp | 3 +- src/test/app/NFToken_test.cpp | 2 +- .../beast/aged_associative_container_test.cpp | 119 +++++++---- src/test/csf/Tx.h | 6 +- src/test/csf/submitters.h | 3 +- src/test/jtx/TestHelpers.h | 3 +- src/test/jtx/amount.h | 22 +- src/test/jtx/paths.h | 3 +- src/test/protocol/Quality_test.cpp | 6 +- src/test/protocol/TER_test.cpp | 9 +- src/xrpld/overlay/detail/PeerImp.h | 12 +- src/xrpld/overlay/detail/ProtocolMessage.h | 13 +- src/xrpld/rpc/Status.h | 8 +- 41 files changed, 549 insertions(+), 441 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index c5f638b395..3bad686a11 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -80,7 +80,6 @@ Checks: "-*, -modernize-return-braced-init-list, -modernize-shrink-to-fit, -modernize-use-bool-literals, - -modernize-use-constraints, -modernize-use-default-member-init, -modernize-use-integer-sign-comparison, -modernize-use-noexcept, diff --git a/include/xrpl/basics/Slice.h b/include/xrpl/basics/Slice.h index 948d012958..f87ca063b8 100644 --- a/include/xrpl/basics/Slice.h +++ b/include/xrpl/basics/Slice.h @@ -211,15 +211,17 @@ operator<<(Stream& s, Slice const& v) } template -std::enable_if_t || std::is_same_v, Slice> +Slice makeSlice(std::array const& a) + requires(std::is_same_v || std::is_same_v) { return Slice(a.data(), a.size()); } template -std::enable_if_t || std::is_same_v, Slice> +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 71ebfc57a4..16c87cf833 100644 --- a/include/xrpl/basics/TaggedCache.h +++ b/include/xrpl/basics/TaggedCache.h @@ -212,11 +212,13 @@ public: */ template auto - insert(key_type const& key, T const& value) -> std::enable_if_t; + insert(key_type const& key, T const& value) -> ReturnType + requires(!IsKeyCache); template auto - insert(key_type const& key) -> std::enable_if_t; + insert(key_type const& key) -> ReturnType + requires IsKeyCache; // 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 ca50bb64b7..b79561c71a 100644 --- a/include/xrpl/basics/TaggedCache.ipp +++ b/include/xrpl/basics/TaggedCache.ipp @@ -503,7 +503,8 @@ template < template inline auto TaggedCache:: - insert(key_type const& key, T const& value) -> std::enable_if_t + insert(key_type const& key, T const& value) -> ReturnType + requires(!IsKeyCache) { static_assert( std::is_same_v, SharedPointerType> || @@ -533,7 +534,8 @@ template < template inline auto TaggedCache:: - insert(key_type const& key) -> std::enable_if_t + insert(key_type const& key) -> ReturnType + requires IsKeyCache { 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 7764c1e3e3..e9f8f43633 100644 --- a/include/xrpl/basics/ToString.h +++ b/include/xrpl/basics/ToString.h @@ -12,8 +12,9 @@ namespace xrpl { */ template -std::enable_if_t, std::string> +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 c60fbf35b4..481a7dbd77 100644 --- a/include/xrpl/basics/base_uint.h +++ b/include/xrpl/basics/base_uint.h @@ -280,12 +280,11 @@ public: { } - template < - class Container, - class = std::enable_if_t< - detail::IsContiguousContainer::value && - std::is_trivially_copyable_v>> + template explicit BaseUInt(Container const& c) + requires( + detail::IsContiguousContainer::value && + std::is_trivially_copyable_v) { // Use AlwaysFalseT so the static_assert condition is dependent // and only triggers when this constructor template is instantiated. @@ -295,13 +294,12 @@ public: "Use base_uint::fromRaw instead."); } - template < - class Container, - class = std::enable_if_t< - detail::IsContiguousContainer::value && - std::is_trivially_copyable_v>> + template static BaseUInt fromRaw(Container const& c) + requires( + detail::IsContiguousContainer::value && + std::is_trivially_copyable_v) { BaseUInt result; XRPL_ASSERT( @@ -312,11 +310,11 @@ public: } template - std::enable_if_t< - detail::IsContiguousContainer::value && - std::is_trivially_copyable_v, - BaseUInt&> + 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/random.h b/include/xrpl/basics/random.h index cceaa6f029..c544e7d0c8 100644 --- a/include/xrpl/basics/random.h +++ b/include/xrpl/basics/random.h @@ -91,8 +91,9 @@ defaultPrng() */ /** @{ */ template -std::enable_if_t && detail::is_engine::value, Integral> +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"); @@ -103,36 +104,41 @@ randInt(Engine& engine, Integral min, Integral max) } template -std::enable_if_t, Integral> +Integral randInt(Integral min, Integral max) + requires(std::is_integral_v) { return randInt(defaultPrng(), min, max); } template -std::enable_if_t && detail::is_engine::value, Integral> +Integral randInt(Engine& engine, Integral max) + requires(std::is_integral_v && detail::is_engine::value) { return randInt(engine, Integral(0), max); } template -std::enable_if_t, Integral> +Integral randInt(Integral max) + requires(std::is_integral_v) { return randInt(defaultPrng(), max); } template -std::enable_if_t && detail::is_engine::value, Integral> +Integral randInt(Engine& engine) + requires(std::is_integral_v && detail::is_engine::value) { return randInt(engine, std::numeric_limits::max()); } template -std::enable_if_t, Integral> +Integral randInt() + requires(std::is_integral_v) { return randInt(defaultPrng(), std::numeric_limits::max()); } @@ -141,19 +147,20 @@ randInt() /** Return a random byte */ /** @{ */ template -std::enable_if_t< - (std::is_same_v || std::is_same_v) && - detail::is_engine::value, - Byte> +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 -std::enable_if_t<(std::is_same_v || std::is_same_v), Byte> +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 714146e089..483a783f5d 100644 --- a/include/xrpl/basics/safe_cast.h +++ b/include/xrpl/basics/safe_cast.h @@ -15,8 +15,9 @@ concept SafeToCast = (std::is_integral_v && std::is_integral_v) && : sizeof(Dest) >= sizeof(Src)); template -constexpr std::enable_if_t && std::is_integral_v, Dest> +constexpr 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"); @@ -28,15 +29,17 @@ safeCast(Src s) noexcept } template -constexpr std::enable_if_t && std::is_integral_v, Dest> +constexpr Dest safeCast(Src s) noexcept + requires(std::is_enum_v && std::is_integral_v) { return static_cast(safeCast>(s)); } template -constexpr std::enable_if_t && std::is_enum_v, Dest> +constexpr Dest safeCast(Src s) noexcept + requires(std::is_integral_v && std::is_enum_v) { return safeCast(static_cast>(s)); } @@ -46,8 +49,9 @@ safeCast(Src s) noexcept // underlying types become safe, it can be converted to a safe_cast. template -constexpr std::enable_if_t && std::is_integral_v, Dest> +constexpr Dest unsafeCast(Src s) noexcept + requires(std::is_integral_v && std::is_integral_v) { static_assert( !SafeToCast, @@ -57,15 +61,17 @@ unsafeCast(Src s) noexcept } template -constexpr std::enable_if_t && std::is_integral_v, Dest> +constexpr Dest unsafeCast(Src s) noexcept + requires(std::is_enum_v && std::is_integral_v) { return static_cast(unsafeCast>(s)); } template -constexpr std::enable_if_t && std::is_enum_v, Dest> +constexpr 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 cfd21e6e30..e63bb69eb5 100644 --- a/include/xrpl/basics/scope.h +++ b/include/xrpl/basics/scope.h @@ -46,11 +46,9 @@ public: operator=(ScopeExit&&) = delete; template - explicit ScopeExit( - EFP&& f, - std::enable_if_t< - !std::is_same_v, ScopeExit> && - std::is_constructible_v>* = 0) noexcept + explicit ScopeExit(EFP&& f) noexcept + requires( + !std::is_same_v, ScopeExit> && std::is_constructible_v) : exitFunction_{std::forward(f)} { static_assert(std::is_nothrow_constructible_v(f))>); @@ -93,11 +91,9 @@ public: operator=(ScopeFail&&) = delete; template - explicit ScopeFail( - EFP&& f, - std::enable_if_t< - !std::is_same_v, ScopeFail> && - std::is_constructible_v>* = 0) noexcept + explicit ScopeFail(EFP&& f) noexcept + requires( + !std::is_same_v, ScopeFail> && std::is_constructible_v) : exitFunction_{std::forward(f)} { static_assert(std::is_nothrow_constructible_v(f))>); @@ -140,12 +136,11 @@ public: operator=(ScopeSuccess&&) = delete; template - explicit ScopeSuccess( - EFP&& f, - std::enable_if_t< + explicit ScopeSuccess(EFP&& f) noexcept( + std::is_nothrow_constructible_v || std::is_nothrow_constructible_v) + requires( !std::is_same_v, ScopeSuccess> && - std::is_constructible_v>* = - 0) noexcept(std::is_nothrow_constructible_v || std::is_nothrow_constructible_v) + std::is_constructible_v) : exitFunction_{std::forward(f)} { } diff --git a/include/xrpl/basics/tagged_integer.h b/include/xrpl/basics/tagged_integer.h index 8fbd2a274b..5a088db863 100644 --- a/include/xrpl/basics/tagged_integer.h +++ b/include/xrpl/basics/tagged_integer.h @@ -43,10 +43,10 @@ public: TaggedInteger() = default; - template < - class OtherInt, - class = std::enable_if_t && sizeof(OtherInt) <= sizeof(Int)>> - explicit constexpr TaggedInteger(OtherInt value) noexcept : value_(value) + template + explicit constexpr TaggedInteger(OtherInt value) noexcept + requires(std::is_integral_v && sizeof(OtherInt) <= sizeof(Int)) + : 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 7cda863fab..f43e59b0f7 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::enable_if_t::value, std::size_t> +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 02fb3927dd..d6c061bb86 100644 --- a/include/xrpl/beast/container/detail/aged_container_iterator.h +++ b/include/xrpl/beast/container/detail/aged_container_iterator.h @@ -30,20 +30,19 @@ public: // Disable constructing a const_iterator from a non-const_iterator. // Converting between reverse and non-reverse iterators should be explicit. - template < - bool OtherIsConst, - class OtherIterator, - class = std::enable_if_t< - (!OtherIsConst || IsConst) && - !static_cast(std::is_same_v)>> + template explicit AgedContainerIterator(AgedContainerIterator const& other) + requires( + (!OtherIsConst || IsConst) && + !static_cast(std::is_same_v)) : 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_) { } @@ -52,7 +51,8 @@ public: template auto operator=(AgedContainerIterator const& other) - -> std::enable_if_t + -> AgedContainerIterator& + requires(!OtherIsConst || IsConst) { 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 0533a51f00..f739f05d2c 100644 --- a/include/xrpl/beast/container/detail/aged_ordered_container.h +++ b/include/xrpl/beast/container/detail/aged_ordered_container.h @@ -111,10 +111,9 @@ private: { } - template < - class... Args, - class = std::enable_if_t>> + template Element(time_point const& when, Args&&... args) + requires(std::is_constructible_v) : value(std::forward(args)...), when(when) { } @@ -608,35 +607,25 @@ public: // //-------------------------------------------------------------------------- - template < - class K, - bool MaybeMulti = IsMulti, - bool MaybeMap = IsMap, - class = std::enable_if_t> + template std::conditional_t& - at(K const& k); + at(K const& k) + requires(MaybeMap && !MaybeMulti); - template < - class K, - bool MaybeMulti = IsMulti, - bool MaybeMap = IsMap, - class = std::enable_if_t> + template std::conditional::type const& - at(K const& k) const; + at(K const& k) const + requires(MaybeMap && !MaybeMulti); - template < - bool MaybeMulti = IsMulti, - bool MaybeMap = IsMap, - class = std::enable_if_t> + template std::conditional_t& - operator[](Key const& key); + operator[](Key const& key) + requires(MaybeMap && !MaybeMulti); - template < - bool MaybeMulti = IsMulti, - bool MaybeMap = IsMap, - class = std::enable_if_t> + template std::conditional_t& - operator[](Key&& key); + operator[](Key&& key) + requires(MaybeMap && !MaybeMulti); //-------------------------------------------------------------------------- // @@ -770,35 +759,40 @@ public: // map, set template auto - insert(value_type const& value) -> std::enable_if_t>; + insert(value_type const& value) -> std::pair + requires(!MaybeMulti); // multimap, multiset template auto - insert(value_type const& value) -> std::enable_if_t; + insert(value_type const& value) -> iterator + requires MaybeMulti; // set template auto - insert(value_type&& value) - -> std::enable_if_t>; + insert(value_type&& value) -> std::pair + requires(!MaybeMulti && !MaybeMap); // multiset template auto - insert(value_type&& value) -> std::enable_if_t; + insert(value_type&& value) -> iterator + requires(MaybeMulti && !MaybeMap); //--- // map, set template auto - insert(const_iterator hint, value_type const& value) -> std::enable_if_t; + insert(const_iterator hint, value_type const& value) -> iterator + requires(!MaybeMulti); // multimap, multiset template - std::enable_if_t + iterator insert(const_iterator /*hint*/, value_type const& value) + requires MaybeMulti { // VFALCO TODO Figure out how to utilize 'hint' return insert(value); @@ -807,12 +801,14 @@ public: // map, set template auto - insert(const_iterator hint, value_type&& value) -> std::enable_if_t; + insert(const_iterator hint, value_type&& value) -> iterator + requires(!MaybeMulti); // multimap, multiset template - std::enable_if_t + iterator insert(const_iterator /*hint*/, value_type&& value) + requires MaybeMulti { // VFALCO TODO Figure out how to utilize 'hint' return insert(std::move(value)); @@ -820,20 +816,18 @@ public: // map, multimap template - std::enable_if_t< - MaybeMap && std::is_constructible_v, - std::conditional_t>> + std::conditional_t> insert(P&& value) + requires(MaybeMap && std::is_constructible_v) { return emplace(std::forward

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

(value)); } @@ -855,46 +849,45 @@ public: // map, set template auto - emplace(Args&&... args) -> std::enable_if_t>; + emplace(Args&&... args) -> std::pair + requires(!MaybeMulti); // multiset, multimap template auto - emplace(Args&&... args) -> std::enable_if_t; + emplace(Args&&... args) -> iterator + requires MaybeMulti; // map, set template auto - emplaceHint(const_iterator hint, Args&&... args) - -> std::enable_if_t>; + emplaceHint(const_iterator hint, Args&&... args) -> std::pair + requires(!MaybeMulti); // multiset, multimap template - std::enable_if_t + iterator emplaceHint(const_iterator /*hint*/, Args&&... args) + requires MaybeMulti { // VFALCO TODO Figure out how to utilize 'hint' return emplace(std::forward(args)...); } - // enable_if prevents erase (reverse_iterator pos) from compiling - template < - bool IsConst, - class Iterator, - class = std::enable_if_t::value>> + // The constraint prevents erase (reverse_iterator pos) from compiling + template beast::detail::AgedContainerIterator - erase(beast::detail::AgedContainerIterator pos); + erase(beast::detail::AgedContainerIterator pos) + requires(!IsBoostReverseIterator::value); - // enable_if prevents erase (reverse_iterator first, reverse_iterator last) + // The constraint prevents erase (reverse_iterator first, reverse_iterator last) // from compiling - template < - bool IsConst, - class Iterator, - class = std::enable_if_t::value>> + template beast::detail::AgedContainerIterator erase( beast::detail::AgedContainerIterator first, - beast::detail::AgedContainerIterator last); + beast::detail::AgedContainerIterator last) + requires(!IsBoostReverseIterator::value); template auto @@ -905,13 +898,11 @@ public: //-------------------------------------------------------------------------- - // enable_if prevents touch (reverse_iterator pos) from compiling - template < - bool IsConst, - class Iterator, - class = std::enable_if_t::value>> + // The constraint prevents touch (reverse_iterator pos) from compiling + template void touch(beast::detail::AgedContainerIterator pos) + requires(!IsBoostReverseIterator::value) { touch(pos, clock().now()); } @@ -1142,25 +1133,25 @@ public: } private: - // enable_if prevents erase (reverse_iterator pos, now) from compiling - template < - bool IsConst, - class Iterator, - class = std::enable_if_t::value>> + // The constraint prevents erase (reverse_iterator pos, now) from compiling + template void touch( beast::detail::AgedContainerIterator pos, - clock_type::time_point const& now); + clock_type::time_point const& now) + requires(!IsBoostReverseIterator::value); template < bool MaybePropagate = std::allocator_traits::propagate_on_container_swap::value> - std::enable_if_t - swapData(AgedOrderedContainer& other) noexcept; + void + swapData(AgedOrderedContainer& other) noexcept + requires MaybePropagate; template < bool MaybePropagate = std::allocator_traits::propagate_on_container_swap::value> - std::enable_if_t - swapData(AgedOrderedContainer& other) noexcept; + void + swapData(AgedOrderedContainer& other) noexcept + requires(!MaybePropagate); private: ConfigT config_; @@ -1369,9 +1360,10 @@ 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()) @@ -1380,9 +1372,10 @@ 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()) @@ -1391,9 +1384,10 @@ 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)); @@ -1409,9 +1403,10 @@ 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)); @@ -1445,7 +1440,8 @@ template auto AgedOrderedContainer::insert( - value_type const& value) -> std::enable_if_t> + value_type const& value) -> std::pair + requires(!MaybeMulti) { typename cont_type::insert_commit_data d; auto const result(cont_.insert_check(extract(value), std::cref(config_.keyCompare()), d)); @@ -1464,7 +1460,8 @@ template auto AgedOrderedContainer::insert( - value_type const& value) -> std::enable_if_t + value_type const& value) -> iterator + requires MaybeMulti { auto const before(cont_.upper_bound(extract(value), std::cref(config_.keyCompare()))); Element* const p(newElement(value)); @@ -1478,7 +1475,8 @@ template auto AgedOrderedContainer::insert(value_type&& value) - -> std::enable_if_t> + -> std::pair + requires(!MaybeMulti && !MaybeMap) { typename cont_type::insert_commit_data d; auto const result(cont_.insert_check(extract(value), std::cref(config_.keyCompare()), d)); @@ -1497,7 +1495,8 @@ template auto AgedOrderedContainer::insert(value_type&& value) - -> std::enable_if_t + -> iterator + requires(MaybeMulti && !MaybeMap) { auto const before(cont_.upper_bound(extract(value), std::cref(config_.keyCompare()))); Element* const p(newElement(std::move(value))); @@ -1514,7 +1513,8 @@ template auto AgedOrderedContainer::insert( const_iterator hint, - value_type const& value) -> std::enable_if_t + value_type const& value) -> iterator + requires(!MaybeMulti) { typename cont_type::insert_commit_data d; auto const result( @@ -1535,7 +1535,8 @@ template auto AgedOrderedContainer::insert( const_iterator hint, - value_type&& value) -> std::enable_if_t + value_type&& value) -> iterator + requires(!MaybeMulti) { typename cont_type::insert_commit_data d; auto const result( @@ -1555,7 +1556,8 @@ template auto AgedOrderedContainer::emplace(Args&&... args) - -> std::enable_if_t> + -> std::pair + requires(!MaybeMulti) { // VFALCO NOTE Its unfortunate that we need to // construct element here @@ -1577,7 +1579,8 @@ template auto AgedOrderedContainer::emplace(Args&&... args) - -> std::enable_if_t + -> iterator + requires MaybeMulti { Element* const p(newElement(std::forward(args)...)); auto const before(cont_.upper_bound(extract(p->value), std::cref(config_.keyCompare()))); @@ -1592,7 +1595,8 @@ template auto AgedOrderedContainer::emplaceHint( const_iterator hint, - Args&&... args) -> std::enable_if_t> + Args&&... args) -> std::pair + requires(!MaybeMulti) { // VFALCO NOTE Its unfortunate that we need to // construct element here @@ -1611,21 +1615,23 @@ 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())); @@ -1728,11 +1734,12 @@ 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; @@ -1742,9 +1749,10 @@ AgedOrderedContainer::touch( template template -std::enable_if_t +void AgedOrderedContainer::swapData( AgedOrderedContainer& other) noexcept + requires MaybePropagate { std::swap(config_.keyCompare(), other.config_.keyCompare()); std::swap(config_.alloc(), other.config_.alloc()); @@ -1753,9 +1761,10 @@ AgedOrderedContainer::swapDat template template -std::enable_if_t +void 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 782f36cd52..4c0882b04a 100644 --- a/include/xrpl/beast/container/detail/aged_unordered_container.h +++ b/include/xrpl/beast/container/detail/aged_unordered_container.h @@ -117,10 +117,9 @@ private: { } - template < - class... Args, - class = std::enable_if_t>> + template Element(time_point const& when, Args&&... args) + requires(std::is_constructible_v) : value(std::forward(args)...), when(when) { } @@ -841,35 +840,25 @@ public: // //-------------------------------------------------------------------------- - template < - class K, - bool MaybeMulti = IsMulti, - bool MaybeMap = IsMap, - class = std::enable_if_t> + template std::conditional_t& - at(K const& k); + at(K const& k) + requires(MaybeMap && !MaybeMulti); - template < - class K, - bool MaybeMulti = IsMulti, - bool MaybeMap = IsMap, - class = std::enable_if_t> + template std::conditional::type const& - at(K const& k) const; + at(K const& k) const + requires(MaybeMap && !MaybeMulti); - template < - bool MaybeMulti = IsMulti, - bool MaybeMap = IsMap, - class = std::enable_if_t> + template std::conditional_t& - operator[](Key const& key); + operator[](Key const& key) + requires(MaybeMap && !MaybeMulti); - template < - bool MaybeMulti = IsMulti, - bool MaybeMap = IsMap, - class = std::enable_if_t> + template std::conditional_t& - operator[](Key&& key); + operator[](Key&& key) + requires(MaybeMap && !MaybeMulti); //-------------------------------------------------------------------------- // @@ -967,28 +956,32 @@ public: // map, set template auto - insert(value_type const& value) -> std::enable_if_t>; + insert(value_type const& value) -> std::pair + requires(!MaybeMulti); // multimap, multiset template auto - insert(value_type const& value) -> std::enable_if_t; + insert(value_type const& value) -> iterator + requires MaybeMulti; // map, set template auto - insert(value_type&& value) - -> std::enable_if_t>; + insert(value_type&& value) -> std::pair + requires(!MaybeMulti && !MaybeMap); // multimap, multiset template auto - insert(value_type&& value) -> std::enable_if_t; + insert(value_type&& value) -> iterator + requires(MaybeMulti && !MaybeMap); // map, set template - std::enable_if_t + iterator 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. @@ -997,8 +990,9 @@ public: // multimap, multiset template - std::enable_if_t + iterator insert(const_iterator /*hint*/, value_type const& value) + requires MaybeMulti { // VFALCO TODO The hint could be used to let // the client order equal ranges @@ -1007,8 +1001,9 @@ public: // map, set template - std::enable_if_t + iterator 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. @@ -1017,8 +1012,9 @@ public: // multimap, multiset template - std::enable_if_t + iterator insert(const_iterator /*hint*/, value_type&& value) + requires MaybeMulti { // VFALCO TODO The hint could be used to let // the client order equal ranges @@ -1027,20 +1023,18 @@ public: // map, multimap template - std::enable_if_t< - MaybeMap && std::is_constructible_v, - std::conditional_t>> + std::conditional_t> insert(P&& value) + requires(MaybeMap && std::is_constructible_v) { return emplace(std::forward

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

(value)); } @@ -1061,23 +1055,26 @@ public: // set, map template auto - emplace(Args&&... args) -> std::enable_if_t>; + emplace(Args&&... args) -> std::pair + requires(!MaybeMulti); // multiset, multimap template auto - emplace(Args&&... args) -> std::enable_if_t; + emplace(Args&&... args) -> iterator + requires MaybeMulti; // set, map template auto - emplaceHint(const_iterator /*hint*/, Args&&... args) - -> std::enable_if_t>; + emplaceHint(const_iterator /*hint*/, Args&&... args) -> std::pair + requires(!MaybeMulti); // multiset, multimap template - std::enable_if_t + iterator emplaceHint(const_iterator /*hint*/, Args&&... args) + requires MaybeMulti { // VFALCO TODO The hint could be used for multi, to let // the client order equal ranges @@ -1308,7 +1305,7 @@ public: class OtherHash, class OtherAllocator, bool MaybeMulti = IsMulti> - std::enable_if_t + bool operator==(AgedUnorderedContainer< false, OtherIsMap, @@ -1317,7 +1314,8 @@ public: OtherDuration, OtherHash, KeyEqual, - OtherAllocator> const& other) const; + OtherAllocator> const& other) const + requires(!MaybeMulti); template < bool OtherIsMap, @@ -1327,7 +1325,7 @@ public: class OtherHash, class OtherAllocator, bool MaybeMulti = IsMulti> - std::enable_if_t + bool operator==(AgedUnorderedContainer< true, OtherIsMap, @@ -1336,7 +1334,8 @@ public: OtherDuration, OtherHash, KeyEqual, - OtherAllocator> const& other) const; + OtherAllocator> const& other) const + requires MaybeMulti; template < bool OtherIsMulti, @@ -1381,13 +1380,14 @@ private: // map, set template auto - insertUnchecked(value_type const& value) - -> std::enable_if_t>; + insertUnchecked(value_type const& value) -> std::pair + requires(!MaybeMulti); // multimap, multiset template auto - insertUnchecked(value_type const& value) -> std::enable_if_t; + insertUnchecked(value_type const& value) -> iterator + requires MaybeMulti; template void @@ -1428,8 +1428,9 @@ private: template < bool MaybePropagate = std::allocator_traits::propagate_on_container_swap::value> - std::enable_if_t + void swapData(AgedUnorderedContainer& other) noexcept + requires MaybePropagate { std::swap(config_.hashFunction(), other.config_.hashFunction()); std::swap(config_.keyEq(), other.config_.keyEq()); @@ -1439,8 +1440,9 @@ private: template < bool MaybePropagate = std::allocator_traits::propagate_on_container_swap::value> - std::enable_if_t + void swapData(AgedUnorderedContainer& other) noexcept + requires(!MaybePropagate) { std::swap(config_.hashFunction(), other.config_.hashFunction()); std::swap(config_.keyEq(), other.config_.keyEq()); @@ -2094,9 +2096,10 @@ 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()))); @@ -2114,10 +2117,11 @@ 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()))); @@ -2135,10 +2139,11 @@ 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; @@ -2164,10 +2169,11 @@ 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; @@ -2220,7 +2226,8 @@ template < template auto AgedUnorderedContainer::insert( - value_type const& value) -> std::enable_if_t> + value_type const& value) -> std::pair + requires(!MaybeMulti) { maybeRehash(1); typename cont_type::insert_commit_data d; @@ -2249,7 +2256,8 @@ template < template auto AgedUnorderedContainer::insert( - value_type const& value) -> std::enable_if_t + value_type const& value) -> iterator + requires MaybeMulti { maybeRehash(1); Element* const p(newElement(value)); @@ -2271,7 +2279,8 @@ template < template auto AgedUnorderedContainer::insert( - value_type&& value) -> std::enable_if_t> + value_type&& value) -> std::pair + requires(!MaybeMulti && !MaybeMap) { maybeRehash(1); typename cont_type::insert_commit_data d; @@ -2300,7 +2309,8 @@ template < template auto AgedUnorderedContainer::insert( - value_type&& value) -> std::enable_if_t + value_type&& value) -> iterator + requires(MaybeMulti && !MaybeMap) { maybeRehash(1); Element* const p(newElement(std::move(value))); @@ -2323,7 +2333,8 @@ template < template auto AgedUnorderedContainer::emplace( - Args&&... args) -> std::enable_if_t> + Args&&... args) -> std::pair + requires(!MaybeMulti) { maybeRehash(1); // VFALCO NOTE Its unfortunate that we need to @@ -2352,7 +2363,8 @@ template < template auto AgedUnorderedContainer::emplace( - Args&&... args) -> typename std::enable_if>::type + Args&&... args) -> std::pair + requires(!maybe_multi) { maybe_rehash(1); // VFALCO NOTE Its unfortunate that we need to @@ -2388,7 +2400,8 @@ template < template auto AgedUnorderedContainer::emplace( - Args&&... args) -> std::enable_if_t + Args&&... args) -> iterator + requires MaybeMulti { maybeRehash(1); Element* const p(newElement(std::forward(args)...)); @@ -2411,7 +2424,8 @@ template auto AgedUnorderedContainer::emplaceHint( const_iterator /*hint*/, - Args&&... args) -> std::enable_if_t> + Args&&... args) -> std::pair + requires(!MaybeMulti) { maybeRehash(1); // VFALCO NOTE Its unfortunate that we need to @@ -2562,7 +2576,7 @@ template < class OtherHash, class OtherAllocator, bool MaybeMulti> -std::enable_if_t +bool AgedUnorderedContainer::operator==( AgedUnorderedContainer< false, @@ -2573,6 +2587,7 @@ AgedUnorderedContainer OtherHash, KeyEqual, OtherAllocator> const& other) const + requires(!MaybeMulti) { if (size() != other.size()) return false; @@ -2602,7 +2617,7 @@ template < class OtherHash, class OtherAllocator, bool MaybeMulti> -std::enable_if_t +bool AgedUnorderedContainer::operator==( AgedUnorderedContainer< true, @@ -2613,6 +2628,7 @@ AgedUnorderedContainer OtherHash, KeyEqual, OtherAllocator> const& other) const + requires MaybeMulti { if (size() != other.size()) return false; @@ -2649,7 +2665,8 @@ template < template auto AgedUnorderedContainer::insertUnchecked( - value_type const& value) -> std::enable_if_t> + value_type const& value) -> std::pair + requires(!MaybeMulti) { typename cont_type::insert_commit_data d; auto const result(cont_.insert_check( @@ -2677,7 +2694,8 @@ template < template auto AgedUnorderedContainer::insertUnchecked( - value_type const& value) -> std::enable_if_t + value_type const& value) -> iterator + requires MaybeMulti { 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 8faf90f53d..1162d83078 100644 --- a/include/xrpl/beast/core/LexicalCast.h +++ b/include/xrpl/beast/core/LexicalCast.h @@ -29,16 +29,18 @@ struct LexicalCast explicit LexicalCast() = default; template - std::enable_if_t, bool> + bool operator()(std::string& out, Arithmetic in) + requires(std::is_arithmetic_v) { out = std::to_string(in); return true; } template - std::enable_if_t, bool> + bool operator()(std::string& out, Enumeration in) + requires(std::is_enum_v) { out = std::to_string(static_cast>(in)); return true; @@ -56,8 +58,9 @@ struct LexicalCast "beast::LexicalCast can only be used with integral types"); template - std::enable_if_t && !std::is_same_v, bool> + 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/hash/hash_append.h b/include/xrpl/beast/hash/hash_append.h index 5f77f41e5d..da499dc612 100644 --- a/include/xrpl/beast/hash/hash_append.h +++ b/include/xrpl/beast/hash/hash_append.h @@ -200,26 +200,29 @@ struct IsContiguouslyHashable // scalars template -inline std::enable_if_t::value> +inline void 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 std::enable_if_t< - !IsContiguouslyHashable::value && - (std::is_integral_v || std::is_pointer_v || std::is_enum_v)> +inline void 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 std::enable_if_t> +inline void hash_append(Hasher& h, T t) noexcept + requires(std::is_floating_point_v) { if (t == 0) t = 0; @@ -239,36 +242,44 @@ hash_append(Hasher& h, std::nullptr_t) noexcept // Forward declarations for ADL purposes template -std::enable_if_t::value> -hash_append(Hasher& h, T (&a)[N]) noexcept; +void +hash_append(Hasher& h, T (&a)[N]) noexcept + requires(!IsContiguouslyHashable::value); template -std::enable_if_t::value> -hash_append(Hasher& h, std::basic_string const& s) noexcept; +void +hash_append(Hasher& h, std::basic_string const& s) noexcept + requires(!IsContiguouslyHashable::value); template -std::enable_if_t::value> -hash_append(Hasher& h, std::basic_string const& s) noexcept; +void +hash_append(Hasher& h, std::basic_string const& s) noexcept + requires(IsContiguouslyHashable::value); template -std::enable_if_t, Hasher>::value> -hash_append(Hasher& h, std::pair const& p) noexcept; +void +hash_append(Hasher& h, std::pair const& p) noexcept + requires(!IsContiguouslyHashable, Hasher>::value); template -std::enable_if_t::value> -hash_append(Hasher& h, std::vector const& v) noexcept; +void +hash_append(Hasher& h, std::vector const& v) noexcept + requires(!IsContiguouslyHashable::value); template -std::enable_if_t::value> -hash_append(Hasher& h, std::vector const& v) noexcept; +void +hash_append(Hasher& h, std::vector const& v) noexcept + requires(IsContiguouslyHashable::value); template -std::enable_if_t, Hasher>::value> -hash_append(Hasher& h, std::array const& a) noexcept; +void +hash_append(Hasher& h, std::array const& a) noexcept + requires(!IsContiguouslyHashable, Hasher>::value); template -std::enable_if_t, Hasher>::value> -hash_append(Hasher& h, std::tuple const& t) noexcept; +void +hash_append(Hasher& h, std::tuple const& t) noexcept + requires(!IsContiguouslyHashable, Hasher>::value); template void @@ -279,11 +290,13 @@ void hash_append(Hasher& h, std::unordered_set const& s); template -std::enable_if_t::value> -hash_append(Hasher& h, boost::container::flat_set const& v) noexcept; +void +hash_append(Hasher& h, boost::container::flat_set const& v) noexcept + requires(!IsContiguouslyHashable::value); template -std::enable_if_t::value> -hash_append(Hasher& h, boost::container::flat_set const& v) noexcept; +void +hash_append(Hasher& h, boost::container::flat_set const& v) noexcept + requires(IsContiguouslyHashable::value); template void hash_append(Hasher& h, T0 const& t0, T1 const& t1, T const&... t) noexcept; @@ -291,8 +304,9 @@ hash_append(Hasher& h, T0 const& t0, T1 const& t1, T const&... t) noexcept; // c-array template -std::enable_if_t::value> +void hash_append(Hasher& h, T (&a)[N]) noexcept + requires(!IsContiguouslyHashable::value) { for (auto const& t : a) hash_append(h, t); @@ -301,8 +315,9 @@ hash_append(Hasher& h, T (&a)[N]) noexcept // basic_string template -inline std::enable_if_t::value> +inline void hash_append(Hasher& h, std::basic_string const& s) noexcept + requires(!IsContiguouslyHashable::value) { for (auto c : s) hash_append(h, c); @@ -310,8 +325,9 @@ hash_append(Hasher& h, std::basic_string const& s) noexcep } template -inline std::enable_if_t::value> +inline void 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()); @@ -320,8 +336,9 @@ hash_append(Hasher& h, std::basic_string const& s) noexcep // pair template -inline std::enable_if_t, Hasher>::value> +inline void hash_append(Hasher& h, std::pair const& p) noexcept + requires(!IsContiguouslyHashable, Hasher>::value) { hash_append(h, p.first, p.second); } @@ -329,8 +346,9 @@ hash_append(Hasher& h, std::pair const& p) noexcept // vector template -inline std::enable_if_t::value> +inline void hash_append(Hasher& h, std::vector const& v) noexcept + requires(!IsContiguouslyHashable::value) { for (auto const& t : v) hash_append(h, t); @@ -338,8 +356,9 @@ hash_append(Hasher& h, std::vector const& v) noexcept } template -inline std::enable_if_t::value> +inline void hash_append(Hasher& h, std::vector const& v) noexcept + requires(IsContiguouslyHashable::value) { h(v.data(), v.size() * sizeof(T)); hash_append(h, v.size()); @@ -348,23 +367,26 @@ hash_append(Hasher& h, std::vector const& v) noexcept // array template -std::enable_if_t, Hasher>::value> +void hash_append(Hasher& h, std::array const& a) noexcept + requires(!IsContiguouslyHashable, Hasher>::value) { for (auto const& t : a) hash_append(h, t); } template -std::enable_if_t::value> +void hash_append(Hasher& h, boost::container::flat_set const& v) noexcept + requires(!IsContiguouslyHashable::value) { for (auto const& t : v) hash_append(h, t); } template -std::enable_if_t::value> +void hash_append(Hasher& h, boost::container::flat_set const& v) noexcept + requires(IsContiguouslyHashable::value) { h(&(v.begin()), v.size() * sizeof(Key)); } @@ -395,8 +417,9 @@ tuple_hash(Hasher& h, std::tuple const& t, std::index_sequence) noex } // namespace detail template -inline std::enable_if_t, Hasher>::value> +inline void hash_append(Hasher& h, std::tuple const& t) noexcept + requires(!IsContiguouslyHashable, Hasher>::value) { detail::tuple_hash(h, t, std::index_sequence_for{}); } diff --git a/include/xrpl/beast/hash/xxhasher.h b/include/xrpl/beast/hash/xxhasher.h index 978bbc6917..73dbb8e8ab 100644 --- a/include/xrpl/beast/hash/xxhasher.h +++ b/include/xrpl/beast/hash/xxhasher.h @@ -124,14 +124,18 @@ public: } } - template >* = nullptr> - explicit Xxhasher(Seed seed) : seed_(seed) + template + explicit Xxhasher(Seed seed) + requires(std::is_unsigned_v) + : seed_(seed) { resetBuffers(); } - template >* = nullptr> - Xxhasher(Seed seed, Seed) : seed_(seed) + template + Xxhasher(Seed seed, Seed) + requires(std::is_unsigned_v) + : seed_(seed) { resetBuffers(); } diff --git a/include/xrpl/beast/utility/rngfill.h b/include/xrpl/beast/utility/rngfill.h index ee7a5e2434..5bd9d8bc5c 100644 --- a/include/xrpl/beast/utility/rngfill.h +++ b/include/xrpl/beast/utility/rngfill.h @@ -3,7 +3,6 @@ #include #include #include -#include namespace beast { @@ -33,12 +32,10 @@ rngfill(void* const buffer, std::size_t const bytes, Generator& g) } } -template < - class Generator, - std::size_t N, - class = std::enable_if_t> +template 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); diff --git a/include/xrpl/core/JobQueue.h b/include/xrpl/core/JobQueue.h index 14170a39be..e4b64546f3 100644 --- a/include/xrpl/core/JobQueue.h +++ b/include/xrpl/core/JobQueue.h @@ -154,16 +154,14 @@ public: @param type The type of job. @param name Name of the job. - @param jobHandler Lambda with signature void (Job&). Called when the - job is executed. + @param jobHandler Callable with signature void(). Called when the job is executed. @return true if jobHandler added to queue. */ - template < - typename JobHandler, - typename = std::enable_if_t()()), void>>> + template 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/ledger/helpers/DirectoryHelpers.h b/include/xrpl/ledger/helpers/DirectoryHelpers.h index 76a5f3bdad..a95b9bc95a 100644 --- a/include/xrpl/ledger/helpers/DirectoryHelpers.h +++ b/include/xrpl/ledger/helpers/DirectoryHelpers.h @@ -19,11 +19,7 @@ namespace xrpl { namespace detail { -template < - class V, - class N, - class = std::enable_if_t< - std::is_same_v, SLE> && std::is_base_of_v>> +template bool internalDirNext( V& view, @@ -31,6 +27,7 @@ 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"); @@ -68,11 +65,7 @@ internalDirNext( return true; } -template < - class V, - class N, - class = std::enable_if_t< - std::is_same_v, SLE> && std::is_base_of_v>> +template bool internalDirFirst( V& view, @@ -80,6 +73,7 @@ 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/net/HTTPClientSSLContext.h b/include/xrpl/net/HTTPClientSSLContext.h index 2b26d7e404..51b50a084c 100644 --- a/include/xrpl/net/HTTPClientSSLContext.h +++ b/include/xrpl/net/HTTPClientSSLContext.h @@ -83,13 +83,12 @@ public: * * @return error_code indicating failures, if any */ - template < - class T, - class = std::enable_if_t< - std::is_same_v> || - std::is_same_v>>> + template 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())) @@ -103,11 +102,7 @@ public: return ec; } - template < - class T, - class = std::enable_if_t< - std::is_same_v> || - std::is_same_v>>> + template /** * @brief invoked after connect/async_connect but before sending data * on an ssl stream - to setup name verification. @@ -117,6 +112,9 @@ 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; diff --git a/include/xrpl/nodestore/detail/varint.h b/include/xrpl/nodestore/detail/varint.h index 6102c0cf2d..5a65545d3a 100644 --- a/include/xrpl/nodestore/detail/varint.h +++ b/include/xrpl/nodestore/detail/varint.h @@ -68,9 +68,10 @@ readVarint(void const* buf, std::size_t buflen, std::size_t& t) return used; } -template >* = nullptr> +template std::size_t sizeVarint(T v) + requires(std::is_unsigned_v) { std::size_t n = 0; do @@ -100,9 +101,10 @@ writeVarint(void* p0, std::size_t v) // input stream -template >* = nullptr> +template void read(nudb::detail::istream& is, std::size_t& u) + requires(std::is_same_v) { auto p0 = is(1); auto p1 = p0; @@ -113,9 +115,10 @@ read(nudb::detail::istream& is, std::size_t& u) // output stream -template >* = nullptr> +template 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/STArray.h b/include/xrpl/protocol/STArray.h index ed39e65026..573bb6dad8 100644 --- a/include/xrpl/protocol/STArray.h +++ b/include/xrpl/protocol/STArray.h @@ -32,17 +32,13 @@ public: STArray() = default; STArray(STArray const&) = default; - template < - class Iter, - class = std::enable_if_t< - std::is_convertible_v::reference, STObject>>> - explicit STArray(Iter first, Iter last); + 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>>> - STArray(SField const& f, Iter first, Iter last); + template + STArray(SField const& f, Iter first, Iter last) + requires(std::is_convertible_v::reference, STObject>); STArray& operator=(STArray const&) = default; @@ -170,13 +166,17 @@ private: friend class detail::STVar; }; -template -STArray::STArray(Iter first, Iter last) : v_(first, last) +template +STArray::STArray(Iter first, Iter last) + requires(std::is_convertible_v::reference, STObject>) + : v_(first, last) { } -template -STArray::STArray(SField const& f, Iter first, Iter last) : STBase(f), 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) { } diff --git a/include/xrpl/protocol/STObject.h b/include/xrpl/protocol/STObject.h index a60e8f7fe8..c96086b1d0 100644 --- a/include/xrpl/protocol/STObject.h +++ b/include/xrpl/protocol/STObject.h @@ -556,8 +556,9 @@ public: operator=(ValueProxy const&) = delete; template - std::enable_if_t, ValueProxy&> - operator=(U&& u); + ValueProxy& + operator=(U&& u) + requires(std::is_assignable_v); // Convenience operators for value types supporting // arithmetic operations @@ -691,8 +692,9 @@ public: operator=(optional_type const& v); template - std::enable_if_t, OptionalProxy&> - operator=(U&& u); + OptionalProxy& + operator=(U&& u) + requires(std::is_assignable_v); private: friend class STObject; @@ -798,8 +800,9 @@ STObject::Proxy::assign(U&& u) template template -std::enable_if_t, STObject::ValueProxy&> +STObject::ValueProxy& STObject::ValueProxy::operator=(U&& u) + requires(std::is_assignable_v) { this->assign(std::forward(u)); return *this; @@ -902,8 +905,9 @@ STObject::OptionalProxy::operator=(optional_type const& v) -> OptionalProxy& template template -std::enable_if_t, STObject::OptionalProxy&> +STObject::OptionalProxy& STObject::OptionalProxy::operator=(U&& u) + requires(std::is_assignable_v) { this->assign(std::forward(u)); return *this; diff --git a/include/xrpl/protocol/TER.h b/include/xrpl/protocol/TER.h index b29cb11e15..54b081f358 100644 --- a/include/xrpl/protocol/TER.h +++ b/include/xrpl/protocol/TER.h @@ -411,7 +411,7 @@ TERtoInt(TECcodes v) //------------------------------------------------------------------------------ // Template class that is specific to selected ranges of error codes. The -// Trait tells std::enable_if which ranges are allowed. +// Trait tells the requires-clause which ranges are allowed. template