2 // ip/address_v4_iterator.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_IP_ADDRESS_V4_ITERATOR_HPP
12 #define BOOST_ASIO_IP_ADDRESS_V4_ITERATOR_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
19 #include <boost/asio/ip/address_v4.hpp>
21 #include <boost/asio/detail/push_options.hpp>
27 template <typename> class basic_address_iterator;
29 /// An input iterator that can be used for traversing IPv4 addresses.
31 * In addition to satisfying the input iterator requirements, this iterator
32 * also supports decrement.
35 * @e Distinct @e objects: Safe.@n
36 * @e Shared @e objects: Unsafe.
38 template <> class basic_address_iterator<address_v4>
41 /// The type of the elements pointed to by the iterator.
42 typedef address_v4 value_type;
44 /// Distance between two iterators.
45 typedef std::ptrdiff_t difference_type;
47 /// The type of a pointer to an element pointed to by the iterator.
48 typedef const address_v4* pointer;
50 /// The type of a reference to an element pointed to by the iterator.
51 typedef const address_v4& reference;
53 /// Denotes that the iterator satisfies the input iterator requirements.
54 typedef std::input_iterator_tag iterator_category;
56 /// Construct an iterator that points to the specified address.
57 basic_address_iterator(const address_v4& addr) BOOST_ASIO_NOEXCEPT
63 basic_address_iterator(
64 const basic_address_iterator& other) BOOST_ASIO_NOEXCEPT
65 : address_(other.address_)
69 #if defined(BOOST_ASIO_HAS_MOVE)
71 basic_address_iterator(basic_address_iterator&& other) BOOST_ASIO_NOEXCEPT
72 : address_(BOOST_ASIO_MOVE_CAST(address_v4)(other.address_))
75 #endif // defined(BOOST_ASIO_HAS_MOVE)
77 /// Assignment operator.
78 basic_address_iterator& operator=(
79 const basic_address_iterator& other) BOOST_ASIO_NOEXCEPT
81 address_ = other.address_;
85 #if defined(BOOST_ASIO_HAS_MOVE)
86 /// Move assignment operator.
87 basic_address_iterator& operator=(
88 basic_address_iterator&& other) BOOST_ASIO_NOEXCEPT
90 address_ = BOOST_ASIO_MOVE_CAST(address_v4)(other.address_);
93 #endif // defined(BOOST_ASIO_HAS_MOVE)
95 /// Dereference the iterator.
96 const address_v4& operator*() const BOOST_ASIO_NOEXCEPT
101 /// Dereference the iterator.
102 const address_v4* operator->() const BOOST_ASIO_NOEXCEPT
107 /// Pre-increment operator.
108 basic_address_iterator& operator++() BOOST_ASIO_NOEXCEPT
110 address_ = address_v4((address_.to_uint() + 1) & 0xFFFFFFFF);
114 /// Post-increment operator.
115 basic_address_iterator operator++(int) BOOST_ASIO_NOEXCEPT
117 basic_address_iterator tmp(*this);
122 /// Pre-decrement operator.
123 basic_address_iterator& operator--() BOOST_ASIO_NOEXCEPT
125 address_ = address_v4((address_.to_uint() - 1) & 0xFFFFFFFF);
129 /// Post-decrement operator.
130 basic_address_iterator operator--(int)
132 basic_address_iterator tmp(*this);
137 /// Compare two addresses for equality.
138 friend bool operator==(const basic_address_iterator& a,
139 const basic_address_iterator& b)
141 return a.address_ == b.address_;
144 /// Compare two addresses for inequality.
145 friend bool operator!=(const basic_address_iterator& a,
146 const basic_address_iterator& b)
148 return a.address_ != b.address_;
155 /// An input iterator that can be used for traversing IPv4 addresses.
156 typedef basic_address_iterator<address_v4> address_v4_iterator;
162 #include <boost/asio/detail/pop_options.hpp>
164 #endif // BOOST_ASIO_IP_ADDRESS_V4_ITERATOR_HPP