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.

empty.hpp 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /// \file
  2. // Range v3 library
  3. //
  4. // Copyright Eric Niebler 2014-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_VIEW_EMPTY_HPP
  14. #define RANGES_V3_VIEW_EMPTY_HPP
  15. #include <range/v3/range_fwd.hpp>
  16. #include <range/v3/view/interface.hpp>
  17. namespace ranges
  18. {
  19. /// \cond
  20. namespace detail
  21. {
  22. struct empty_view_base
  23. {
  24. template<typename T>
  25. friend constexpr T * begin(empty_view<T>) noexcept
  26. {
  27. return nullptr;
  28. }
  29. template<typename T>
  30. friend constexpr T * end(empty_view<T>) noexcept
  31. {
  32. return nullptr;
  33. }
  34. };
  35. } // namespace detail
  36. /// \endcond
  37. template<typename T>
  38. struct empty_view
  39. : view_interface<empty_view<T>, (cardinality)0>
  40. , private detail::empty_view_base
  41. {
  42. static_assert(std::is_object<T>::value,
  43. "The template parameter to empty_view must be an object type.");
  44. empty_view() = default;
  45. constexpr static T * begin() noexcept
  46. {
  47. return nullptr;
  48. }
  49. constexpr static T * end() noexcept
  50. {
  51. return nullptr;
  52. }
  53. static constexpr std::size_t size() noexcept
  54. {
  55. return 0u;
  56. }
  57. static constexpr T * data() noexcept
  58. {
  59. return nullptr;
  60. }
  61. RANGES_DEPRECATED(
  62. "Replace views::empty<T>() with views::empty<>. "
  63. "It is now a variable template.")
  64. empty_view operator()() const
  65. {
  66. return *this;
  67. }
  68. };
  69. namespace views
  70. {
  71. template<typename T>
  72. RANGES_INLINE_VAR constexpr empty_view<T> empty{};
  73. }
  74. namespace cpp20
  75. {
  76. namespace views
  77. {
  78. using ranges::views::empty;
  79. }
  80. CPP_template(typename T)( //
  81. requires std::is_object<T>::value) //
  82. using empty_view = ranges::empty_view<T>;
  83. } // namespace cpp20
  84. } // namespace ranges
  85. #include <range/v3/detail/satisfy_boost_range.hpp>
  86. RANGES_SATISFY_BOOST_RANGE(::ranges::empty_view)
  87. #endif