File indexing completed on 2025-01-18 10:09:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef RANGES_V3_ACTION_SPLIT_HPP
0015 #define RANGES_V3_ACTION_SPLIT_HPP
0016
0017 #include <vector>
0018
0019 #include <meta/meta.hpp>
0020
0021 #include <range/v3/range_fwd.hpp>
0022
0023 #include <range/v3/action/action.hpp>
0024 #include <range/v3/action/concepts.hpp>
0025 #include <range/v3/functional/bind_back.hpp>
0026 #include <range/v3/iterator/concepts.hpp>
0027 #include <range/v3/iterator/traits.hpp>
0028 #include <range/v3/range/conversion.hpp>
0029 #include <range/v3/utility/static_const.hpp>
0030 #include <range/v3/view/split.hpp>
0031
0032 #include <range/v3/detail/prologue.hpp>
0033
0034 namespace ranges
0035 {
0036
0037
0038 namespace actions
0039 {
0040 struct split_fn
0041 {
0042 template<typename Rng>
0043 using split_value_t =
0044 meta::if_c<(bool)ranges::container<Rng>,
0045 uncvref_t<Rng>, std::vector<range_value_t<Rng>>>;
0046
0047 template(typename T)(
0048 requires range<T &>)
0049 constexpr auto operator()(T & t) const
0050 {
0051 return make_action_closure(
0052 bind_back(split_fn{}, detail::reference_wrapper_<T>(t)));
0053 }
0054
0055 template<typename T>
0056 constexpr auto operator()(T && t) const
0057 {
0058 return make_action_closure(bind_back(split_fn{}, static_cast<T &&>(t)));
0059 }
0060
0061
0062
0063 template(typename Rng)(
0064 requires input_range<Rng> AND indirectly_comparable<
0065 iterator_t<Rng>, range_value_t<Rng> const *, ranges::equal_to>)
0066 std::vector<split_value_t<Rng>>
0067 operator()(Rng && rng, range_value_t<Rng> val) const
0068 {
0069 return views::split(rng, std::move(val)) |
0070 to<std::vector<split_value_t<Rng>>>();
0071 }
0072
0073 template(typename Rng, typename Pattern)(
0074 requires input_range<Rng> AND viewable_range<Pattern> AND
0075 forward_range<Pattern> AND
0076 indirectly_comparable<
0077 iterator_t<Rng>,
0078 iterator_t<Pattern>,
0079 ranges::equal_to> AND
0080 (forward_range<Rng> || detail::tiny_range<Pattern>))
0081 std::vector<split_value_t<Rng>> operator()(Rng && rng, Pattern && pattern)
0082 const
0083 {
0084 return views::split(rng, static_cast<Pattern &&>(pattern)) |
0085 to<std::vector<split_value_t<Rng>>>();
0086 }
0087
0088
0089 template<typename Rng, typename T>
0090 invoke_result_t<split_fn, Rng, T &>
0091 operator()(Rng && rng, detail::reference_wrapper_<T> r) const
0092 {
0093 return (*this)(static_cast<Rng &&>(rng), r.get());
0094 }
0095
0096 };
0097
0098
0099 RANGES_INLINE_VARIABLE(split_fn, split)
0100 }
0101
0102 }
0103
0104 #include <range/v3/detail/epilogue.hpp>
0105
0106 #endif