File indexing completed on 2025-01-18 10:09:55
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef RANGES_V3_VIEW_DROP_WHILE_HPP
0015 #define RANGES_V3_VIEW_DROP_WHILE_HPP
0016
0017 #include <utility>
0018
0019 #include <meta/meta.hpp>
0020
0021 #include <range/v3/range_fwd.hpp>
0022
0023 #include <range/v3/algorithm/find_if_not.hpp>
0024 #include <range/v3/functional/bind_back.hpp>
0025 #include <range/v3/functional/compose.hpp>
0026 #include <range/v3/range/concepts.hpp>
0027 #include <range/v3/range/traits.hpp>
0028 #include <range/v3/utility/optional.hpp>
0029 #include <range/v3/utility/semiregular_box.hpp>
0030 #include <range/v3/utility/static_const.hpp>
0031 #include <range/v3/view/all.hpp>
0032 #include <range/v3/view/interface.hpp>
0033 #include <range/v3/view/view.hpp>
0034
0035 #include <range/v3/detail/prologue.hpp>
0036
0037 namespace ranges
0038 {
0039
0040
0041 template<typename Rng, typename Pred>
0042 struct drop_while_view
0043 : view_interface<drop_while_view<Rng, Pred>,
0044 is_finite<Rng>::value ? finite : unknown>
0045 {
0046 private:
0047 Rng rng_;
0048 RANGES_NO_UNIQUE_ADDRESS semiregular_box_t<Pred> pred_;
0049 detail::non_propagating_cache<iterator_t<Rng>> begin_;
0050
0051 iterator_t<Rng> get_begin_()
0052 {
0053 if(!begin_)
0054 begin_ = find_if_not(rng_, std::ref(pred_));
0055 return *begin_;
0056 }
0057
0058 public:
0059 drop_while_view() = default;
0060 drop_while_view(Rng rng, Pred pred)
0061 : rng_(std::move(rng))
0062 , pred_(std::move(pred))
0063 {}
0064 iterator_t<Rng> begin()
0065 {
0066 return get_begin_();
0067 }
0068 sentinel_t<Rng> end()
0069 {
0070 return ranges::end(rng_);
0071 }
0072 Rng base() const
0073 {
0074 return rng_;
0075 }
0076 };
0077
0078
0079
0080 template<typename Rng, typename Pred>
0081 RANGES_INLINE_VAR constexpr bool enable_borrowed_range<drop_while_view<Rng, Pred>> =
0082 enable_borrowed_range<Rng>;
0083
0084 #if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17
0085 template(typename Rng, typename Fun)(
0086 requires copy_constructible<Fun>)
0087 drop_while_view(Rng &&, Fun)
0088 -> drop_while_view<views::all_t<Rng>, Fun>;
0089 #endif
0090
0091 template<typename Rng, typename Pred>
0092 RANGES_INLINE_VAR constexpr bool disable_sized_range<drop_while_view<Rng, Pred>> =
0093 true;
0094
0095 namespace views
0096 {
0097 struct drop_while_base_fn
0098 {
0099 template(typename Rng, typename Pred)(
0100 requires viewable_range<Rng> AND input_range<Rng> AND
0101 indirect_unary_predicate<Pred, iterator_t<Rng>>)
0102 auto operator()(Rng && rng, Pred pred) const
0103 -> drop_while_view<all_t<Rng>, Pred>
0104 {
0105 return {all(static_cast<Rng &&>(rng)), std::move(pred)};
0106 }
0107 template(typename Rng, typename Pred, typename Proj)(
0108 requires viewable_range<Rng> AND input_range<Rng> AND
0109 indirect_unary_predicate<composed<Pred, Proj>, iterator_t<Rng>>)
0110 auto operator()(Rng && rng, Pred pred, Proj proj) const
0111 -> drop_while_view<all_t<Rng>, composed<Pred, Proj>>
0112 {
0113 return {all(static_cast<Rng &&>(rng)),
0114 compose(std::move(pred), std::move(proj))};
0115 }
0116 };
0117
0118 struct drop_while_bind_fn
0119 {
0120 template<typename Pred>
0121 constexpr auto operator()(Pred pred) const
0122 {
0123 return make_view_closure(
0124 bind_back(drop_while_base_fn{}, std::move(pred)));
0125 }
0126 template(typename Pred, typename Proj)(
0127 requires (!range<Pred>))
0128 constexpr auto operator()(Pred && pred, Proj proj) const
0129 {
0130 return make_view_closure(bind_back(
0131 drop_while_base_fn{}, static_cast<Pred &&>(pred), std::move(proj)));
0132 }
0133 };
0134
0135 struct RANGES_EMPTY_BASES drop_while_fn
0136 : drop_while_base_fn, drop_while_bind_fn
0137 {
0138 using drop_while_base_fn::operator();
0139 using drop_while_bind_fn::operator();
0140 };
0141
0142
0143
0144 RANGES_INLINE_VARIABLE(drop_while_fn, drop_while)
0145 }
0146
0147 namespace cpp20
0148 {
0149 namespace views
0150 {
0151 using ranges::views::drop_while;
0152 }
0153 template(typename Rng, typename Pred)(
0154 requires viewable_range<Rng> AND input_range<Rng> AND
0155 indirect_unary_predicate<Pred, iterator_t<Rng>>)
0156 using drop_while_view = ranges::drop_while_view<Rng, Pred>;
0157 }
0158
0159 }
0160
0161 #include <range/v3/detail/epilogue.hpp>
0162 #include <range/v3/detail/satisfy_boost_range.hpp>
0163 RANGES_SATISFY_BOOST_RANGE(::ranges::drop_while_view)
0164
0165 #endif