Horizon
Loading...
Searching...
No Matches
find_first_of.hpp
Go to the documentation of this file.
1
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
19
29#include <range/v3/utility/static_const.hpp>
30
31#include <range/v3/detail/prologue.hpp>
32
33namespace ranges
34{
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
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
71 template(typename Rng0,
72 typename Rng1,
73 typename R = equal_to,
74 typename P0 = identity,
75 typename P1 = identity)(
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 }
99} // namespace ranges
100
101#include <range/v3/detail/epilogue.hpp>
102
103#endif
The forward_iterator concept.
The forward_range concept.
The indirect_relation concept.
The input_iterator concept.
The input_range concept.
The sentinel_for concept.
decltype(begin(declval(Rng &))) iterator_t
Definition access.hpp:698
typename Fn::template invoke< Args... > invoke
Evaluate the invocable Fn with the arguments Args.
Definition meta.hpp:541
Definition comparisons.hpp:28
Definition identity.hpp:25