Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /// \file
0002 // Range v3 library
0003 //
0004 //  Copyright Eric Niebler 2013-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 
0014 #ifndef RANGES_V3_VIEW_CONST_HPP
0015 #define RANGES_V3_VIEW_CONST_HPP
0016 
0017 #include <type_traits>
0018 #include <utility>
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/common_type.hpp>
0026 #include <range/v3/utility/move.hpp>
0027 #include <range/v3/utility/static_const.hpp>
0028 #include <range/v3/view/adaptor.hpp>
0029 #include <range/v3/view/all.hpp>
0030 #include <range/v3/view/view.hpp>
0031 
0032 #include <range/v3/detail/prologue.hpp>
0033 
0034 namespace ranges
0035 {
0036     /// \addtogroup group-views
0037     /// @{
0038     template<typename Rng>
0039     struct const_view : view_adaptor<const_view<Rng>, Rng>
0040     {
0041     private:
0042         friend range_access;
0043         template<bool Const>
0044         struct adaptor : adaptor_base
0045         {
0046             using CRng = meta::const_if_c<Const, Rng>;
0047             using value_ = range_value_t<CRng>;
0048             using reference_ =
0049                 common_reference_t<value_ const &&, range_reference_t<CRng>>;
0050             using rvalue_reference_ =
0051                 common_reference_t<value_ const &&, range_rvalue_reference_t<CRng>>;
0052             adaptor() = default;
0053             template(bool Other)(
0054                 requires Const && CPP_NOT(Other)) //
0055                 constexpr adaptor(adaptor<Other>)
0056             {}
0057             reference_ read(iterator_t<CRng> const & it) const
0058             {
0059                 return *it;
0060             }
0061             rvalue_reference_ iter_move(iterator_t<CRng> const & it) const
0062                 noexcept(noexcept(rvalue_reference_(ranges::iter_move(it))))
0063             {
0064                 return ranges::iter_move(it);
0065             }
0066         };
0067         adaptor<simple_view<Rng>()> begin_adaptor()
0068         {
0069             return {};
0070         }
0071         CPP_member
0072         auto begin_adaptor() const //
0073             -> CPP_ret(adaptor<true>)(
0074                 requires range<Rng const>)
0075         {
0076             return {};
0077         }
0078         adaptor<simple_view<Rng>()> end_adaptor()
0079         {
0080             return {};
0081         }
0082         CPP_member
0083         auto end_adaptor() const //
0084             -> CPP_ret(adaptor<true>)(
0085                 requires range<Rng const>)
0086         {
0087             return {};
0088         }
0089 
0090     public:
0091         const_view() = default;
0092         explicit const_view(Rng rng)
0093           : const_view::view_adaptor{std::move(rng)}
0094         {}
0095         CPP_auto_member
0096         constexpr auto CPP_fun(size)()(
0097             requires sized_range<Rng>)
0098         {
0099             return ranges::size(this->base());
0100         }
0101         CPP_auto_member
0102         constexpr auto CPP_fun(size)()(const
0103             requires sized_range<Rng const>)
0104         {
0105             return ranges::size(this->base());
0106         }
0107     };
0108 
0109     template<typename Rng>
0110     RANGES_INLINE_VAR constexpr bool enable_borrowed_range<const_view<Rng>> = //
0111         enable_borrowed_range<Rng>;
0112 
0113 #if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17
0114     template<typename Rng>
0115     const_view(Rng &&) //
0116         -> const_view<views::all_t<Rng>>;
0117 #endif
0118 
0119     namespace views
0120     {
0121         struct const_fn
0122         {
0123             template(typename Rng)(
0124                 requires viewable_range<Rng> AND input_range<Rng>)
0125             const_view<all_t<Rng>> operator()(Rng && rng) const
0126             {
0127                 return const_view<all_t<Rng>>{all(static_cast<Rng &&>(rng))};
0128             }
0129         };
0130 
0131         /// \relates const_fn
0132         /// \ingroup group-views
0133         RANGES_INLINE_VARIABLE(view_closure<const_fn>, const_)
0134     } // namespace views
0135     /// @}
0136 } // namespace ranges
0137 
0138 #include <range/v3/detail/epilogue.hpp>
0139 #include <range/v3/detail/satisfy_boost_range.hpp>
0140 RANGES_SATISFY_BOOST_RANGE(::ranges::const_view)
0141 
0142 #endif