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_DELIMIT_HPP
0015 #define RANGES_V3_VIEW_DELIMIT_HPP
0016 
0017 #include <meta/meta.hpp>
0018 
0019 #include <range/v3/range_fwd.hpp>
0020 
0021 #include <range/v3/functional/bind_back.hpp>
0022 #include <range/v3/iterator/concepts.hpp>
0023 #include <range/v3/iterator/unreachable_sentinel.hpp>
0024 #include <range/v3/range/concepts.hpp>
0025 #include <range/v3/utility/static_const.hpp>
0026 #include <range/v3/view/adaptor.hpp>
0027 #include <range/v3/view/all.hpp>
0028 #include <range/v3/view/subrange.hpp>
0029 #include <range/v3/view/view.hpp>
0030 
0031 #include <range/v3/detail/prologue.hpp>
0032 
0033 namespace ranges
0034 {
0035     /// \addtogroup group-views
0036     /// @{
0037     template<typename Rng, typename Val>
0038     struct delimit_view
0039       : view_adaptor<delimit_view<Rng, Val>, Rng,
0040                      is_finite<Rng>::value ? finite : unknown>
0041     {
0042     private:
0043         friend range_access;
0044         Val value_;
0045 
0046         struct sentinel_adaptor : adaptor_base
0047         {
0048             sentinel_adaptor() = default;
0049             sentinel_adaptor(Val value)
0050               : value_(std::move(value))
0051             {}
0052             template<class I, class S>
0053             bool empty(I const & it, S const & last) const
0054             {
0055                 return it == last || *it == value_;
0056             }
0057             Val value_;
0058         };
0059 
0060         sentinel_adaptor end_adaptor() const
0061         {
0062             return {value_};
0063         }
0064 
0065     public:
0066         delimit_view() = default;
0067         constexpr delimit_view(Rng rng, Val value)
0068           : delimit_view::view_adaptor{std::move(rng)}
0069           , value_(std::move(value))
0070         {}
0071     };
0072 
0073     // the begin iterator will be an iterator into the underlying view (conditionally
0074     // borrowed) and the end iterator owns the value to be compared against (borrowed)
0075     template<typename Rng, typename Val>
0076     RANGES_INLINE_VAR constexpr bool enable_borrowed_range<delimit_view<Rng, Val>> = //
0077         enable_borrowed_range<Rng>;
0078 
0079 #if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17
0080     template(typename Rng, typename Val)(
0081         requires copy_constructible<Val>)
0082     delimit_view(Rng &&, Val)
0083         -> delimit_view<views::all_t<Rng>, Val>;
0084 #endif
0085 
0086     namespace views
0087     {
0088         struct delimit_base_fn
0089         {
0090             template(typename I_, typename Val, typename I = detail::decay_t<I_>)(
0091                 requires (!range<I_>) AND convertible_to<I_, I> AND input_iterator<I> AND
0092                     semiregular<Val> AND
0093                     equality_comparable_with<Val, iter_reference_t<I>>)
0094             constexpr auto operator()(I_ && begin_, Val value) const
0095                 -> delimit_view<subrange<I, unreachable_sentinel_t>, Val>
0096             {
0097                 return {{static_cast<I_ &&>(begin_), {}}, std::move(value)};
0098             }
0099 
0100             template(typename Rng, typename Val)(
0101                 requires viewable_range<Rng> AND input_range<Rng> AND semiregular<
0102                         Val> AND equality_comparable_with<Val, range_reference_t<Rng>>)
0103             constexpr auto operator()(Rng && rng, Val value) const //
0104                 -> delimit_view<all_t<Rng>, Val>
0105             {
0106                 return {all(static_cast<Rng &&>(rng)), std::move(value)};
0107             }
0108         };
0109 
0110         struct delimit_fn : delimit_base_fn
0111         {
0112             using delimit_base_fn::operator();
0113 
0114             template<typename Val>
0115             constexpr auto operator()(Val value) const
0116             {
0117                 return make_view_closure(bind_back(delimit_base_fn{}, std::move(value)));
0118             }
0119         };
0120 
0121         /// \relates delimit_fn
0122         /// \ingroup group-views
0123         RANGES_INLINE_VARIABLE(delimit_fn, delimit)
0124     } // namespace views
0125     /// @}
0126 } // namespace ranges
0127 
0128 #include <range/v3/detail/epilogue.hpp>
0129 #include <range/v3/detail/satisfy_boost_range.hpp>
0130 RANGES_SATISFY_BOOST_RANGE(::ranges::delimit_view)
0131 
0132 #endif