Horizon
delimit.hpp
Go to the documentation of this file.
1 // 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 
14 #ifndef RANGES_V3_VIEW_DELIMIT_HPP
15 #define RANGES_V3_VIEW_DELIMIT_HPP
16 
17 #include <meta/meta.hpp>
18 
19 #include <range/v3/range_fwd.hpp>
20 
25 #include <range/v3/utility/static_const.hpp>
27 #include <range/v3/view/all.hpp>
29 #include <range/v3/view/view.hpp>
30 
31 #include <range/v3/detail/prologue.hpp>
32 
33 namespace ranges
34 {
37  template<typename Rng, typename Val>
38  struct delimit_view
39  : view_adaptor<delimit_view<Rng, Val>, Rng,
40  is_finite<Rng>::value ? finite : unknown>
41  {
42  private:
43  friend range_access;
44  Val value_;
45 
46  struct sentinel_adaptor : adaptor_base
47  {
48  sentinel_adaptor() = default;
49  sentinel_adaptor(Val value)
50  : value_(std::move(value))
51  {}
52  template<class I, class S>
53  bool empty(I const & it, S const & last) const
54  {
55  return it == last || *it == value_;
56  }
57  Val value_;
58  };
59 
60  sentinel_adaptor end_adaptor() const
61  {
62  return {value_};
63  }
64 
65  public:
66  delimit_view() = default;
67  constexpr delimit_view(Rng rng, Val value)
68  : delimit_view::view_adaptor{std::move(rng)}
69  , value_(std::move(value))
70  {}
71  };
72 
73  // the begin iterator will be an iterator into the underlying view (conditionally
74  // borrowed) and the end iterator owns the value to be compared against (borrowed)
75  template<typename Rng, typename Val>
76  RANGES_INLINE_VAR constexpr bool enable_borrowed_range<delimit_view<Rng, Val>> = //
77  enable_borrowed_range<Rng>;
78 
79 #if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17
80  template(typename Rng, typename Val)(
81  requires copy_constructible<Val>)
82  delimit_view(Rng &&, Val)
84 #endif
85 
86  namespace views
87  {
89  {
90  template(typename I_, typename Val, typename I = detail::decay_t<I_>)(
91  requires (!range<I_>) AND convertible_to<I_, I> AND input_iterator<I> AND
92  semiregular<Val> AND
93  equality_comparable_with<Val, iter_reference_t<I>>)
94  constexpr auto operator()(I_ && begin_, Val value) const
96  {
97  return {{static_cast<I_ &&>(begin_), {}}, std::move(value)};
98  }
99 
100  template(typename Rng, typename Val)(
101  requires viewable_range<Rng> AND input_range<Rng> AND semiregular<
102  Val> AND equality_comparable_with<Val, range_reference_t<Rng>>)
103  constexpr auto operator()(Rng && rng, Val value) const //
104  -> delimit_view<all_t<Rng>, Val>
105  {
106  return {all(static_cast<Rng &&>(rng)), std::move(value)};
107  }
108  };
109 
111  {
112  using delimit_base_fn::operator();
113 
114  template<typename Val>
115  constexpr auto operator()(Val value) const
116  {
117  return make_view_closure(bind_back(delimit_base_fn{}, std::move(value)));
118  }
119  };
120 
124  } // namespace views
126 } // namespace ranges
127 
128 #include <range/v3/detail/epilogue.hpp>
129 #include <range/v3/detail/satisfy_boost_range.hpp>
130 RANGES_SATISFY_BOOST_RANGE(::ranges::delimit_view)
131 
132 #endif
RANGES_INLINE_VARIABLE(detail::to_container_fn< detail::from_range< std::vector >>, to_vector) template< template< typename... > class ContT > auto to(RANGES_HIDDEN_DETAIL(detail
For initializing a container of the specified type with the elements of an Range.
Definition: conversion.hpp:399
defer< bind_back, Fn, Ts... > bind_back
Definition: meta.hpp:994
Tiny meta-programming library.
Definition: adaptor.hpp:110
Definition: delimit.hpp:41
Definition: subrange.hpp:196
Definition: adaptor.hpp:475
constexpr CPP_member auto empty() const noexcept -> CPP_ret(bool)(requires(detail::has_fixed_size_< Cardinality >))
Test whether a range can be empty:
Definition: interface.hpp:154
Definition: delimit.hpp:89
Definition: delimit.hpp:111