2 // ip/address_v6_iterator.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 // Oliver Kowalke (oliver dot kowalke at gmail dot com)
8 // Distributed under the Boost Software License, Version 1.0. (See accompanying
9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
12 #ifndef BOOST_ASIO_IP_ADDRESS_V6_ITERATOR_HPP
13 #define BOOST_ASIO_IP_ADDRESS_V6_ITERATOR_HPP
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
19 #include <boost/asio/detail/config.hpp>
20 #include <boost/asio/ip/address_v6.hpp>
22 #include <boost/asio/detail/push_options.hpp>
28 template <typename> class basic_address_iterator;
30 /// An input iterator that can be used for traversing IPv6 addresses.
32 * In addition to satisfying the input iterator requirements, this iterator
33 * also supports decrement.
36 * @e Distinct @e objects: Safe.@n
37 * @e Shared @e objects: Unsafe.
39 template <> class basic_address_iterator<address_v6>
42 /// The type of the elements pointed to by the iterator.
43 typedef address_v6 value_type;
45 /// Distance between two iterators.
46 typedef std::ptrdiff_t difference_type;
48 /// The type of a pointer to an element pointed to by the iterator.
49 typedef const address_v6* pointer;
51 /// The type of a reference to an element pointed to by the iterator.
52 typedef const address_v6& reference;
54 /// Denotes that the iterator satisfies the input iterator requirements.
55 typedef std::input_iterator_tag iterator_category;
57 /// Construct an iterator that points to the specified address.
58 basic_address_iterator(const address_v6& addr) BOOST_ASIO_NOEXCEPT
64 basic_address_iterator(
65 const basic_address_iterator& other) BOOST_ASIO_NOEXCEPT
66 : address_(other.address_)
70 #if defined(BOOST_ASIO_HAS_MOVE)
72 basic_address_iterator(basic_address_iterator&& other) BOOST_ASIO_NOEXCEPT
73 : address_(BOOST_ASIO_MOVE_CAST(address_v6)(other.address_))
76 #endif // defined(BOOST_ASIO_HAS_MOVE)
78 /// Assignment operator.
79 basic_address_iterator& operator=(
80 const basic_address_iterator& other) BOOST_ASIO_NOEXCEPT
82 address_ = other.address_;
86 #if defined(BOOST_ASIO_HAS_MOVE)
87 /// Move assignment operator.
88 basic_address_iterator& operator=(
89 basic_address_iterator&& other) BOOST_ASIO_NOEXCEPT
91 address_ = BOOST_ASIO_MOVE_CAST(address_v6)(other.address_);
94 #endif // defined(BOOST_ASIO_HAS_MOVE)
96 /// Dereference the iterator.
97 const address_v6& operator*() const BOOST_ASIO_NOEXCEPT
102 /// Dereference the iterator.
103 const address_v6* operator->() const BOOST_ASIO_NOEXCEPT
108 /// Pre-increment operator.
109 basic_address_iterator& operator++() BOOST_ASIO_NOEXCEPT
111 for (int i = 15; i >= 0; --i)
113 if (address_.addr_.s6_addr[i] < 0xFF)
115 ++address_.addr_.s6_addr[i];
119 address_.addr_.s6_addr[i] = 0;
125 /// Post-increment operator.
126 basic_address_iterator operator++(int) BOOST_ASIO_NOEXCEPT
128 basic_address_iterator tmp(*this);
133 /// Pre-decrement operator.
134 basic_address_iterator& operator--() BOOST_ASIO_NOEXCEPT
136 for (int i = 15; i >= 0; --i)
138 if (address_.addr_.s6_addr[i] > 0)
140 --address_.addr_.s6_addr[i];
144 address_.addr_.s6_addr[i] = 0xFF;
150 /// Post-decrement operator.
151 basic_address_iterator operator--(int)
153 basic_address_iterator tmp(*this);
158 /// Compare two addresses for equality.
159 friend bool operator==(const basic_address_iterator& a,
160 const basic_address_iterator& b)
162 return a.address_ == b.address_;
165 /// Compare two addresses for inequality.
166 friend bool operator!=(const basic_address_iterator& a,
167 const basic_address_iterator& b)
169 return a.address_ != b.address_;
176 /// An input iterator that can be used for traversing IPv6 addresses.
177 typedef basic_address_iterator<address_v6> address_v6_iterator;
183 #include <boost/asio/detail/pop_options.hpp>
185 #endif // BOOST_ASIO_IP_ADDRESS_V6_ITERATOR_HPP