• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. Algorithms/Querying Algorithms//find_if |20
2
3find_if
4=======
5
6Synopsis
7--------
8
9.. parsed-literal::
10
11    template<
12          typename Sequence
13        , typename Pred
14        >
15    struct find_if
16    {
17        typedef |unspecified| type;
18    };
19
20
21
22Description
23-----------
24
25Returns an iterator to the first element in ``Sequence`` that satisfies
26the predicate ``Pred``.
27
28
29Header
30------
31
32.. parsed-literal::
33
34    #include <boost/mpl/find_if.hpp>
35
36
37
38Parameters
39----------
40
41+---------------+-------------------------------+-----------------------------------+
42| Parameter     | Requirement                   | Description                       |
43+===============+===============================+===================================+
44| ``Sequence``  | |Forward Sequence|            | A sequence to search in.          |
45+---------------+-------------------------------+-----------------------------------+
46| ``Pred``      | Unary |Lambda Expression|     | A search condition.               |
47+---------------+-------------------------------+-----------------------------------+
48
49
50Expression semantics
51--------------------
52
53For any |Forward Sequence| ``s`` and unary |Lambda Expression| ``pred``:
54
55
56.. parsed-literal::
57
58    typedef find_if<s,pred>::type i;
59
60:Return type:
61    |Forward Iterator|.
62
63:Semantics:
64    ``i`` is the first iterator in the range |begin/end<s>| such that
65
66    .. parsed-literal::
67
68        apply< pred,deref<i>::type >::type::value == true
69
70    If no such iterator exists, ``i`` is identical to ``end<s>::type``.
71
72
73Complexity
74----------
75
76Linear. At most ``size<s>::value`` applications of ``pred``.
77
78
79Example
80-------
81
82.. parsed-literal::
83
84    typedef vector<char,int,unsigned,long,unsigned long> types;
85    typedef find_if<types, is_same<_1,unsigned> >::type iter;
86
87    BOOST_MPL_ASSERT(( is_same< deref<iter>::type, unsigned > ));
88    BOOST_MPL_ASSERT_RELATION( iter::pos::value, ==, 2 );
89
90
91See also
92--------
93
94|Querying Algorithms|, |find|, |count_if|, |lower_bound|
95
96
97.. copyright:: Copyright �  2001-2009 Aleksey Gurtovoy and David Abrahams
98   Distributed under the Boost Software License, Version 1.0. (See accompanying
99   file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
100