Debian Codegraph @

3rd_party/range-v3/range/v3/algorithm/find_first_of.hpp

raw
1 /// \file
2 // Range v3 library
3 //
4 // Copyright Eric Niebler 2014-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 #ifndef RANGES_V3_ALGORITHM_FIND_FIRST_OF_HPP
14 #define RANGES_V3_ALGORITHM_FIND_FIRST_OF_HPP
15
16 #include <utility>
17
18 #include <range/v3/range_fwd.hpp>
19
20 #include <range/v3/functional/comparisons.hpp>
21 #include <range/v3/functional/identity.hpp>
22 #include <range/v3/functional/invoke.hpp>
23 #include <range/v3/iterator/concepts.hpp>
24 #include <range/v3/iterator/traits.hpp>
25 #include <range/v3/range/access.hpp>
26 #include <range/v3/range/concepts.hpp>
27 #include <range/v3/range/dangling.hpp>
28 #include <range/v3/range/traits.hpp>
29 #include <range/v3/utility/static_const.hpp>
30
31 #include <range/v3/detail/prologue.hpp>
32
33 namespace ranges
34 {
35 /// \addtogroup group-algorithms
36 /// @{
37 RANGES_FUNC_BEGIN(find_first_of)
38 // Rationale: return I0 instead of pair<I0,I1> because find_first_of need
39 // not actually compute the end of [I1,S0); therefore, it is not necessarily
40 // losing information. E.g., if begin0 == end0, we can return begin0 immediately.
41 // If we returned pair<I0,I1>, we would need to do an O(N) scan to find the
42 // end position.
43
44 /// \brief function template \c find_first_of
45 template(typename I0,
46 typename S0,
47 typename I1,
48 typename S1,
49 typename R = equal_to,
50 typename P0 = identity,
51 typename P1 = identity)(
52 requires input_iterator<I0> AND sentinel_for<S0, I0> AND
53 forward_iterator<I1> AND sentinel_for<S1, I1> AND
54 indirect_relation<R, projected<I0, P0>, projected<I1, P1>>)
55 constexpr I0 RANGES_FUNC(find_first_of)(I0 begin0,
56 S0 end0,
57 I1 begin1,
58 S1 end1,
59 R pred = R{},
60 P0 proj0 = P0{},
61 P1 proj1 = P1{}) //
62 {
63 for(; begin0 != end0; ++begin0)
64 for(auto tmp = begin1; tmp != end1; ++tmp)
65 if(invoke(pred, invoke(proj0, *begin0), invoke(proj1, *tmp)))
66 return begin0;
67 return begin0;
68 }
69
70 /// \overload
71 template(typename Rng0,
72 typename Rng1,
73 typename R = equal_to,
74 typename P0 = identity,
75 typename P1 = identity)(
76 requires input_range<Rng0> AND forward_range<Rng1> AND
77 indirect_relation<R,
78 projected<iterator_t<Rng0>, P0>,
79 projected<iterator_t<Rng1>, P1>>)
80 constexpr borrowed_iterator_t<Rng0> RANGES_FUNC(find_first_of)(
81 Rng0 && rng0, Rng1 && rng1, R pred = R{}, P0 proj0 = P0{}, P1 proj1 = P1{}) //
82 {
83 return (*this)(begin(rng0),
84 end(rng0),
85 begin(rng1),
86 end(rng1),
87 std::move(pred),
88 std::move(proj0),
89 std::move(proj1));
90 }
91
92 RANGES_FUNC_END(find_first_of)
93
94 namespace cpp20
95 {
96 using ranges::find_first_of;
97 }
98 /// @}
99 } // namespace ranges
100
101 #include <range/v3/detail/epilogue.hpp>
102
103 #endif