VCCC  2024.05
VisualCamp Common C++ library
drop_while_view.hpp
Go to the documentation of this file.
1 //
2 // Created by YongGyu Lee on 2/13/24.
3 //
4 
5 #ifndef VCCC_RANGES_VIEWS_DROP_WHILE_VIEW_HPP_
6 #define VCCC_RANGES_VIEWS_DROP_WHILE_VIEW_HPP_
7 
8 #include <functional>
9 #include <type_traits>
10 
15 #include "vccc/__ranges/end.hpp"
20 #include "vccc/__ranges/view.hpp"
25 
26 namespace vccc {
27 namespace ranges {
28 
31 
32 template<typename V, typename Pred>
33 class drop_while_view : public view_interface<drop_while_view<V, Pred>> {
34  public:
35  static_assert(view<V>::value, "Constraints not satisfied");
36  static_assert(input_range<V>::value, "Constraints not satisfied");
37  static_assert(std::is_object<Pred>::value, "Constraints not satisfied");
38  static_assert(indirect_unary_predicate<const Pred, iterator_t<V>>::value, "Constraints not satisfied");
39 
40  drop_while_view() = default;
41 
42  constexpr explicit drop_while_view(V base, Pred pred)
43  : base_(std::move(base)), pred_(std::move(pred)) {}
44 
46  constexpr V base() const& {
47  return base_;
48  }
49 
50  constexpr V base() && {
51  return std::move(base_);
52  }
53 
54  constexpr const Pred& pred() const {
55  return *pred_;
56  }
57 
58  constexpr auto begin() {
59  if (!cached_begin_) {
60  cached_begin_.emplace(ranges::find_if_not(base_, std::cref(*pred_)));
61  }
62  return *cached_begin_;
63  }
64 
65  constexpr auto end() {
66  return ranges::end(base_);
67  }
68 
69  private:
70  V base_{};
71  movable_box<Pred> pred_{};
72  using begin_type = decltype(ranges::find_if_not(base_, std::cref(*pred_)));
73  non_propagating_cache<begin_type> cached_begin_;
74 };
75 
76 #if __cplusplus >= 201703L
77 
78 template<typename R, typename Pred>
79 drop_while_view(R&&, Pred) -> drop_while_view<views::all_t<R>, Pred>;
80 
81 #endif
82 
83 template<typename R, typename Pred, std::enable_if_t<conjunction<
84  has_typename_type<views::detail::all_t_impl<R>>,
85  std::is_object<Pred>
86 >::value, int> = 0>
87 constexpr auto make_drop_while_view(R&& r, Pred&& pred) {
88  return drop_while_view<views::all_t<R>, std::decay_t<Pred>>(std::forward<R>(r), std::forward<Pred>(pred));
89 }
90 
91 template<typename T, typename Pred>
93 
95 
96 } // namespace ranges
97 } // namespace vccc
98 
99 #endif // VCCC_RANGES_VIEWS_DROP_WHILE_VIEW_HPP_
Definition: drop_while_view.hpp:33
constexpr V base() const &
Definition: drop_while_view.hpp:46
constexpr auto begin()
Definition: drop_while_view.hpp:58
constexpr const Pred & pred() const
Definition: drop_while_view.hpp:54
constexpr V base() &&
Definition: drop_while_view.hpp:50
constexpr drop_while_view(V base, Pred pred)
Definition: drop_while_view.hpp:42
constexpr auto end()
Definition: drop_while_view.hpp:65
helper class template for defining a view, using the curiously recurring template pattern
Definition: view_interface.hpp:78
constexpr VCCC_INLINE_OR_STATIC detail::find_if_not_niebloid find_if_not
Definition: find_if_not.hpp:51
typename ranges::iterator< T >::type iterator_t
Definition: iterator_t.hpp:32
constexpr auto make_drop_while_view(R &&r, Pred &&pred)
Definition: drop_while_view.hpp:87
constexpr VCCC_INLINE_OR_STATIC detail::end_niebloid end
returns a sentinel indicating the end of a range
Definition: end.hpp:120
Definition: matrix.hpp:495
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35
specifies that a callable type, when invoked with the result of dereferencing an indirectly_readable ...
Definition: indirect_unary_predicate.hpp:49
Definition: enable_borrowed_range.hpp:17
specifies a range whose iterator type satisfies input_iterator
Definition: input_range.hpp:46
specifies that a range is a view, that is, it has constant time copy/move/assignment
Definition: view.hpp:31