Horizon
Loading...
Searching...
No Matches
split_when.hpp
Go to the documentation of this file.
1
2// Range v3 library
3//
4// Copyright Eric Niebler 2013-present
5//
6// Use, modification and distribution is subject to the
7// Boost Software License, Version 1.0. (See accompanying
8// file LICENSE_1_0.txt or copy at
9// http://www.boost.org/LICENSE_1_0.txt)
10//
11// Project home: https://github.com/ericniebler/range-v3
12//
13
14#ifndef RANGES_V3_ACTION_SPLIT_WHEN_HPP
15#define RANGES_V3_ACTION_SPLIT_WHEN_HPP
16
17#include <vector>
18
19#include <meta/meta.hpp>
20
22
30#include <range/v3/utility/static_const.hpp>
32
33#include <range/v3/detail/prologue.hpp>
34
35namespace ranges
36{
39 namespace actions
40 {
42 {
43 template<typename Rng>
44 using split_value_t =
45 meta::if_c<(bool)ranges::container<Rng>, //
46 uncvref_t<Rng>, std::vector<range_value_t<Rng>>>;
47
48 template<typename Fun>
49 constexpr auto operator()(Fun fun) const
50 {
51 return make_action_closure(
52 bind_back(split_when_fn{}, static_cast<Fun &&>(fun)));
53 }
54
55 // BUGBUG something is not right with the actions. It should be possible
56 // to move a container into a split and have elements moved into the result.
57 template(typename Rng, typename Fun)(
58 requires forward_range<Rng> AND
59 invocable<Fun &, iterator_t<Rng>, sentinel_t<Rng>> AND
61 copy_constructible<Fun> AND
62 convertible_to<invoke_result_t<Fun &, iterator_t<Rng>,
63 sentinel_t<Rng>>,
64 std::pair<bool, iterator_t<Rng>>>)
65 std::vector<split_value_t<Rng>> operator()(Rng && rng, Fun fun) const
66 {
67 return views::split_when(rng, std::move(fun)) |
68 to<std::vector<split_value_t<Rng>>>();
69 }
70
71 template(typename Rng, typename Fun)(
72 requires forward_range<Rng> AND
73 predicate<Fun const &, range_reference_t<Rng>> AND
74 copy_constructible<Fun>)
75 std::vector<split_value_t<Rng>> operator()(Rng && rng, Fun fun) const
76 {
77 return views::split_when(rng, std::move(fun)) |
78 to<std::vector<split_value_t<Rng>>>();
79 }
80 };
81
83 RANGES_INLINE_VARIABLE(split_when_fn, split_when)
84 } // namespace actions
86} // namespace ranges
87
88#include <range/v3/detail/epilogue.hpp>
89
90#endif
The container concept.
The forward_range concept.
The invocable concept.
The predicate concept.
decltype(begin(declval(Rng &))) iterator_t
Definition access.hpp:698
Tiny meta-programming library.
Definition split_when.hpp:42