fwd.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Copyright (C) 2019 T. Zachary Laine
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_STL_INTERFACES_FWD_HPP
  7. #define BOOST_STL_INTERFACES_FWD_HPP
  8. #include <boost/stl_interfaces/config.hpp>
  9. #if BOOST_STL_INTERFACES_USE_CONCEPTS
  10. #include <ranges>
  11. #endif
  12. #if defined(__cpp_lib_three_way_comparison)
  13. #include <compare>
  14. #endif
  15. #ifndef BOOST_STL_INTERFACES_DOXYGEN
  16. #if defined(_MSC_VER) || defined(__GNUC__) && __GNUC__ < 8
  17. #define BOOST_STL_INTERFACES_NO_HIDDEN_FRIEND_CONSTEXPR
  18. #define BOOST_STL_INTERFACES_HIDDEN_FRIEND_CONSTEXPR
  19. #else
  20. #define BOOST_STL_INTERFACES_HIDDEN_FRIEND_CONSTEXPR constexpr
  21. #endif
  22. #if defined(__GNUC__) && __GNUC__ < 9
  23. #define BOOST_STL_INTERFACES_CONCEPT concept bool
  24. #else
  25. #define BOOST_STL_INTERFACES_CONCEPT concept
  26. #endif
  27. #endif
  28. namespace boost { namespace stl_interfaces {
  29. /** An enumeration used to indicate whether the underlying data have a
  30. contiguous or discontiguous layout when instantiating `view_interface`
  31. and `sequence_container_interface`. */
  32. enum class element_layout : bool {
  33. discontiguous = false,
  34. contiguous = true
  35. };
  36. BOOST_STL_INTERFACES_NAMESPACE_V1 {
  37. namespace v1_dtl {
  38. template<typename... T>
  39. using void_t = void;
  40. template<typename Iter>
  41. using iter_difference_t =
  42. typename std::iterator_traits<Iter>::difference_type;
  43. template<typename Range, typename = void>
  44. struct iterator;
  45. template<typename Range>
  46. struct iterator<
  47. Range,
  48. void_t<decltype(std::declval<Range &>().begin())>>
  49. {
  50. using type = decltype(std::declval<Range &>().begin());
  51. };
  52. template<typename Range>
  53. using iterator_t = typename iterator<Range>::type;
  54. template<typename Range, typename = void>
  55. struct sentinel;
  56. template<typename Range>
  57. struct sentinel<
  58. Range,
  59. void_t<decltype(std::declval<Range &>().end())>>
  60. {
  61. using type = decltype(std::declval<Range &>().end());
  62. };
  63. template<typename Range>
  64. using sentinel_t = typename sentinel<Range>::type;
  65. template<typename Range>
  66. using range_difference_t = iter_difference_t<iterator_t<Range>>;
  67. template<typename Range>
  68. using common_range =
  69. std::is_same<iterator_t<Range>, sentinel_t<Range>>;
  70. template<typename Range, typename = void>
  71. struct decrementable_sentinel : std::false_type
  72. {
  73. };
  74. template<typename Range>
  75. struct decrementable_sentinel<
  76. Range,
  77. void_t<decltype(--std::declval<sentinel_t<Range> &>())>>
  78. : std::true_type
  79. {
  80. };
  81. }
  82. }
  83. }}
  84. #endif