fwd.hpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 <iterator>
  9. #ifndef BOOST_STL_INTERFACES_DOXYGEN
  10. #if defined(_MSC_VER) || defined(__GNUC__) && __GNUC__ < 8
  11. #define BOOST_STL_INTERFACES_NO_HIDDEN_FRIEND_CONSTEXPR
  12. #define BOOST_STL_INTERFACES_HIDDEN_FRIEND_CONSTEXPR
  13. #else
  14. #define BOOST_STL_INTERFACES_HIDDEN_FRIEND_CONSTEXPR constexpr
  15. #endif
  16. #if defined(__GNUC__) && __GNUC__ < 9
  17. #define BOOST_STL_INTERFACES_CONCEPT concept bool
  18. #else
  19. #define BOOST_STL_INTERFACES_CONCEPT concept
  20. #endif
  21. #endif
  22. namespace boost { namespace stl_interfaces {
  23. inline namespace v1 {
  24. /** An enumeration used to indicate whether the underlying data have a
  25. contiguous or discontiguous layout when instantiating
  26. `view_interface` and `sequence_container_interface`. */
  27. enum class element_layout : bool {
  28. discontiguous = false,
  29. contiguous = true
  30. };
  31. namespace v1_dtl {
  32. template<typename... T>
  33. using void_t = void;
  34. template<typename Iter>
  35. using iter_difference_t =
  36. typename std::iterator_traits<Iter>::difference_type;
  37. template<typename Range, typename = void>
  38. struct iterator;
  39. template<typename Range>
  40. struct iterator<
  41. Range,
  42. void_t<decltype(std::declval<Range &>().begin())>>
  43. {
  44. using type = decltype(std::declval<Range &>().begin());
  45. };
  46. template<typename Range>
  47. using iterator_t = typename iterator<Range>::type;
  48. template<typename Range, typename = void>
  49. struct sentinel;
  50. template<typename Range>
  51. struct sentinel<
  52. Range,
  53. void_t<decltype(std::declval<Range &>().end())>>
  54. {
  55. using type = decltype(std::declval<Range &>().end());
  56. };
  57. template<typename Range>
  58. using sentinel_t = typename sentinel<Range>::type;
  59. template<typename Range>
  60. using range_difference_t = iter_difference_t<iterator_t<Range>>;
  61. template<typename Range>
  62. using common_range =
  63. std::is_same<iterator_t<Range>, sentinel_t<Range>>;
  64. template<typename Range, typename = void>
  65. struct decrementable_sentinel : std::false_type
  66. {
  67. };
  68. template<typename Range>
  69. struct decrementable_sentinel<
  70. Range,
  71. void_t<decltype(--std::declval<sentinel_t<Range> &>())>>
  72. : std::true_type
  73. {
  74. };
  75. }
  76. }
  77. }}
  78. #endif