address_v6_range.hpp 2.9 KB

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