source: XIOS/dev/dev_olga/src/extern/boost/include/boost/range/algorithm/search_n.hpp @ 1022

Last change on this file since 1022 was 1022, checked in by mhnguyen, 7 years ago
File size: 5.4 KB
Line 
1//  Copyright Neil Groves 2009. Use, modification and
2//  distribution is subject to the Boost Software License, Version
3//  1.0. (See accompanying file LICENSE_1_0.txt or copy at
4//  http://www.boost.org/LICENSE_1_0.txt)
5//
6//
7// For more information, see http://www.boost.org/libs/range/
8//
9#ifndef BOOST_RANGE_ALGORITHM_SEARCH_N_HPP_INCLUDED
10#define BOOST_RANGE_ALGORITHM_SEARCH_N_HPP_INCLUDED
11
12#include <boost/concept_check.hpp>
13#include <boost/range/begin.hpp>
14#include <boost/range/end.hpp>
15#include <boost/range/concepts.hpp>
16#include <boost/range/detail/range_return.hpp>
17#include <boost/range/value_type.hpp>
18#include <algorithm>
19
20namespace boost
21{
22    namespace range
23    {
24
25/// \brief template function search
26///
27/// range-based version of the search std algorithm
28///
29/// \pre ForwardRange is a model of the ForwardRangeConcept
30/// \pre Integer is an integral type
31/// \pre Value is a model of the EqualityComparableConcept
32/// \pre ForwardRange's value type is a model of the EqualityComparableConcept
33/// \pre Object's of ForwardRange's value type can be compared for equality with Objects of type Value
34template< class ForwardRange, class Integer, class Value >
35inline BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
36search_n(ForwardRange& rng, Integer count, const Value& value)
37{
38    BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
39    return std::search_n(boost::begin(rng),boost::end(rng), count, value);
40}
41
42/// \overload
43template< class ForwardRange, class Integer, class Value >
44inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type
45search_n(const ForwardRange& rng, Integer count, const Value& value)
46{
47    BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept<const ForwardRange>));
48    return std::search_n(boost::begin(rng), boost::end(rng), count, value);
49}
50
51/// \overload
52template< class ForwardRange, class Integer, class Value,
53          class BinaryPredicate >
54inline BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
55search_n(ForwardRange& rng, Integer count, const Value& value,
56         BinaryPredicate binary_pred)
57{
58    BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
59    BOOST_RANGE_CONCEPT_ASSERT((BinaryPredicateConcept<BinaryPredicate,
60        BOOST_DEDUCED_TYPENAME range_value<ForwardRange>::type, const Value&>));
61    return std::search_n(boost::begin(rng), boost::end(rng),
62        count, value, binary_pred);
63}
64
65/// \overload
66template< class ForwardRange, class Integer, class Value,
67          class BinaryPredicate >
68inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type
69search_n(const ForwardRange& rng, Integer count, const Value& value,
70         BinaryPredicate binary_pred)
71{
72    BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept<const ForwardRange>));
73    BOOST_RANGE_CONCEPT_ASSERT((BinaryPredicateConcept<BinaryPredicate,
74        BOOST_DEDUCED_TYPENAME range_value<const ForwardRange>::type, const Value&>));
75    return std::search_n(boost::begin(rng), boost::end(rng),
76        count, value, binary_pred);
77}
78
79// range_return overloads
80
81/// \overload
82template< range_return_value re, class ForwardRange, class Integer,
83          class Value >
84inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
85search_n(ForwardRange& rng, Integer count, const Value& value)
86{
87    BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
88    return range_return<ForwardRange,re>::
89        pack(std::search_n(boost::begin(rng),boost::end(rng),
90                           count, value),
91             rng);
92}
93
94/// \overload
95template< range_return_value re, class ForwardRange, class Integer,
96          class Value >
97inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
98search_n(const ForwardRange& rng, Integer count, const Value& value)
99{
100    BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept<const ForwardRange>));
101    return range_return<const ForwardRange,re>::
102        pack(std::search_n(boost::begin(rng), boost::end(rng),
103                           count, value),
104             rng);
105}
106
107/// \overload
108template< range_return_value re, class ForwardRange, class Integer,
109          class Value, class BinaryPredicate >
110inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
111search_n(ForwardRange& rng, Integer count, const Value& value,
112         BinaryPredicate pred)
113{
114    BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
115    BOOST_RANGE_CONCEPT_ASSERT((BinaryPredicateConcept<BinaryPredicate,
116        BOOST_DEDUCED_TYPENAME range_value<ForwardRange>::type,
117        const Value&>));
118    return range_return<ForwardRange,re>::
119        pack(std::search_n(boost::begin(rng), boost::end(rng),
120                           count, value, pred),
121             rng);
122}
123
124/// \overload
125template< range_return_value re, class ForwardRange, class Integer,
126          class Value, class BinaryPredicate >
127inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
128search_n(const ForwardRange& rng, Integer count, const Value& value,
129         BinaryPredicate pred)
130{
131    BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept<const ForwardRange>));
132    BOOST_RANGE_CONCEPT_ASSERT((BinaryPredicateConcept<BinaryPredicate,
133        BOOST_DEDUCED_TYPENAME range_value<const ForwardRange>::type,
134        const Value&>));
135    return range_return<const ForwardRange,re>::
136        pack(std::search_n(boost::begin(rng), boost::end(rng),
137                           count, value, pred),
138             rng);
139}
140
141    } // namespace range
142    using range::search_n;
143} // namespace boost
144
145#endif // include guard
Note: See TracBrowser for help on using the repository browser.