From f151293e8a87d192ed1e4f3c95d9782c602a2efb Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Fri, 3 Jul 2026 12:17:03 +0100 Subject: [PATCH 1/8] 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 2/8] 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