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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /// \file
  2. // Range v3 library
  3. //
  4. // Copyright Eric Niebler 2013-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_MOVE_HPP
  14. #define RANGES_V3_VIEW_MOVE_HPP
  15. #include <type_traits>
  16. #include <utility>
  17. #include <range/v3/range_fwd.hpp>
  18. #include <range/v3/range/access.hpp>
  19. #include <range/v3/range/concepts.hpp>
  20. #include <range/v3/range/primitives.hpp>
  21. #include <range/v3/range/traits.hpp>
  22. #include <range/v3/utility/static_const.hpp>
  23. #include <range/v3/view/adaptor.hpp>
  24. #include <range/v3/view/all.hpp>
  25. #include <range/v3/view/view.hpp>
  26. namespace ranges
  27. {
  28. /// \addtogroup group-views
  29. /// @{
  30. template<typename Rng>
  31. struct move_view : view_adaptor<move_view<Rng>, Rng>
  32. {
  33. private:
  34. friend range_access;
  35. template<bool Const>
  36. struct adaptor : adaptor_base
  37. {
  38. adaptor() = default;
  39. CPP_template(bool Other)( //
  40. requires Const && (!Other)) constexpr adaptor(adaptor<Other>)
  41. {}
  42. using CRng = meta::const_if_c<Const, Rng>;
  43. using value_type = range_value_t<Rng>;
  44. range_rvalue_reference_t<CRng> read(iterator_t<CRng> const & it) const
  45. {
  46. return ranges::iter_move(it);
  47. }
  48. range_rvalue_reference_t<CRng> iter_move(iterator_t<CRng> const & it) const
  49. {
  50. return ranges::iter_move(it);
  51. }
  52. };
  53. adaptor<simple_view<Rng>()> begin_adaptor()
  54. {
  55. return {};
  56. }
  57. adaptor<simple_view<Rng>()> end_adaptor()
  58. {
  59. return {};
  60. }
  61. CPP_member
  62. auto begin_adaptor() const -> CPP_ret(adaptor<true>)( //
  63. requires input_range<Rng const>)
  64. {
  65. return {};
  66. }
  67. CPP_member
  68. auto end_adaptor() const -> CPP_ret(adaptor<true>)( //
  69. requires input_range<Rng const>)
  70. {
  71. return {};
  72. }
  73. public:
  74. move_view() = default;
  75. explicit move_view(Rng rng)
  76. : move_view::view_adaptor{std::move(rng)}
  77. {}
  78. CPP_member
  79. auto CPP_fun(size)()(const requires sized_range<Rng const>)
  80. {
  81. return ranges::size(this->base());
  82. }
  83. CPP_member
  84. auto CPP_fun(size)()(requires sized_range<Rng>)
  85. {
  86. return ranges::size(this->base());
  87. }
  88. };
  89. #if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17
  90. template<typename Rng>
  91. move_view(Rng &&)->move_view<views::all_t<Rng>>;
  92. #endif
  93. namespace views
  94. {
  95. struct move_fn
  96. {
  97. template<typename Rng>
  98. auto operator()(Rng && rng) const -> CPP_ret(move_view<all_t<Rng>>)( //
  99. requires viewable_range<Rng> && input_range<Rng>)
  100. {
  101. return move_view<all_t<Rng>>{all(static_cast<Rng &&>(rng))};
  102. }
  103. };
  104. /// \relates move_fn
  105. /// \ingroup group-views
  106. RANGES_INLINE_VARIABLE(view<move_fn>, move)
  107. } // namespace views
  108. /// @}
  109. } // namespace ranges
  110. #include <range/v3/detail/satisfy_boost_range.hpp>
  111. RANGES_SATISFY_BOOST_RANGE(::ranges::move_view)
  112. #endif