You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

traits.hpp 6.4KB

5 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /// \file
  2. // Range v3 library
  3. //
  4. // Copyright Eric Niebler 2013-present
  5. //
  6. // Use, modification and distribution is subject to the
  7. // Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. // Project home: https://github.com/ericniebler/range-v3
  12. //
  13. #ifndef RANGES_V3_ITERATOR_TRAITS_HPP
  14. #define RANGES_V3_ITERATOR_TRAITS_HPP
  15. #include <iterator>
  16. #include <type_traits>
  17. #include <meta/meta.hpp>
  18. #include <concepts/concepts.hpp>
  19. #include <range/v3/range_fwd.hpp>
  20. #include <range/v3/iterator/access.hpp> // for iter_move, iter_swap
  21. #include <range/v3/utility/common_type.hpp>
  22. namespace ranges
  23. {
  24. /// \addtogroup group-iterator
  25. /// @{
  26. /// \cond
  27. using input_iterator_tag RANGES_DEPRECATED(
  28. "Please switch to the standard iterator tags") = std::input_iterator_tag;
  29. using forward_iterator_tag RANGES_DEPRECATED(
  30. "Please switch to the standard iterator tags") = std::forward_iterator_tag;
  31. using bidirectional_iterator_tag RANGES_DEPRECATED(
  32. "Please switch to the standard iterator tags") = std::bidirectional_iterator_tag;
  33. using random_access_iterator_tag RANGES_DEPRECATED(
  34. "Please switch to the standard iterator tags") = std::random_access_iterator_tag;
  35. /// \cond
  36. struct contiguous_iterator_tag : std::random_access_iterator_tag
  37. {};
  38. /// \cond
  39. struct input_iterator_concept;
  40. struct forward_iterator_concept;
  41. struct bidirectional_iterator_concept;
  42. struct random_access_iterator_concept;
  43. struct contiguous_iterator_concept;
  44. namespace detail
  45. {
  46. using input_iterator_tag_ = ::concepts::tag<input_iterator_concept>;
  47. using forward_iterator_tag_ =
  48. ::concepts::tag<forward_iterator_concept, input_iterator_tag_>;
  49. using bidirectional_iterator_tag_ =
  50. ::concepts::tag<bidirectional_iterator_concept, forward_iterator_tag_>;
  51. using random_access_iterator_tag_ =
  52. ::concepts::tag<random_access_iterator_concept, bidirectional_iterator_tag_>;
  53. using contiguous_iterator_tag_ =
  54. ::concepts::tag<contiguous_iterator_concept, random_access_iterator_tag_>;
  55. template<typename I, typename = iter_reference_t<I>,
  56. typename R = decltype(iter_move(std::declval<I &>())), typename = R &>
  57. using iter_rvalue_reference_t = R;
  58. template<typename I>
  59. RANGES_INLINE_VAR constexpr bool has_nothrow_iter_move_v =
  60. noexcept(iter_rvalue_reference_t<I>(ranges::iter_move(std::declval<I &>())));
  61. } // namespace detail
  62. /// \endcond
  63. template<typename I>
  64. using iter_rvalue_reference_t = detail::iter_rvalue_reference_t<I>;
  65. template<typename I>
  66. using iter_common_reference_t =
  67. common_reference_t<iter_reference_t<I>, iter_value_t<I> &>;
  68. #if defined(RANGES_DEEP_STL_INTEGRATION) && RANGES_DEEP_STL_INTEGRATION && \
  69. !defined(RANGES_DOXYGEN_INVOKED)
  70. template<typename T>
  71. using iter_difference_t =
  72. typename detail::if_then_t<detail::is_std_iterator_traits_specialized_v<T>,
  73. std::iterator_traits<T>,
  74. incrementable_traits<T>>::difference_type;
  75. #else
  76. template<typename T>
  77. using iter_difference_t = typename incrementable_traits<T>::difference_type;
  78. #endif
  79. // Defined in <range/v3/iterator/access.hpp>
  80. // template<typename T>
  81. // using iter_value_t = ...
  82. // Defined in <range/v3/iterator/access.hpp>
  83. // template<typename R>
  84. // using iter_reference_t = detail::iter_reference_t_<R>;
  85. // Defined in <range/v3/range_fwd.hpp>:
  86. // template<typename S, typename I>
  87. // inline constexpr bool disable_sized_sentinel = false;
  88. /// \cond
  89. namespace detail
  90. {
  91. template<typename I>
  92. using iter_size_t =
  93. meta::_t<if_then_t<std::is_integral<iter_difference_t<I>>::value,
  94. std::make_unsigned<iter_difference_t<I>>,
  95. meta::id<iter_difference_t<I>>>>;
  96. template<typename I>
  97. using iter_arrow_t = decltype(std::declval<I &>().operator->());
  98. template<typename I>
  99. using iter_pointer_t =
  100. meta::_t<if_then_t<meta::is_trait<meta::defer<iter_arrow_t, I>>::value,
  101. meta::defer<iter_arrow_t, I>,
  102. std::add_pointer<iter_reference_t<I>>>>;
  103. template<typename T>
  104. struct difference_type_ : meta::defer<iter_difference_t, T>
  105. {};
  106. template<typename T>
  107. struct value_type_ : meta::defer<iter_value_t, T>
  108. {};
  109. template<typename T>
  110. struct size_type_ : meta::defer<iter_size_t, T>
  111. {};
  112. } // namespace detail
  113. template<typename T>
  114. using difference_type_t RANGES_DEPRECATED(
  115. "ranges::difference_type_t is deprecated. Please use "
  116. "ranges::iter_difference_t instead.") = iter_difference_t<T>;
  117. template<typename T>
  118. using value_type_t RANGES_DEPRECATED(
  119. "ranges::value_type_t is deprecated. Please use "
  120. "ranges::iter_value_t instead.") = iter_value_t<T>;
  121. template<typename R>
  122. using reference_t RANGES_DEPRECATED(
  123. "ranges::reference_t is deprecated. Use ranges::iter_reference_t "
  124. "instead.") = iter_reference_t<R>;
  125. template<typename I>
  126. using rvalue_reference_t RANGES_DEPRECATED(
  127. "rvalue_reference_t is deprecated; "
  128. "use iter_rvalue_reference_t instead") = iter_rvalue_reference_t<I>;
  129. template<typename T>
  130. struct RANGES_DEPRECATED(
  131. "ranges::size_type is deprecated. Iterators do not have an associated "
  132. "size_type.") size_type : detail::size_type_<T>
  133. {};
  134. template<typename I>
  135. using size_type_t RANGES_DEPRECATED("size_type_t is deprecated.") =
  136. detail::iter_size_t<I>;
  137. /// \endcond
  138. namespace cpp20
  139. {
  140. using ranges::iter_common_reference_t;
  141. using ranges::iter_difference_t;
  142. using ranges::iter_reference_t;
  143. using ranges::iter_rvalue_reference_t;
  144. using ranges::iter_value_t;
  145. // Specialize these in the ranges:: namespace
  146. using ranges::disable_sized_sentinel;
  147. template<typename T>
  148. using incrementable_traits = ranges::incrementable_traits<T>;
  149. template<typename T>
  150. using readable_traits = ranges::readable_traits<T>;
  151. } // namespace cpp20
  152. /// @}
  153. } // namespace ranges
  154. #endif // RANGES_V3_ITERATOR_TRAITS_HPP