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_REMOVE_IF_HPP_INCLUDED |
10 | #define BOOST_RANGE_ALGORITHM_REMOVE_IF_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 <algorithm> |
18 | |
19 | namespace boost |
20 | { |
21 | namespace range |
22 | { |
23 | |
24 | /// \brief template function remove_if |
25 | /// |
26 | /// range-based version of the remove_if std algorithm |
27 | /// |
28 | /// \pre ForwardRange is a model of the ForwardRangeConcept |
29 | /// \pre UnaryPredicate is a model of the UnaryPredicateConcept |
30 | template< class ForwardRange, class UnaryPredicate > |
31 | inline BOOST_DEDUCED_TYPENAME boost::range_iterator<ForwardRange>::type |
32 | remove_if(ForwardRange& rng, UnaryPredicate pred) |
33 | { |
34 | BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> )); |
35 | return std::remove_if(boost::begin(rng), boost::end(rng), pred); |
36 | } |
37 | |
38 | /// \overload |
39 | template< class ForwardRange, class UnaryPredicate > |
40 | inline BOOST_DEDUCED_TYPENAME boost::range_iterator<const ForwardRange>::type |
41 | remove_if(const ForwardRange& rng, UnaryPredicate pred) |
42 | { |
43 | BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> )); |
44 | return std::remove_if(boost::begin(rng), boost::end(rng), pred); |
45 | } |
46 | |
47 | // range_return overloads |
48 | |
49 | /// \overload |
50 | template< range_return_value re, class ForwardRange, class UnaryPredicate > |
51 | inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type |
52 | remove_if(ForwardRange& rng, UnaryPredicate pred) |
53 | { |
54 | BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> )); |
55 | return range_return<ForwardRange,re>::pack( |
56 | std::remove_if(boost::begin(rng), boost::end(rng), pred), |
57 | rng); |
58 | } |
59 | |
60 | /// \overload |
61 | template< range_return_value re, class ForwardRange, class UnaryPredicate > |
62 | inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type |
63 | remove_if(const ForwardRange& rng, UnaryPredicate pred) |
64 | { |
65 | BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> )); |
66 | return range_return<const ForwardRange,re>::pack( |
67 | std::remove_if(boost::begin(rng), boost::end(rng), pred), |
68 | rng); |
69 | } |
70 | |
71 | } // namespace range |
72 | using range::remove_if; |
73 | } // namespace boost |
74 | |
75 | #endif // include guard |
76 | |