Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:09:54

0001 /// \file
0002 // Range v3 library
0003 //
0004 //  Copyright Eric Niebler 2014-present
0005 //
0006 //  Use, modification and distribution is subject to the
0007 //  Boost Software License, Version 1.0. (See accompanying
0008 //  file LICENSE_1_0.txt or copy at
0009 //  http://www.boost.org/LICENSE_1_0.txt)
0010 //
0011 // Project home: https://github.com/ericniebler/range-v3
0012 //
0013 #ifndef RANGES_V3_VIEW_ALL_HPP
0014 #define RANGES_V3_VIEW_ALL_HPP
0015 
0016 #include <type_traits>
0017 
0018 #include <meta/meta.hpp>
0019 
0020 #include <range/v3/range_fwd.hpp>
0021 
0022 #include <range/v3/range/access.hpp>
0023 #include <range/v3/range/concepts.hpp>
0024 #include <range/v3/range/primitives.hpp>
0025 #include <range/v3/utility/static_const.hpp>
0026 #include <range/v3/view/ref.hpp>
0027 #include <range/v3/view/subrange.hpp>
0028 #include <range/v3/view/view.hpp>
0029 
0030 #include <range/v3/detail/prologue.hpp>
0031 
0032 namespace ranges
0033 {
0034     /// \addtogroup group-views
0035     /// @{
0036     namespace views
0037     {
0038         struct all_fn
0039         {
0040         private:
0041             /// If it's a view already, pass it though.
0042             template<typename T>
0043             static constexpr auto from_range_(T && t, std::true_type, detail::ignore_t,
0044                                               detail::ignore_t)
0045             {
0046                 return static_cast<T &&>(t);
0047             }
0048 
0049             /// If it is container-like, turn it into a view, being careful
0050             /// to preserve the Sized-ness of the range.
0051             template<typename T>
0052             static constexpr auto from_range_(T && t, std::false_type, std::true_type,
0053                                               detail::ignore_t)
0054             {
0055                 return ranges::views::ref(t);
0056             }
0057 
0058             /// Not a view and not an lvalue? If it's a borrowed_range, then
0059             /// return a subrange holding the range's begin/end.
0060             template<typename T>
0061             static constexpr auto from_range_(T && t, std::false_type, std::false_type,
0062                                               std::true_type)
0063             {
0064                 return make_subrange(static_cast<T &&>(t));
0065             }
0066 
0067         public:
0068             template(typename T)(
0069                 requires range<T &> AND viewable_range<T>)
0070             constexpr auto operator()(T && t) const
0071             {
0072                 return all_fn::from_range_(static_cast<T &&>(t),
0073                                            meta::bool_<view_<uncvref_t<T>>>{},
0074                                            std::is_lvalue_reference<T>{},
0075                                            meta::bool_<borrowed_range<T>>{});
0076             }
0077 
0078             template<typename T>
0079             RANGES_DEPRECATED("Passing a reference_wrapper to views::all is deprecated.")
0080             constexpr ref_view<T> operator()(std::reference_wrapper<T> r) const
0081             {
0082                 return ranges::views::ref(r.get());
0083             }
0084         };
0085 
0086         /// \relates all_fn
0087         /// \ingroup group-views
0088         RANGES_INLINE_VARIABLE(view_closure<all_fn>, all)
0089 
0090         template<typename Rng>
0091         using all_t = decltype(all(std::declval<Rng>()));
0092     } // namespace views
0093 
0094     template<typename Rng>
0095     struct identity_adaptor : Rng
0096     {
0097         CPP_assert(view_<Rng>);
0098 
0099         identity_adaptor() = default;
0100         constexpr explicit identity_adaptor(Rng const & rng)
0101           : Rng(rng)
0102         {}
0103         constexpr explicit identity_adaptor(Rng && rng)
0104           : Rng(detail::move(rng))
0105         {}
0106     };
0107 
0108     namespace cpp20
0109     {
0110         namespace views
0111         {
0112             using ranges::views::all;
0113             using ranges::views::all_t;
0114         }
0115         template(typename Rng)(
0116             requires viewable_range<Rng>)
0117         using all_view RANGES_DEPRECATED(
0118             "Please use ranges::cpp20::views::all_t instead.") =
0119                 ranges::views::all_t<Rng>;
0120     } // namespace cpp20
0121     /// @}
0122 } // namespace ranges
0123 
0124 #include <range/v3/detail/epilogue.hpp>
0125 
0126 #endif