Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:51:13

0001 // Boost.Range library
0002 //
0003 //  Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. Use, modification and
0004 //  distribution is subject to the Boost Software License, Version
0005 //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
0006 //  http://www.boost.org/LICENSE_1_0.txt)
0007 //
0008 // For more information, see http://www.boost.org/libs/range/
0009 //
0010 
0011 #ifndef BOOST_RANGE_ADAPTOR_FILTERED_HPP
0012 #define BOOST_RANGE_ADAPTOR_FILTERED_HPP
0013 
0014 #include <boost/range/adaptor/argument_fwd.hpp>
0015 #include <boost/range/detail/default_constructible_unary_fn.hpp>
0016 #include <boost/range/iterator_range.hpp>
0017 #include <boost/range/concepts.hpp>
0018 #include <boost/iterator/filter_iterator.hpp>
0019 
0020 namespace boost
0021 {
0022     namespace range_detail
0023     {
0024         template< class P, class R >
0025         struct filtered_range :
0026             boost::iterator_range<
0027                 boost::filter_iterator<
0028                     typename default_constructible_unary_fn_gen<P, bool>::type,
0029                     typename range_iterator<R>::type
0030                 >
0031             >
0032         {
0033         private:
0034             typedef boost::iterator_range<
0035                 boost::filter_iterator<
0036                     typename default_constructible_unary_fn_gen<P, bool>::type,
0037                     typename range_iterator<R>::type
0038                 >
0039             > base;
0040         public:
0041             typedef typename default_constructible_unary_fn_gen<P, bool>::type
0042                 pred_t;
0043 
0044             filtered_range(P p, R& r)
0045             : base(make_filter_iterator(pred_t(p),
0046                                         boost::begin(r), boost::end(r)),
0047                    make_filter_iterator(pred_t(p),
0048                                         boost::end(r), boost::end(r)))
0049             { }
0050         };
0051 
0052         template< class T >
0053         struct filter_holder : holder<T>
0054         {
0055             filter_holder( T r ) : holder<T>(r)
0056             { }
0057         };
0058 
0059         template< class SinglePassRange, class Predicate >
0060         inline filtered_range<Predicate, SinglePassRange>
0061         operator|(SinglePassRange& r,
0062                   const filter_holder<Predicate>& f)
0063         {
0064             BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept<SinglePassRange>));
0065             return filtered_range<Predicate, SinglePassRange>( f.val, r );
0066         }
0067 
0068         template< class SinglePassRange, class Predicate >
0069         inline filtered_range<Predicate, const SinglePassRange>
0070         operator|(const SinglePassRange& r,
0071                   const filter_holder<Predicate>& f )
0072         {
0073             BOOST_RANGE_CONCEPT_ASSERT((
0074                 SinglePassRangeConcept<const SinglePassRange>));
0075             return filtered_range<Predicate, const SinglePassRange>( f.val, r );
0076         }
0077 
0078     } // 'range_detail'
0079 
0080     // Unusual use of 'using' is intended to bring filter_range into the boost namespace
0081     // while leaving the mechanics of the '|' operator in range_detail and maintain
0082     // argument dependent lookup.
0083     // filter_range logically needs to be in the boost namespace to allow user of
0084     // the library to define the return type for filter()
0085     using range_detail::filtered_range;
0086 
0087     namespace adaptors
0088     {
0089         namespace
0090         {
0091             const range_detail::forwarder<range_detail::filter_holder>
0092                     filtered =
0093                        range_detail::forwarder<range_detail::filter_holder>();
0094         }
0095 
0096         template<class SinglePassRange, class Predicate>
0097         inline filtered_range<Predicate, SinglePassRange>
0098         filter(SinglePassRange& rng, Predicate filter_pred)
0099         {
0100             BOOST_RANGE_CONCEPT_ASSERT((
0101                 SinglePassRangeConcept<SinglePassRange>));
0102 
0103             return range_detail::filtered_range<
0104                 Predicate, SinglePassRange>( filter_pred, rng );
0105         }
0106 
0107         template<class SinglePassRange, class Predicate>
0108         inline filtered_range<Predicate, const SinglePassRange>
0109         filter(const SinglePassRange& rng, Predicate filter_pred)
0110         {
0111             BOOST_RANGE_CONCEPT_ASSERT((
0112                 SinglePassRangeConcept<const SinglePassRange>));
0113 
0114             return range_detail::filtered_range<
0115                 Predicate, const SinglePassRange>( filter_pred, rng );
0116         }
0117     } // 'adaptors'
0118 
0119 }
0120 
0121 #endif