VCCC  2024.05
VisualCamp Common C++ library
split.hpp
Go to the documentation of this file.
1 //
2 // Created by yonggyulee on 2/3/24.
3 //
4 
5 #ifndef VCCC_RANGES_VIEWS_SPLIT_HPP
6 #define VCCC_RANGES_VIEWS_SPLIT_HPP
7 
8 #include <type_traits>
9 #include <utility>
10 
11 #include "split_view.hpp"
21 
22 namespace vccc {
23 namespace ranges {
24 namespace views {
25 namespace detail {
26 
27 template<typename Pattern>
28 class split_adapter_closure : public range_adaptor_closure<split_adapter_closure<Pattern>> {
30  struct pattern_type_impl {
31  using type = single_view<range_value_t<R>>;
32  };
33  template<typename R>
34  struct pattern_type_impl<R, false> {
35  using type = all_t<Pattern>;
36  };
37 
38  template<typename R>
39  using pattern_type = typename pattern_type_impl<R>::type;
40  movable_box<Pattern> pattern_;
41 
42  public:
44  constexpr explicit split_adapter_closure(T&& pattern)
45  : pattern_(std::forward<T>(pattern)) {}
46 
48  constexpr auto operator()(R&& r) & {
49  return split_view<all_t<R>, pattern_type<R>>(std::forward<R>(r), *pattern_);
50  }
51 
53  constexpr auto operator()(R&& r) const& {
54  return split_view<all_t<R>, pattern_type<R>>(std::forward<R>(r), *pattern_);
55  }
56 
58  constexpr auto operator()(R&& r) && {
59  return split_view<all_t<R>, pattern_type<R>>(std::forward<R>(r), std::move(*pattern_));
60  }
61 
63  constexpr auto operator()(R&& r) const && {
64  return split_view<all_t<R>, pattern_type<R>>(std::forward<R>(r), std::move(*pattern_));
65  }
66 };
67 
70  constexpr auto operator()(R&& r, Pattern&& pattern) const {
71  return vccc::ranges::make_split_view(std::forward<R>(r), std::forward<Pattern>(pattern));
72  }
73 
74  template<typename Pattern>
76  return split_adapter_closure<std::remove_reference_t<Pattern>>(std::forward<Pattern>(pattern));
77  }
78 };
79 
80 } // namespace detail
81 
84 
90 
92 
93 } // namespace views
94 } // namespace ranges
95 } // namespace vccc
96 
97 #endif // VCCC_RANGES_VIEWS_SPLIT_HPP
Definition: single.hpp:38
split_view takes a view and a delimiter, and splits the view into subranges on the delimiter.
Definition: split_view.hpp:47
constexpr auto operator()(R &&r) &&
Definition: split.hpp:58
constexpr auto operator()(R &&r) const &
Definition: split.hpp:53
constexpr split_adapter_closure(T &&pattern)
Definition: split.hpp:44
constexpr auto operator()(R &&r) const &&
Definition: split.hpp:63
constexpr auto operator()(R &&r) &
Definition: split.hpp:48
constexpr auto make_split_view(R &&r, P &&pattern)
Definition: split_view.hpp:239
constexpr VCCC_INLINE_OR_STATIC detail::split_niebloid split
RangeAdaptorObject. The expression views::split(e, p) is expression-equivalent to split_view(e,...
Definition: split.hpp:89
typename detail::all_t_impl< R >::type all_t
Calculates the suitable view type of a viewable_range type.
Definition: all.hpp:107
#define VCCC_INLINE_OR_STATIC
Definition: inline_or_static.hpp:9
Definition: matrix.hpp:495
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35
helper base class template for defining a range adaptor closure object
Definition: range_adaptor_closure.hpp:96
constexpr split_adapter_closure< std::remove_reference_t< Pattern > > operator()(Pattern &&pattern) const
Definition: split.hpp:75
constexpr auto operator()(R &&r, Pattern &&pattern) const
Definition: split.hpp:70