diff --git a/rak/algorithm.h b/rak/algorithm.h index aa225bd54..458d13c13 100644 --- a/rak/algorithm.h +++ b/rak/algorithm.h @@ -115,7 +115,7 @@ advance_backward(_InputIter __first, _InputIter __last, _Distance __distance) { } template -struct compare_base : public std::binary_function<_Value, _Value, bool> { +struct compare_base { bool operator () (const _Value& complete, const _Value& base) const { return !complete.compare(0, base.size(), base); } diff --git a/src/data/chunk_list.cc b/src/data/chunk_list.cc index 3cbf1077e..05dafbcaa 100644 --- a/src/data/chunk_list.cc +++ b/src/data/chunk_list.cc @@ -410,7 +410,7 @@ ChunkList::partition_optimize(Queue::iterator first, Queue::iterator last, int w for (Queue::iterator itr = first; itr != last;) { auto range = seek_range(itr, last); - bool required = std::find_if(itr, range, std::bind1st(std::mem_fn(&ChunkList::check_node), this)) != range; + bool required = std::any_of(itr, range, [this](auto wrapper) { return check_node(wrapper); }); dontSkip = dontSkip || required; if (!required && std::distance(itr, range) < maxDistance) { diff --git a/src/dht/dht_bucket.cc b/src/dht/dht_bucket.cc index b2f18b870..20655b176 100644 --- a/src/dht/dht_bucket.cc +++ b/src/dht/dht_bucket.cc @@ -75,7 +75,7 @@ DhtBucket::add_node(DhtNode* n) { void DhtBucket::remove_node(DhtNode* n) { - iterator itr = std::find_if(begin(), end(), std::bind2nd(std::equal_to(), n)); + auto itr = std::find(begin(), end(), n); if (itr == end()) throw internal_error("DhtBucket::remove_node called for node not in bucket."); @@ -165,9 +165,11 @@ DhtBucket::split(const HashString& id) { // Move nodes over to other bucket if they fall in its range, then // delete them from this one. - iterator split = std::partition(begin(), end(), std::bind2nd(std::mem_fn(&DhtNode::is_in_range), this)); + auto split = std::partition(begin(), end(), [this](auto dht) { return dht->is_in_range(this); }); other->insert(other->end(), split, end()); - std::for_each(other->begin(), other->end(), std::bind2nd(std::mem_fn(&DhtNode::set_bucket), other)); + for (auto& dht : *other) { + dht->set_bucket(other); + } erase(split, end()); other->set_time(m_lastChanged); diff --git a/src/dht/dht_hash_map.h b/src/dht/dht_hash_map.h index 2f6f922db..17a5bb535 100644 --- a/src/dht/dht_hash_map.h +++ b/src/dht/dht_hash_map.h @@ -58,7 +58,7 @@ namespace torrent { // aligned 64-bit access. static const unsigned int hashstring_hash_ofs = 8; -struct hashstring_ptr_hash : public std::unary_function { +struct hashstring_ptr_hash { size_t operator () (const HashString* n) const { #if USE_ALIGNED size_t result = 0; @@ -75,7 +75,7 @@ struct hashstring_ptr_hash : public std::unary_function { +struct hashstring_hash { size_t operator () (const HashString& n) const { #if USE_ALIGNED size_t result = 0; @@ -93,7 +93,7 @@ struct hashstring_hash : public std::unary_function { }; // Compare HashString pointers by dereferencing them. -struct hashstring_ptr_equal : public std::binary_function { +struct hashstring_ptr_equal { size_t operator () (const HashString* one, const HashString* two) const { return *one == *two; } }; diff --git a/src/dht/dht_tracker.cc b/src/dht/dht_tracker.cc index 2ff7ba4b7..7ea653304 100644 --- a/src/dht/dht_tracker.cc +++ b/src/dht/dht_tracker.cc @@ -109,7 +109,7 @@ DhtTracker::prune(uint32_t maxAge) { if (m_lastSeen[i] < minSeen) m_peers[i].peer.port = 0; m_peers.erase(std::remove_if(m_peers.begin(), m_peers.end(), std::mem_fn(&BencodeAddress::empty)), m_peers.end()); - m_lastSeen.erase(std::remove_if(m_lastSeen.begin(), m_lastSeen.end(), std::bind2nd(std::less(), minSeen)), m_lastSeen.end()); + m_lastSeen.erase(std::remove_if(m_lastSeen.begin(), m_lastSeen.end(), [minSeen](auto seen) { return seen < minSeen; }), m_lastSeen.end()); if (m_peers.size() != m_lastSeen.size()) throw internal_error("DhtTracker::prune did inconsistent peer pruning."); diff --git a/src/dht/dht_transaction.h b/src/dht/dht_transaction.h index e612e26e2..ea8843888 100644 --- a/src/dht/dht_transaction.h +++ b/src/dht/dht_transaction.h @@ -70,7 +70,7 @@ class DhtTransactionAnnouncePeer; // Compare predicate for ID closeness. -struct dht_compare_closer : public std::binary_function { +struct dht_compare_closer { dht_compare_closer(const HashString& target) : m_target(target) { } bool operator () (const DhtNode* one, const DhtNode* two) const; diff --git a/src/manager.cc b/src/manager.cc index 7390c1364..32c30e3a0 100644 --- a/src/manager.cc +++ b/src/manager.cc @@ -141,10 +141,11 @@ Manager::receive_tick() { // various limited resources, like sockets for handshakes, cycle the // group in reverse order. if (!m_downloadManager->empty()) { - DownloadManager::iterator split = m_downloadManager->end() - m_ticks % m_downloadManager->size() - 1; + auto split = m_downloadManager->end() - m_ticks % m_downloadManager->size() - 1; + auto f = [this](auto wrapper) { return wrapper->receive_tick(m_ticks); }; - std::for_each(split, m_downloadManager->end(), std::bind2nd(std::mem_fn(&DownloadWrapper::receive_tick), m_ticks)); - std::for_each(m_downloadManager->begin(), split, std::bind2nd(std::mem_fn(&DownloadWrapper::receive_tick), m_ticks)); + std::for_each(split, m_downloadManager->end(), f); + std::for_each(m_downloadManager->begin(), split, f); } // If you change the interval, make sure the keepalives gets diff --git a/src/net/socket_set.cc b/src/net/socket_set.cc index b0b0bbdd1..cf460616f 100644 --- a/src/net/socket_set.cc +++ b/src/net/socket_set.cc @@ -66,7 +66,9 @@ SocketSet::_replace_with_last(size_type idx) { void SocketSet::prepare() { - std::for_each(m_erased.begin(), m_erased.end(), std::bind1st(std::mem_fn(&SocketSet::_replace_with_last), this)); + for (auto& socket : m_erased) { + _replace_with_last(socket); + } m_erased.clear(); } diff --git a/src/protocol/initial_seed.cc b/src/protocol/initial_seed.cc index fc36b3453..738d26bcb 100644 --- a/src/protocol/initial_seed.cc +++ b/src/protocol/initial_seed.cc @@ -173,9 +173,8 @@ InitialSeeding::chunk_offer(PeerConnectionBase* pcb, uint32_t chunkDone) { // Re-connection of a peer we already sent a chunk. // Offer the same chunk again. - PeerInfo** peerChunksEnd = m_peerChunks + m_download->file_list()->size_chunks(); - PeerInfo** itr = std::find_if(m_peerChunks, peerChunksEnd, - std::bind2nd(std::equal_to(), peer)); + auto peerChunksEnd = m_peerChunks + m_download->file_list()->size_chunks(); + auto itr = std::find(m_peerChunks, peerChunksEnd, peer); if (itr != peerChunksEnd) return itr - m_peerChunks; diff --git a/src/torrent/data/block.cc b/src/torrent/data/block.cc index 76bf6291a..70572db6a 100644 --- a/src/torrent/data/block.cc +++ b/src/torrent/data/block.cc @@ -64,10 +64,14 @@ Block::~Block() { m_leader = NULL; m_state = STATE_INVALID; - std::for_each(m_queued.begin(), m_queued.end(), std::bind1st(std::mem_fn(&Block::invalidate_transfer), this)); + for (auto& block : m_queued) { + invalidate_transfer(block); + } m_queued.clear(); - std::for_each(m_transfers.begin(), m_transfers.end(), std::bind1st(std::mem_fn(&Block::invalidate_transfer), this)); + for (auto& block : m_transfers) { + invalidate_transfer(block); + } m_transfers.clear(); if (m_notStalled != 0) @@ -137,10 +141,10 @@ Block::erase(BlockTransfer* transfer) { // Create a range containing transfers with // is_not_leader(). Erased transfer will end up in the back. - transfer_list_type::iterator first = std::find_if(m_transfers.begin(), m_transfers.end(), std::not1(std::mem_fn(&BlockTransfer::is_leader))); - transfer_list_type::iterator last = std::stable_partition(first, m_transfers.end(), std::mem_fn(&BlockTransfer::is_not_leader)); + auto first = std::find_if_not(m_transfers.begin(), m_transfers.end(), std::mem_fn(&BlockTransfer::is_leader)); + auto last = std::stable_partition(first, m_transfers.end(), std::mem_fn(&BlockTransfer::is_not_leader)); - transfer_list_type::iterator new_leader = std::max_element(first, last, [](BlockTransfer* t1, BlockTransfer* t2) { + auto new_leader = std::max_element(first, last, [](BlockTransfer* t1, BlockTransfer* t2) { return t1->position() < t2->position(); }); @@ -233,7 +237,9 @@ Block::completed(BlockTransfer* transfer) { // Block::transfering(...). But that would propably not be correct // as we want to trigger cancel messages from here, as hash fail is // a rare occurrence. - std::for_each(m_queued.begin(), m_queued.end(), std::bind1st(std::mem_fn(&Block::invalidate_transfer), this)); + for (const auto& block : m_queued) { + invalidate_transfer(block); + } m_queued.clear(); // We need to invalidate those unfinished and keep the one that @@ -366,17 +372,17 @@ Block::invalidate_transfer(BlockTransfer* transfer) { void Block::remove_erased_transfers() { - transfer_list_type::iterator split = std::stable_partition(m_transfers.begin(), m_transfers.end(), std::not1(std::mem_fn(&BlockTransfer::is_erased))); + auto split = std::stable_partition(m_transfers.begin(), m_transfers.end(), [](auto block) { return !block->is_erased(); }); - std::for_each(split, m_transfers.end(), std::bind1st(std::mem_fn(&Block::invalidate_transfer), this)); + std::for_each(split, m_transfers.end(), [this](auto block) { invalidate_transfer(block); }); m_transfers.erase(split, m_transfers.end()); } void Block::remove_non_leader_transfers() { - transfer_list_type::iterator split = std::stable_partition(m_transfers.begin(), m_transfers.end(), std::mem_fn(&BlockTransfer::is_leader)); + auto split = std::stable_partition(m_transfers.begin(), m_transfers.end(), std::mem_fn(&BlockTransfer::is_leader)); - std::for_each(split, m_transfers.end(), std::bind1st(std::mem_fn(&Block::invalidate_transfer), this)); + std::for_each(split, m_transfers.end(), [this](auto block) { invalidate_transfer(block); }); m_transfers.erase(split, m_transfers.end()); } diff --git a/src/torrent/torrent.cc b/src/torrent/torrent.cc index 3728225b2..f08e3d7ef 100644 --- a/src/torrent/torrent.cc +++ b/src/torrent/torrent.cc @@ -96,8 +96,7 @@ is_initialized() { bool is_inactive() { - return manager == NULL || - std::find_if(manager->download_manager()->begin(), manager->download_manager()->end(), std::not1(std::mem_fn(&DownloadWrapper::is_stopped))) == manager->download_manager()->end(); + return !manager || std::all_of(manager->download_manager()->begin(), manager->download_manager()->end(), std::mem_fn(&DownloadWrapper::is_stopped)); } thread_base* @@ -133,7 +132,7 @@ encoding_list() { Download download_add(Object* object) { - std::auto_ptr download(new DownloadWrapper); + auto download = std::make_unique(); DownloadConstructor ctor; ctor.set_download(download.get()); diff --git a/src/torrent/tracker_list.cc b/src/torrent/tracker_list.cc index 7c4c3dfee..ac7eb2444 100644 --- a/src/torrent/tracker_list.cc +++ b/src/torrent/tracker_list.cc @@ -230,7 +230,7 @@ TrackerList::find_usable(const_iterator itr) const { TrackerList::iterator TrackerList::find_next_to_request(iterator itr) { - TrackerList::iterator preferred = itr = std::find_if(itr, end(), std::mem_fn(&Tracker::can_request_state)); + auto preferred = itr = std::find_if(itr, end(), std::mem_fn(&Tracker::can_request_state)); if (preferred == end() || (*preferred)->failed_counter() == 0) return preferred; diff --git a/src/torrent/utils/log.cc b/src/torrent/utils/log.cc index e7c0f9974..85d6923e3 100644 --- a/src/torrent/utils/log.cc +++ b/src/torrent/utils/log.cc @@ -63,9 +63,8 @@ const char log_level_char[] = { 'C', 'E', 'W', 'N', 'I', 'D' }; void log_update_child_cache(int index) { - log_child_list::const_iterator first = - std::find_if(log_children.begin(), log_children.end(), - std::bind2nd(std::greater_equal >(), std::make_pair(index, 0))); + auto first = + std::find_if(log_children.begin(), log_children.end(), [index](const auto& pair) { return pair >= std::make_pair(index, 0); }); if (first == log_children.end()) return;