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_WHEN_HPP
0015 #define RANGES_V3_ACTION_SPLIT_WHEN_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/functional/invoke.hpp>
0027 #include <range/v3/iterator/concepts.hpp>
0028 #include <range/v3/iterator/traits.hpp>
0029 #include <range/v3/range/conversion.hpp>
0030 #include <range/v3/utility/static_const.hpp>
0031 #include <range/v3/view/split_when.hpp>
0032
0033 #include <range/v3/detail/prologue.hpp>
0034
0035 namespace ranges
0036 {
0037
0038
0039 namespace actions
0040 {
0041 struct split_when_fn
0042 {
0043 template<typename Rng>
0044 using split_value_t =
0045 meta::if_c<(bool)ranges::container<Rng>,
0046 uncvref_t<Rng>, std::vector<range_value_t<Rng>>>;
0047
0048 template<typename Fun>
0049 constexpr auto operator()(Fun fun) const
0050 {
0051 return make_action_closure(
0052 bind_back(split_when_fn{}, static_cast<Fun &&>(fun)));
0053 }
0054
0055
0056
0057 template(typename Rng, typename Fun)(
0058 requires forward_range<Rng> AND
0059 invocable<Fun &, iterator_t<Rng>, sentinel_t<Rng>> AND
0060 invocable<Fun &, iterator_t<Rng>, iterator_t<Rng>> AND
0061 copy_constructible<Fun> AND
0062 convertible_to<invoke_result_t<Fun &, iterator_t<Rng>,
0063 sentinel_t<Rng>>,
0064 std::pair<bool, iterator_t<Rng>>>)
0065 std::vector<split_value_t<Rng>> operator()(Rng && rng, Fun fun) const
0066 {
0067 return views::split_when(rng, std::move(fun)) |
0068 to<std::vector<split_value_t<Rng>>>();
0069 }
0070
0071 template(typename Rng, typename Fun)(
0072 requires forward_range<Rng> AND
0073 predicate<Fun const &, range_reference_t<Rng>> AND
0074 copy_constructible<Fun>)
0075 std::vector<split_value_t<Rng>> operator()(Rng && rng, Fun fun) const
0076 {
0077 return views::split_when(rng, std::move(fun)) |
0078 to<std::vector<split_value_t<Rng>>>();
0079 }
0080 };
0081
0082
0083 RANGES_INLINE_VARIABLE(split_when_fn, split_when)
0084 }
0085
0086 }
0087
0088 #include <range/v3/detail/epilogue.hpp>
0089
0090 #endif