iterator_traits.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2014-2014.
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // See http://www.boost.org/libs/move for documentation.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11. //! \file
  12. #ifndef BOOST_MOVE_DETAIL_ITERATOR_TRAITS_HPP
  13. #define BOOST_MOVE_DETAIL_ITERATOR_TRAITS_HPP
  14. #ifndef BOOST_CONFIG_HPP
  15. # include <boost/config.hpp>
  16. #endif
  17. #
  18. #if defined(BOOST_HAS_PRAGMA_ONCE)
  19. # pragma once
  20. #endif
  21. #if (BOOST_CXX_VERSION > 201703L) && defined(__cpp_lib_concepts)
  22. #include <iterator>
  23. #define BOOST_MOVE_CONTIGUOUS_ITERATOR_TAG
  24. namespace boost {
  25. namespace movelib {
  26. using std::iterator_traits;
  27. template<class T>
  28. struct iter_difference
  29. {
  30. typedef typename std::iterator_traits<T>::difference_type type;
  31. };
  32. template<class T>
  33. struct iter_value
  34. {
  35. typedef typename std::iterator_traits<T>::value_type type;
  36. };
  37. template<class T>
  38. struct iter_category
  39. {
  40. typedef typename std::iterator_traits<T>::iterator_category type;
  41. };
  42. }} //namespace boost::movelib
  43. #else
  44. #include <cstddef>
  45. #include <boost/move/detail/type_traits.hpp>
  46. #include <boost/move/detail/std_ns_begin.hpp>
  47. BOOST_MOVE_STD_NS_BEG
  48. struct input_iterator_tag;
  49. struct forward_iterator_tag;
  50. struct bidirectional_iterator_tag;
  51. struct random_access_iterator_tag;
  52. struct output_iterator_tag;
  53. #if ( (defined(BOOST_GNU_STDLIB) && (__cplusplus > 201703L))\
  54. || (defined(_LIBCPP_VERSION) && (_LIBCPP_STD_VER > 17))\
  55. || (defined(_YVALS) && defined(_CPPLIB_VER) && defined(__cpp_lib_concepts))\
  56. || (__cplusplus >= 202002L)\
  57. )
  58. # define BOOST_MOVE_CONTIGUOUS_ITERATOR_TAG
  59. struct contiguous_iterator_tag;
  60. #endif
  61. BOOST_MOVE_STD_NS_END
  62. #include <boost/move/detail/std_ns_end.hpp>
  63. namespace boost{ namespace movelib{
  64. template<class T>
  65. struct iter_difference
  66. {
  67. typedef typename T::difference_type type;
  68. };
  69. template<class T>
  70. struct iter_difference<T*>
  71. {
  72. typedef std::ptrdiff_t type;
  73. };
  74. template<class T>
  75. struct iter_value
  76. {
  77. typedef typename T::value_type type;
  78. };
  79. template<class T>
  80. struct iter_value<T*>
  81. {
  82. typedef T type;
  83. };
  84. template<class T>
  85. struct iter_value<const T*>
  86. {
  87. typedef T type;
  88. };
  89. template<class T>
  90. struct iter_category
  91. {
  92. typedef typename T::iterator_category type;
  93. };
  94. template<class T>
  95. struct iter_category<T*>
  96. {
  97. typedef std::random_access_iterator_tag type;
  98. };
  99. template<class Iterator>
  100. struct iterator_traits
  101. {
  102. typedef typename iter_difference<Iterator>::type difference_type;
  103. typedef typename iter_value<Iterator>::type value_type;
  104. typedef typename Iterator::pointer pointer;
  105. typedef typename Iterator::reference reference;
  106. typedef typename iter_category<Iterator>::type iterator_category;
  107. };
  108. template<class T>
  109. struct iterator_traits<T*>
  110. {
  111. typedef std::ptrdiff_t difference_type;
  112. typedef T value_type;
  113. typedef T* pointer;
  114. typedef T& reference;
  115. typedef std::random_access_iterator_tag iterator_category;
  116. };
  117. template<class T>
  118. struct iterator_traits<const T*>
  119. {
  120. typedef std::ptrdiff_t difference_type;
  121. typedef T value_type;
  122. typedef const T* pointer;
  123. typedef const T& reference;
  124. typedef std::random_access_iterator_tag iterator_category;
  125. };
  126. }} //namespace boost::movelib
  127. #endif //
  128. #include <boost/move/detail/type_traits.hpp>
  129. namespace boost {
  130. namespace movelib {
  131. template<class T>
  132. struct iter_size
  133. : boost::move_detail::
  134. make_unsigned<typename iter_difference<T>::type >
  135. {};
  136. }} //namespace boost move_detail {
  137. #endif //#ifndef BOOST_MOVE_DETAIL_ITERATOR_TRAITS_HPP