Debian Codegraph @

3rd_party/range-v3/range/v3/view/all.hpp

raw
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_ALL_HPP
14 #define RANGES_V3_VIEW_ALL_HPP
15
16 #include <type_traits>
17
18 #include <meta/meta.hpp>
19
20 #include <range/v3/range_fwd.hpp>
21
22 #include <range/v3/range/access.hpp>
23 #include <range/v3/range/concepts.hpp>
24 #include <range/v3/range/primitives.hpp>
25 #include <range/v3/utility/static_const.hpp>
26 #include <range/v3/view/ref.hpp>
27 #include <range/v3/view/subrange.hpp>
28 #include <range/v3/view/view.hpp>
29
30 #include <range/v3/detail/prologue.hpp>
31
32 namespace ranges
33 {
34 /// \addtogroup group-views
35 /// @{
36 namespace views
37 {
38 struct all_fn
39 {
40 private:
41 /// If it's a view already, pass it though.
42 template<typename T>
43 static constexpr auto from_range_(T && t, std::true_type, detail::ignore_t,
44 detail::ignore_t)
45 {
46 return static_cast<T &&>(t);
47 }
48
49 /// If it is container-like, turn it into a view, being careful
50 /// to preserve the Sized-ness of the range.
51 template<typename T>
52 static constexpr auto from_range_(T && t, std::false_type, std::true_type,
53 detail::ignore_t)
54 {
55 return ranges::views::ref(t);
56 }
57
58 /// Not a view and not an lvalue? If it's a borrowed_range, then
59 /// return a subrange holding the range's begin/end.
60 template<typename T>
61 static constexpr auto from_range_(T && t, std::false_type, std::false_type,
62 std::true_type)
63 {
64 return make_subrange(static_cast<T &&>(t));
65 }
66
67 public:
68 template(typename T)(
69 requires range<T &> AND viewable_range<T>)
70 constexpr auto operator()(T && t) const
71 {
72 return all_fn::from_range_(static_cast<T &&>(t),
73 meta::bool_<view_<uncvref_t<T>>>{},
74 std::is_lvalue_reference<T>{},
75 meta::bool_<borrowed_range<T>>{});
76 }
77
78 template<typename T>
79 RANGES_DEPRECATED("Passing a reference_wrapper to views::all is deprecated.")
80 constexpr ref_view<T> operator()(std::reference_wrapper<T> r) const
81 {
82 return ranges::views::ref(r.get());
83 }
84 };
85
86 /// \relates all_fn
87 /// \ingroup group-views
88 RANGES_INLINE_VARIABLE(view_closure<all_fn>, all)
89
90 template<typename Rng>
91 using all_t = decltype(all(std::declval<Rng>()));
92 } // namespace views
93
94 template<typename Rng>
95 struct identity_adaptor : Rng
96 {
97 CPP_assert(view_<Rng>);
98
99 identity_adaptor() = default;
100 constexpr explicit identity_adaptor(Rng const & rng)
101 : Rng(rng)
102 {}
103 constexpr explicit identity_adaptor(Rng && rng)
104 : Rng(detail::move(rng))
105 {}
106 };
107
108 namespace cpp20
109 {
110 namespace views
111 {
112 using ranges::views::all;
113 using ranges::views::all_t;
114 }
115 template(typename Rng)(
116 requires viewable_range<Rng>)
117 using all_view RANGES_DEPRECATED(
118 "Please use ranges::cpp20::views::all_t instead.") =
119 ranges::views::all_t<Rng>;
120 } // namespace cpp20
121 /// @}
122 } // namespace ranges
123
124 #include <range/v3/detail/epilogue.hpp>
125
126 #endif