Skip to content

Commit

Permalink
remove most ptr_fun
Browse files Browse the repository at this point in the history
Removed in C++17

Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Dec 18, 2024
1 parent cac38b4 commit 58132cd
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/download/download_constructor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 4 additions & 9 deletions src/protocol/handshake_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -60,15 +60,10 @@ HandshakeManager::erase(Handshake* handshake) {
base_type::erase(itr);
}

struct handshake_manager_equal : std::binary_function<const rak::socket_address*, const Handshake*, bool> {
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
Expand All @@ -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());
}

Expand Down
14 changes: 4 additions & 10 deletions src/protocol/request_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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. (?)
Expand Down Expand Up @@ -334,12 +334,6 @@ RequestList::transfer_dissimilar() {
m_transfer = dummy;
}

struct equals_reservee : public std::binary_function<BlockTransfer*, uint32_t, bool> {
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
Expand Down
6 changes: 3 additions & 3 deletions src/torrent/data/block_failed.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ class BlockFailed : public std::vector<std::pair<char*, uint32_t> > {

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);
}

}
Expand Down
6 changes: 0 additions & 6 deletions src/torrent/peer/peer_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ socket_address_less(const sockaddr* s1, const sockaddr* s2) {
}
}

struct peer_list_equal_port : public std::binary_function<PeerList::reference, uint16_t, bool> {
bool operator () (PeerList::reference p, uint16_t port) {
return rak::socket_address::cast_from(p.second->socket_address())->port() == port;
}
};

//
// PeerList:
//
Expand Down
8 changes: 4 additions & 4 deletions src/torrent/utils/uri_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 58132cd

Please sign in to comment.