Skip to content

Commit

Permalink
Add explicit this to lambda
Browse files Browse the repository at this point in the history
Implicit capture of `this` via `[=]` is deprecated in C++20 [-Wdeprecated]
  • Loading branch information
Chocobo1 committed Aug 24, 2023
1 parent 4257b65 commit d4b45e1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ namespace libtorrent {
address const ip = make_address(host, ec);
if (!ec)
{
#if __cplusplus >= 202002L
m_ios.post([=, this]{ callback(h, ec, std::vector<address>{ip}); });
#else
m_ios.post([=]{ callback(h, ec, std::vector<address>{ip}); });
#endif
return;
}
ec.clear();
Expand All @@ -124,15 +128,23 @@ namespace libtorrent {
|| i->second.last_seen + m_timeout >= aux::time_now())
{
std::vector<address> ips = i->second.addresses;
#if __cplusplus >= 202002L
m_ios.post([=, this] { callback(h, ec, ips); });
#else
m_ios.post([=] { callback(h, ec, ips); });
#endif
return;
}
}

if (flags & resolver_interface::cache_only)
{
// we did not find a cache entry, fail the lookup
#if __cplusplus >= 202002L
m_ios.post([=, this] {
#else
m_ios.post([=] {
#endif
callback(h, boost::asio::error::host_not_found, std::vector<address>{});
});
return;
Expand Down
4 changes: 4 additions & 0 deletions src/session_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5892,7 +5892,11 @@ namespace {
m_dht = std::make_shared<dht::dht_tracker>(
static_cast<dht::dht_observer*>(this)
, m_io_service
#if __cplusplus >= 202002L
, [=, this](aux::listen_socket_handle const& sock
#else
, [=](aux::listen_socket_handle const& sock
#endif
, udp::endpoint const& ep
, span<char const> p
, error_code& ec
Expand Down
6 changes: 5 additions & 1 deletion src/torrent_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ namespace libtorrent {
std::shared_ptr<torrent> t = m_torrent.lock();
if (!t) aux::throw_ex<system_error>(errors::invalid_torrent_handle);
auto& ses = static_cast<session_impl&>(t->session());
ses.get_io_service().dispatch([=,&ses] ()
#if __cplusplus >= 202002L
ses.get_io_service().dispatch([=, this, &ses] ()
#else
ses.get_io_service().dispatch([=, &ses] ()
#endif
{
#ifndef BOOST_NO_EXCEPTIONS
try {
Expand Down

0 comments on commit d4b45e1

Please sign in to comment.