unbounded.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // Copyright Eric Niebler 2014-present
  3. //
  4. // Use, modification and distribution is subject to the
  5. // Boost Software License, Version 1.0. (See accompanying
  6. // file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // Project home: https://github.com/ericniebler/range-v3
  10. //
  11. #ifndef RANGES_V3_VIEW_UNBOUNDED_HPP
  12. #define RANGES_V3_VIEW_UNBOUNDED_HPP
  13. #include <range/v3/range_fwd.hpp>
  14. #include <range/v3/iterator/unreachable_sentinel.hpp>
  15. #include <range/v3/utility/static_const.hpp>
  16. #include <range/v3/view/interface.hpp>
  17. #include <range/v3/detail/prologue.hpp>
  18. namespace ranges
  19. {
  20. /// \addtogroup group-views
  21. /// @{
  22. template<typename I>
  23. struct unbounded_view : view_interface<unbounded_view<I>, infinite>
  24. {
  25. private:
  26. I it_;
  27. public:
  28. unbounded_view() = default;
  29. constexpr explicit unbounded_view(I it)
  30. : it_(detail::move(it))
  31. {}
  32. constexpr I begin() const
  33. {
  34. return it_;
  35. }
  36. constexpr unreachable_sentinel_t end() const
  37. {
  38. return {};
  39. }
  40. };
  41. template<typename I>
  42. RANGES_INLINE_VAR constexpr bool enable_borrowed_range<unbounded_view<I>> = true;
  43. namespace views
  44. {
  45. struct unbounded_fn
  46. {
  47. template(typename I)(
  48. requires input_iterator<I>)
  49. constexpr unbounded_view<I> operator()(I it) const
  50. {
  51. return unbounded_view<I>{detail::move(it)};
  52. }
  53. };
  54. /// \relates unbounded_fn
  55. /// \ingroup group-views
  56. RANGES_INLINE_VARIABLE(unbounded_fn, unbounded)
  57. } // namespace views
  58. /// @}
  59. } // namespace ranges
  60. #include <range/v3/detail/epilogue.hpp>
  61. #include <range/v3/detail/satisfy_boost_range.hpp>
  62. RANGES_SATISFY_BOOST_RANGE(::ranges::unbounded_view)
  63. #endif