2 // ip/address_v4_range.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_RANGE_HPP
12 #define BOOST_ASIO_IP_ADDRESS_V4_RANGE_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_iterator.hpp>
21 #include <boost/asio/detail/push_options.hpp>
27 template <typename> class basic_address_range;
29 /// Represents a range of IPv4 addresses.
32 * @e Distinct @e objects: Safe.@n
33 * @e Shared @e objects: Unsafe.
35 template <> class basic_address_range<address_v4>
38 /// The type of an iterator that points into the range.
39 typedef basic_address_iterator<address_v4> iterator;
41 /// Construct an empty range.
42 basic_address_range() BOOST_ASIO_NOEXCEPT
43 : begin_(address_v4()),
48 /// Construct an range that represents the given range of addresses.
49 explicit basic_address_range(const iterator& first,
50 const iterator& last) BOOST_ASIO_NOEXCEPT
57 basic_address_range(const basic_address_range& other) BOOST_ASIO_NOEXCEPT
58 : begin_(other.begin_),
63 #if defined(BOOST_ASIO_HAS_MOVE)
65 basic_address_range(basic_address_range&& other) BOOST_ASIO_NOEXCEPT
66 : begin_(BOOST_ASIO_MOVE_CAST(iterator)(other.begin_)),
67 end_(BOOST_ASIO_MOVE_CAST(iterator)(other.end_))
70 #endif // defined(BOOST_ASIO_HAS_MOVE)
72 /// Assignment operator.
73 basic_address_range& operator=(
74 const basic_address_range& other) BOOST_ASIO_NOEXCEPT
76 begin_ = other.begin_;
81 #if defined(BOOST_ASIO_HAS_MOVE)
82 /// Move assignment operator.
83 basic_address_range& operator=(
84 basic_address_range&& other) BOOST_ASIO_NOEXCEPT
86 begin_ = BOOST_ASIO_MOVE_CAST(iterator)(other.begin_);
87 end_ = BOOST_ASIO_MOVE_CAST(iterator)(other.end_);
90 #endif // defined(BOOST_ASIO_HAS_MOVE)
92 /// Obtain an iterator that points to the start of the range.
93 iterator begin() const BOOST_ASIO_NOEXCEPT
98 /// Obtain an iterator that points to the end of the range.
99 iterator end() const BOOST_ASIO_NOEXCEPT
104 /// Determine whether the range is empty.
105 bool empty() const BOOST_ASIO_NOEXCEPT
110 /// Return the size of the range.
111 std::size_t size() const BOOST_ASIO_NOEXCEPT
113 return end_->to_uint() - begin_->to_uint();
116 /// Find an address in the range.
117 iterator find(const address_v4& addr) const BOOST_ASIO_NOEXCEPT
119 return addr >= *begin_ && addr < *end_ ? iterator(addr) : end_;
127 /// Represents a range of IPv4 addresses.
128 typedef basic_address_range<address_v4> address_v4_range;
134 #include <boost/asio/detail/pop_options.hpp>
136 #endif // BOOST_ASIO_IP_ADDRESS_V4_RANGE_HPP