3
// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. Use, modification and
4
// distribution is subject to the Boost Software License, Version
5
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6
// http://www.boost.org/LICENSE_1_0.txt)
8
// For more information, see http://www.boost.org/libs/range/
11
#ifndef BOOST_RANGE_ADAPTOR_FILTERED_HPP
12
#define BOOST_RANGE_ADAPTOR_FILTERED_HPP
14
#include <mlib/range/adaptor/argument_fwd.hpp>
15
#include <boost/range/iterator_range.hpp>
16
#include <boost/iterator/filter_iterator.hpp>
20
namespace range_detail
22
template< class P, class R >
24
boost::iterator_range<
25
boost::filter_iterator< P,
26
BOOST_DEDUCED_TYPENAME range_iterator<R>::type
31
typedef boost::iterator_range<
32
boost::filter_iterator< P,
33
BOOST_DEDUCED_TYPENAME range_iterator<R>::type
37
filter_range( P p, R& r )
38
: base( make_filter_iterator( p, boost::begin(r), boost::end(r) ),
39
make_filter_iterator( p, boost::end(r), boost::end(r) ) )
44
struct filter_holder : holder<T>
46
filter_holder( T r ) : holder<T>(r)
50
template< class InputRng, class Predicate >
51
inline filter_range<Predicate, InputRng>
52
operator|( InputRng& r,
53
const filter_holder<Predicate>& f )
55
return filter_range<Predicate, InputRng>( f.val, r );
58
template< class InputRng, class Predicate >
59
inline filter_range<Predicate, const InputRng>
60
operator|( const InputRng& r,
61
const filter_holder<Predicate>& f )
63
return filter_range<Predicate, const InputRng>( f.val, r );
68
// Unusual use of 'using' is intended to bring filter_range into the boost namespace
69
// while leaving the mechanics of the '|' operator in range_detail and maintain
70
// argument dependent lookup.
71
// filter_range logically needs to be in the boost namespace to allow user of
72
// the library to define the return type for filter()
73
using range_detail::filter_range;
79
const range_detail::forwarder<range_detail::filter_holder>
81
range_detail::forwarder<range_detail::filter_holder>();
84
template<class InputRange, class Predicate>
85
inline filter_range<Predicate, InputRange>
86
filter(InputRange& rng, Predicate filter_pred)
88
return range_detail::filter_range<Predicate, InputRange>( filter_pred, rng );
91
template<class InputRange, class Predicate>
92
inline filter_range<Predicate, const InputRange>
93
filter(const InputRange& rng, Predicate filter_pred)
95
return range_detail::filter_range<Predicate, const InputRange>( filter_pred, rng );