1//
2// ip/address_v6_range.hpp
3// ~~~~~~~~~~~~~~~~~~~~~~~
4//
5// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6// Oliver Kowalke (oliver dot kowalke at gmail dot com)
7//
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)
10//
11
12#ifndef BOOST_ASIO_IP_ADDRESS_V6_RANGE_HPP
13#define BOOST_ASIO_IP_ADDRESS_V6_RANGE_HPP
14
15#if defined(_MSC_VER) && (_MSC_VER >= 1200)
16# pragma once
17#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18
19#include <boost/asio/detail/config.hpp>
20#include <boost/asio/ip/address_v6_iterator.hpp>
21
22#include <boost/asio/detail/push_options.hpp>
23
24namespace boost {
25namespace asio {
26namespace ip {
27
28template <typename> class basic_address_range;
29
30/// Represents a range of IPv6 addresses.
31/**
32 * @par Thread Safety
33 * @e Distinct @e objects: Safe.@n
34 * @e Shared @e objects: Unsafe.
35 */
36template <> class basic_address_range<address_v6>
37{
38public:
39 /// The type of an iterator that points into the range.
40 typedef basic_address_iterator<address_v6> iterator;
41
42 /// Construct an empty range.
43 basic_address_range() noexcept
44 : begin_(address_v6()),
45 end_(address_v6())
46 {
47 }
48
49 /// Construct an range that represents the given range of addresses.
50 explicit basic_address_range(const iterator& first,
51 const iterator& last) noexcept
52 : begin_(first),
53 end_(last)
54 {
55 }
56
57 /// Copy constructor.
58 basic_address_range(const basic_address_range& other) noexcept
59 : begin_(other.begin_),
60 end_(other.end_)
61 {
62 }
63
64 /// Move constructor.
65 basic_address_range(basic_address_range&& other) noexcept
66 : begin_(static_cast<iterator&&>(other.begin_)),
67 end_(static_cast<iterator&&>(other.end_))
68 {
69 }
70
71 /// Assignment operator.
72 basic_address_range& operator=(
73 const basic_address_range& other) noexcept
74 {
75 begin_ = other.begin_;
76 end_ = other.end_;
77 return *this;
78 }
79
80 /// Move assignment operator.
81 basic_address_range& operator=(basic_address_range&& other) noexcept
82 {
83 begin_ = static_cast<iterator&&>(other.begin_);
84 end_ = static_cast<iterator&&>(other.end_);
85 return *this;
86 }
87
88 /// Obtain an iterator that points to the start of the range.
89 iterator begin() const noexcept
90 {
91 return begin_;
92 }
93
94 /// Obtain an iterator that points to the end of the range.
95 iterator end() const noexcept
96 {
97 return end_;
98 }
99
100 /// Determine whether the range is empty.
101 bool empty() const noexcept
102 {
103 return begin_ == end_;
104 }
105
106 /// Find an address in the range.
107 iterator find(const address_v6& addr) const noexcept
108 {
109 return addr >= *begin_ && addr < *end_ ? iterator(addr) : end_;
110 }
111
112private:
113 iterator begin_;
114 iterator end_;
115};
116
117/// Represents a range of IPv6 addresses.
118typedef basic_address_range<address_v6> address_v6_range;
119
120} // namespace ip
121} // namespace asio
122} // namespace boost
123
124#include <boost/asio/detail/pop_options.hpp>
125
126#endif // BOOST_ASIO_IP_ADDRESS_V6_RANGE_HPP
127

source code of boost/libs/asio/include/boost/asio/ip/address_v6_range.hpp