diff --git a/include/libtorrent/address.hpp b/include/libtorrent/address.hpp index 0682991b5..d642e67c4 100644 --- a/include/libtorrent/address.hpp +++ b/include/libtorrent/address.hpp @@ -62,16 +62,16 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { #if defined TORRENT_BUILD_SIMULATOR - typedef sim::asio::ip::address address; - typedef sim::asio::ip::address_v4 address_v4; + using address = typedef sim::asio::ip::address; + using address_v4 = sim::asio::ip::address_v4; #if TORRENT_USE_IPV6 - typedef sim::asio::ip::address_v6 address_v6; + using address_v6 = sim::asio::ip::address_v6; #endif #else - typedef boost::asio::ip::address address; - typedef boost::asio::ip::address_v4 address_v4; + using address = boost::asio::ip::address; + using address_v4 = boost::asio::ip::address_v4; #if TORRENT_USE_IPV6 - typedef boost::asio::ip::address_v6 address_v6; + using address_v6 = boost::asio::ip::address_v6; #endif #endif // SIMULATOR } diff --git a/include/libtorrent/alert_manager.hpp b/include/libtorrent/alert_manager.hpp index 2f664cea0..118e1e651 100644 --- a/include/libtorrent/alert_manager.hpp +++ b/include/libtorrent/alert_manager.hpp @@ -183,8 +183,7 @@ namespace libtorrent { aux::stack_allocator m_allocations[2]; #ifndef TORRENT_DISABLE_EXTENSIONS - typedef std::list > ses_extension_list_t; - ses_extension_list_t m_ses_extensions; + std::list > m_ses_extensions; #endif }; } diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 9b9005a87..64146c34b 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -1164,8 +1164,7 @@ namespace libtorrent #ifndef TORRENT_DISABLE_EXTENSIONS // this is a list to allow extensions to potentially remove themselves. - typedef std::list > ses_extension_list_t; - ses_extension_list_t m_ses_extensions; + std::vector > m_ses_extensions; // the union of all session extensions' implemented_features(). This is // used to exclude callbacks to the session extensions. diff --git a/include/libtorrent/file.hpp b/include/libtorrent/file.hpp index aec1a6ed5..c67d1dab9 100644 --- a/include/libtorrent/file.hpp +++ b/include/libtorrent/file.hpp @@ -83,9 +83,9 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { #ifdef TORRENT_WINDOWS - typedef HANDLE handle_type; + using handle_type = HANDLE; #else - typedef int handle_type; + using handle_type = int; #endif struct file_status @@ -227,7 +227,7 @@ namespace libtorrent void TORRENT_EXTRA_EXPORT print_open_files(char const* event, char const* name); #else - typedef boost::shared_ptr file_handle; + using file_handle = boost::shared_ptr; #endif struct TORRENT_EXTRA_EXPORT file: boost::noncopyable @@ -293,15 +293,13 @@ namespace libtorrent size_t iov_len; }; #else - typedef iovec iovec_t; + using iovec_t = iovec; #endif - // use a typedef for the type of iovec_t::iov_base - // since it may differ #ifdef TORRENT_SOLARIS - typedef char* iovec_base_t; + using iovec_base_t = char*; #else - typedef void* iovec_base_t; + using iovec_base_t = void*; #endif file(); diff --git a/include/libtorrent/peer_list.hpp b/include/libtorrent/peer_list.hpp index ae7d9d010..39e6fa26d 100644 --- a/include/libtorrent/peer_list.hpp +++ b/include/libtorrent/peer_list.hpp @@ -169,13 +169,13 @@ namespace libtorrent int num_peers() const { return int(m_peers.size()); } #ifdef TORRENT_OPTIMIZE_MEMORY_USAGE - typedef std::vector peers_t; + using peers_t = std::vector; #else - typedef std::deque peers_t; + using peers_t = std::deque; #endif - typedef peers_t::iterator iterator; - typedef peers_t::const_iterator const_iterator; + using iterator = peers_t::iterator; + using const_iterator = peers_t::const_iterator; iterator begin_peer() { return m_peers.begin(); } iterator end_peer() { return m_peers.end(); } const_iterator begin_peer() const { return m_peers.begin(); } diff --git a/include/libtorrent/socket_io.hpp b/include/libtorrent/socket_io.hpp index 9e6646866..4da8ea093 100644 --- a/include/libtorrent/socket_io.hpp +++ b/include/libtorrent/socket_io.hpp @@ -68,11 +68,8 @@ namespace libtorrent } else if (a.is_v6()) { - typedef address_v6::bytes_type bytes_t; - bytes_t bytes = a.to_v6().to_bytes(); - for (bytes_t::iterator i = bytes.begin() - , end(bytes.end()); i != end; ++i) - write_uint8(*i, out); + for (auto b : a.to_v6().to_bytes()) + write_uint8(b, out); } #endif } @@ -88,11 +85,9 @@ namespace libtorrent template address read_v6_address(InIt& in) { - typedef address_v6::bytes_type bytes_t; - bytes_t bytes; - for (bytes_t::iterator i = bytes.begin() - , end(bytes.end()); i != end; ++i) - *i = read_uint8(in); + address_v6::bytes_type bytes; + for (auto& b : bytes) + b = read_uint8(in); return address_v6(bytes); } #endif diff --git a/include/libtorrent/socket_type.hpp b/include/libtorrent/socket_type.hpp index 9220a3ff7..7dcb08cfc 100644 --- a/include/libtorrent/socket_type.hpp +++ b/include/libtorrent/socket_type.hpp @@ -184,11 +184,11 @@ namespace libtorrent struct TORRENT_EXTRA_EXPORT socket_type { - typedef tcp::socket::endpoint_type endpoint_type; - typedef tcp::socket::protocol_type protocol_type; + using endpoint_type = tcp::socket::endpoint_type; + using protocol_type = tcp::socket::protocol_type; - typedef tcp::socket::receive_buffer_size receive_buffer_size; - typedef tcp::socket::send_buffer_size send_buffer_size; + using receive_buffer_size = tcp::socket::receive_buffer_size; + using send_buffer_size = tcp::socket::send_buffer_size; explicit socket_type(io_service& ios): m_io_service(ios), m_type(0) {} ~socket_type(); diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 1279365c2..a840edeb1 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -642,8 +642,8 @@ namespace libtorrent int num_seeds() const; int num_downloaders() const; - typedef std::vector::iterator peer_iterator; - typedef std::vector::const_iterator const_peer_iterator; + using peer_iterator = std::vector::iterator; + using const_peer_iterator = std::vector::const_iterator; const_peer_iterator begin() const { return m_connections.begin(); } const_peer_iterator end() const { return m_connections.end(); } @@ -1204,8 +1204,7 @@ namespace libtorrent std::list m_web_seeds; #ifndef TORRENT_DISABLE_EXTENSIONS - typedef std::list > extension_list_t; - extension_list_t m_extensions; + std::list > m_extensions; #endif // used for tracker announces diff --git a/src/alert_manager.cpp b/src/alert_manager.cpp index 82dfcf815..0fbd03ad5 100644 --- a/src/alert_manager.cpp +++ b/src/alert_manager.cpp @@ -86,11 +86,8 @@ namespace libtorrent } #ifndef TORRENT_DISABLE_EXTENSIONS - for (ses_extension_list_t::iterator i = m_ses_extensions.begin() - , end(m_ses_extensions.end()); i != end; ++i) - { - (*i)->on_alert(a); - } + for (auto& e : m_ses_extensions) + e->on_alert(a); #else TORRENT_UNUSED(a); #endif diff --git a/src/peer_list.cpp b/src/peer_list.cpp index acbb99dad..ae13b4910 100644 --- a/src/peer_list.cpp +++ b/src/peer_list.cpp @@ -194,9 +194,8 @@ namespace libtorrent void peer_list::clear_peer_prio() { - for (peers_t::iterator i = m_peers.begin() - , end(m_peers.end()); i != end; ++i) - (*i)->peer_rank = 0; + for (auto& p : m_peers) + p->peer_rank = 0; } // disconnects and removes all peers that are now filtered @@ -862,12 +861,7 @@ namespace libtorrent { TORRENT_ASSERT(is_single_thread()); // find p in m_peers - for (const_iterator i = m_peers.begin() - , end(m_peers.end()); i != end; ++i) - { - if (*i == p) return true; - } - return false; + return std::find(m_peers.begin(), m_peers.end(), p) != m_peers.end(); } void peer_list::set_seed(torrent_peer* p, bool s) @@ -1262,10 +1256,9 @@ namespace libtorrent m_finished = state->is_finished; m_max_failcount = state->max_failcount; - for (const_iterator i = m_peers.begin(); - i != m_peers.end(); ++i) + for (auto const& p : m_peers) { - m_num_connect_candidates += is_connect_candidate(**i); + m_num_connect_candidates += is_connect_candidate(*p); } #if TORRENT_USE_INVARIANT_CHECKS diff --git a/src/session_impl.cpp b/src/session_impl.cpp index bdffcaa2b..d6d767a57 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -632,11 +632,10 @@ namespace aux { #endif #ifndef TORRENT_DISABLE_EXTENSIONS - for (ses_extension_list_t::const_iterator i = m_ses_extensions.begin() - , end(m_ses_extensions.end()); i != end; ++i) + for (auto& ext : m_ses_extensions) { TORRENT_TRY { - (*i)->save_state(*eptr); + ext->save_state(*eptr); } TORRENT_CATCH(std::exception&) {} } #endif @@ -780,11 +779,10 @@ namespace aux { #endif #ifndef TORRENT_DISABLE_EXTENSIONS - for (ses_extension_list_t::iterator i = m_ses_extensions.begin() - , end(m_ses_extensions.end()); i != end; ++i) + for (auto& ext : m_ses_extensions) { TORRENT_TRY { - (*i)->load_state(*e); + ext->load_state(*e); } TORRENT_CATCH(std::exception&) {} } #endif @@ -3147,11 +3145,10 @@ namespace aux { #ifndef TORRENT_DISABLE_EXTENSIONS if (m_session_extension_features & plugin::tick_feature) { - for (ses_extension_list_t::const_iterator i = m_ses_extensions.begin() - , end(m_ses_extensions.end()); i != end; ++i) + for (auto& ext : m_ses_extensions) { TORRENT_TRY { - (*i)->on_tick(); + ext->on_tick(); } TORRENT_CATCH(std::exception&) {} } } @@ -3871,10 +3868,9 @@ namespace aux { { peers.push_back(peer_connection_handle(static_cast((*i)->connection)->self())); } - for (ses_extension_list_t::iterator i = m_ses_extensions.begin() - , end(m_ses_extensions.end()); i != end; ++i) + for (auto& e : m_ses_extensions) { - if ((*i)->on_optimistic_unchoke(peers)) + if (e->on_optimistic_unchoke(peers)) break; } // then convert back to the internal torrent_peer pointers @@ -4263,11 +4259,10 @@ namespace aux { , peer_connection* pc) { #ifndef TORRENT_DISABLE_EXTENSIONS - for (ses_extension_list_t::iterator i = m_ses_extensions.begin() - , end(m_ses_extensions.end()); i != end; ++i) + for (auto& e : m_ses_extensions) { add_torrent_params p; - if ((*i)->on_unknown_torrent(info_hash, peer_connection_handle(pc->self()), p)) + if (e->on_unknown_torrent(info_hash, peer_connection_handle(pc->self()), p)) { error_code ec; torrent_handle handle = add_torrent(p, ec); @@ -4663,10 +4658,10 @@ namespace aux { void session_impl::add_extensions_to_torrent( boost::shared_ptr const& torrent_ptr, void* userdata) { - for (ses_extension_list_t::iterator i = m_ses_extensions.begin() - , end(m_ses_extensions.end()); i != end; ++i) + for (auto& e : m_ses_extensions) { - boost::shared_ptr tp((*i)->new_torrent(torrent_ptr->get_handle(), userdata)); + boost::shared_ptr tp(e->new_torrent( + torrent_ptr->get_handle(), userdata)); if (tp) torrent_ptr->add_extension(tp); } } diff --git a/src/torrent.cpp b/src/torrent.cpp index e2b4470b6..b8decd75f 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1428,7 +1428,7 @@ namespace libtorrent void torrent::remove_extension(boost::shared_ptr ext) { - extension_list_t::iterator i = std::find(m_extensions.begin(), m_extensions.end(), ext); + auto i = std::find(m_extensions.begin(), m_extensions.end(), ext); if (i == m_extensions.end()) return; m_extensions.erase(i); } @@ -2095,11 +2095,10 @@ namespace libtorrent // call on_unload() on extensions #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto& ext : m_extensions) { TORRENT_TRY { - (*i)->on_unload(); + ext->on_unload(); } TORRENT_CATCH (std::exception&) {} } @@ -4060,11 +4059,10 @@ namespace libtorrent } #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto& ext : m_extensions) { TORRENT_TRY { - (*i)->on_piece_pass(index); + ext->on_piece_pass(index); } TORRENT_CATCH (std::exception&) {} } #endif @@ -4264,11 +4262,10 @@ namespace libtorrent add_failed_bytes(m_torrent_file->piece_size(index)); #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto& ext : m_extensions) { TORRENT_TRY { - (*i)->on_piece_failed(index); + ext->on_piece_failed(index); } TORRENT_CATCH (std::exception&) {} } #endif @@ -6391,11 +6388,10 @@ namespace libtorrent #endif #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto& ext : m_extensions) { boost::shared_ptr - pp((*i)->new_connection(peer_connection_handle(c.get()->self()))); + pp(ext->new_connection(peer_connection_handle(c.get()->self()))); if (pp) c->add_extension(pp); } #endif @@ -7097,11 +7093,10 @@ namespace libtorrent peerinfo->prev_amount_upload = 0; #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto& ext : m_extensions) { TORRENT_TRY { - boost::shared_ptr pp((*i)->new_connection( + boost::shared_ptr pp(ext->new_connection( peer_connection_handle(c.get()->self()))); if (pp) c->add_extension(pp); } TORRENT_CATCH (std::exception&) {} @@ -7394,10 +7389,9 @@ namespace libtorrent TORRENT_TRY { #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto& ext : m_extensions) { - boost::shared_ptr pp((*i)->new_connection( + boost::shared_ptr pp(ext->new_connection( peer_connection_handle(p->self()))); if (pp) p->add_extension(pp); } @@ -8034,11 +8028,10 @@ namespace libtorrent } #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto& ext : m_extensions) { TORRENT_TRY { - (*i)->on_files_checked(); + ext->on_files_checked(); } TORRENT_CATCH (std::exception&) {} } #endif @@ -9024,11 +9017,10 @@ namespace libtorrent } #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto& ext : m_extensions) { TORRENT_TRY { - if ((*i)->on_pause()) return; + if (ext->on_pause()) return; } TORRENT_CATCH (std::exception&) {} } #endif @@ -9260,11 +9252,10 @@ namespace libtorrent if (is_paused()) return; #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto& ext : m_extensions) { TORRENT_TRY { - if ((*i)->on_resume()) return; + if (ext->on_resume()) return; } TORRENT_CATCH (std::exception&) {} } #endif @@ -9492,11 +9483,10 @@ namespace libtorrent boost::weak_ptr self(shared_from_this()); #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto& ext : m_extensions) { TORRENT_TRY { - (*i)->tick(); + ext->tick(); } TORRENT_CATCH (std::exception&) {} } @@ -11070,11 +11060,10 @@ namespace libtorrent state_updated(); #ifndef TORRENT_DISABLE_EXTENSIONS - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto& ext : m_extensions) { TORRENT_TRY { - (*i)->on_state(m_state); + ext->on_state(m_state); } TORRENT_CATCH (std::exception&) {} } #endif @@ -11084,11 +11073,10 @@ namespace libtorrent void torrent::notify_extension_add_peer(tcp::endpoint const& ip , int src, int flags) { - for (extension_list_t::iterator i = m_extensions.begin() - , end(m_extensions.end()); i != end; ++i) + for (auto& ext : m_extensions) { TORRENT_TRY { - (*i)->on_add_peer(ip, src, flags); + ext->on_add_peer(ip, src, flags); } TORRENT_CATCH (std::exception&) {} } }