From 58132cd724752586c3941d9c8c421092002fa8be Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sun, 29 Sep 2024 15:14:35 -0700 Subject: [PATCH] remove most ptr_fun Removed in C++17 Signed-off-by: Rosen Penev --- src/download/download_constructor.cc | 2 +- src/protocol/handshake_manager.cc | 13 ++++--------- src/protocol/request_list.cc | 14 ++++---------- src/torrent/data/block_failed.h | 6 +++--- src/torrent/peer/peer_list.cc | 6 ------ src/torrent/utils/uri_parser.cc | 8 ++++---- 6 files changed, 16 insertions(+), 33 deletions(-) diff --git a/src/download/download_constructor.cc b/src/download/download_constructor.cc index 0aacb45e7..441970fff 100644 --- a/src/download/download_constructor.cc +++ b/src/download/download_constructor.cc @@ -343,7 +343,7 @@ DownloadConstructor::create_path(const Object::list_type& plist, const std::stri if (plist.empty()) throw input_error("Bad torrent file, \"path\" has zero entries."); - if (std::find_if(plist.begin(), plist.end(), std::ptr_fun(&DownloadConstructor::is_invalid_path_element)) != plist.end()) + if (std::any_of(plist.begin(), plist.end(), &DownloadConstructor::is_invalid_path_element)) throw input_error("Bad torrent file, \"path\" has zero entries or a zero length entry."); Path p; diff --git a/src/protocol/handshake_manager.cc b/src/protocol/handshake_manager.cc index 030a1f835..b9a383ec6 100644 --- a/src/protocol/handshake_manager.cc +++ b/src/protocol/handshake_manager.cc @@ -46,7 +46,7 @@ HandshakeManager::size_info(DownloadMain* info) const { void HandshakeManager::clear() { - std::for_each(base_type::begin(), base_type::end(), std::ptr_fun(&handshake_manager_delete_handshake)); + std::for_each(base_type::begin(), base_type::end(), &handshake_manager_delete_handshake); base_type::clear(); } @@ -60,15 +60,10 @@ HandshakeManager::erase(Handshake* handshake) { base_type::erase(itr); } -struct handshake_manager_equal : std::binary_function { - bool operator () (const rak::socket_address* sa1, const Handshake* p2) const { - return p2->peer_info() != NULL && *sa1 == *rak::socket_address::cast_from(p2->peer_info()->socket_address()); - } -}; - bool HandshakeManager::find(const rak::socket_address& sa) { - return std::find_if(base_type::begin(), base_type::end(), std::bind1st(handshake_manager_equal(), &sa)) != base_type::end(); + auto f = [&sa](const Handshake* p2) { return p2->peer_info() && sa == *rak::socket_address::cast_from(p2->peer_info()->socket_address()); }; + return std::any_of(base_type::begin(), base_type::end(), f); } void @@ -77,7 +72,7 @@ HandshakeManager::erase_download(DownloadMain* info) { return info != h->download(); }); - std::for_each(split, base_type::end(), std::ptr_fun(&handshake_manager_delete_handshake)); + std::for_each(split, base_type::end(), &handshake_manager_delete_handshake); base_type::erase(split, base_type::end()); } diff --git a/src/protocol/request_list.cc b/src/protocol/request_list.cc index 90367fdef..f3fc5da44 100644 --- a/src/protocol/request_list.cc +++ b/src/protocol/request_list.cc @@ -111,9 +111,9 @@ RequestList::delegate(uint32_t maxPieces) { void RequestList::stall_initial() { - queue_bucket_for_all_in_queue(m_queues, bucket_queued, std::ptr_fun(&Block::stalled)); + queue_bucket_for_all_in_queue(m_queues, bucket_queued, &Block::stalled); m_queues.move_all_to(bucket_queued, bucket_stalled); - queue_bucket_for_all_in_queue(m_queues, bucket_unordered, std::ptr_fun(&Block::stalled)); + queue_bucket_for_all_in_queue(m_queues, bucket_unordered, &Block::stalled); m_queues.move_all_to(bucket_unordered, bucket_stalled); } @@ -122,9 +122,9 @@ RequestList::stall_prolonged() { if (m_transfer != NULL) Block::stalled(m_transfer); - queue_bucket_for_all_in_queue(m_queues, bucket_queued, std::ptr_fun(&Block::stalled)); + queue_bucket_for_all_in_queue(m_queues, bucket_queued, &Block::stalled); m_queues.move_all_to(bucket_queued, bucket_stalled); - queue_bucket_for_all_in_queue(m_queues, bucket_unordered, std::ptr_fun(&Block::stalled)); + queue_bucket_for_all_in_queue(m_queues, bucket_unordered, &Block::stalled); m_queues.move_all_to(bucket_unordered, bucket_stalled); // Currently leave the the requests until the peer gets disconnected. (?) @@ -334,12 +334,6 @@ RequestList::transfer_dissimilar() { m_transfer = dummy; } -struct equals_reservee : public std::binary_function { - bool operator () (BlockTransfer* r, uint32_t index) const { - return r->is_valid() && index == r->index(); - } -}; - bool RequestList::is_interested_in_active() const { for (TransferList::const_iterator diff --git a/src/torrent/data/block_failed.h b/src/torrent/data/block_failed.h index 8337324a9..4b7a21312 100644 --- a/src/torrent/data/block_failed.h +++ b/src/torrent/data/block_failed.h @@ -93,17 +93,17 @@ class BlockFailed : public std::vector > { inline BlockFailed::~BlockFailed() { - std::for_each(begin(), end(), std::ptr_fun(&BlockFailed::delete_entry)); + std::for_each(begin(), end(), &BlockFailed::delete_entry); } inline BlockFailed::iterator BlockFailed::max_element() { - return std::max_element(begin(), end(), std::ptr_fun(&BlockFailed::compare_entries)); + return std::max_element(begin(), end(), &BlockFailed::compare_entries); } inline BlockFailed::reverse_iterator BlockFailed::reverse_max_element() { - return std::max_element(rbegin(), rend(), std::ptr_fun(&BlockFailed::compare_entries)); + return std::max_element(rbegin(), rend(), &BlockFailed::compare_entries); } } diff --git a/src/torrent/peer/peer_list.cc b/src/torrent/peer/peer_list.cc index 7dff7af8f..db0fe9a4e 100644 --- a/src/torrent/peer/peer_list.cc +++ b/src/torrent/peer/peer_list.cc @@ -50,12 +50,6 @@ socket_address_less(const sockaddr* s1, const sockaddr* s2) { } } -struct peer_list_equal_port : public std::binary_function { - bool operator () (PeerList::reference p, uint16_t port) { - return rak::socket_address::cast_from(p.second->socket_address())->port() == port; - } -}; - // // PeerList: // diff --git a/src/torrent/utils/uri_parser.cc b/src/torrent/utils/uri_parser.cc index 2f6b2e683..811b483fc 100644 --- a/src/torrent/utils/uri_parser.cc +++ b/src/torrent/utils/uri_parser.cc @@ -120,7 +120,7 @@ uri_parse_str(std::string uri, uri_state& state) { std::string::const_iterator last = state.uri.end(); // Parse scheme: - first = uri_string_copy_until(first, last, state.scheme, std::ptr_fun(&is_not_unreserved_uri_char)); + first = uri_string_copy_until(first, last, state.scheme, &is_not_unreserved_uri_char); if (first == last) goto uri_parse_success; @@ -129,7 +129,7 @@ uri_parse_str(std::string uri, uri_state& state) { uri_parse_throw_error("could not find ':' after scheme, found character 0x", *--first); // Parse resource: - first = uri_string_copy_until(first, last, state.resource, std::ptr_fun(&is_not_unreserved_uri_char)); + first = uri_string_copy_until(first, last, state.resource, &is_not_unreserved_uri_char); if (first == last) goto uri_parse_success; @@ -138,7 +138,7 @@ uri_parse_str(std::string uri, uri_state& state) { uri_parse_throw_error("could not find '?' after resource, found character 0x", *--first); // Parse query: - first = uri_string_copy_until(first, last, state.query, std::ptr_fun(&is_not_valid_uri_query_char)); + first = uri_string_copy_until(first, last, state.query, &is_not_valid_uri_query_char); if (first == last) goto uri_parse_success; @@ -175,7 +175,7 @@ uri_parse_query_str(std::string query, uri_query_state& state) { while (first != last) { std::string element; - first = uri_string_copy_until(first, last, element, std::ptr_fun(&is_not_unreserved_uri_query_char)); + first = uri_string_copy_until(first, last, element, &is_not_unreserved_uri_query_char); if (first != last && *first++ != '&') { std::string invalid_hex;