File indexing completed on 2025-01-18 09:51:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_RANGE_ADAPTOR_TRANSFORMED_HPP
0012 #define BOOST_RANGE_ADAPTOR_TRANSFORMED_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/transform_iterator.hpp>
0019 #include <boost/utility/result_of.hpp>
0020
0021 namespace boost
0022 {
0023 namespace range_detail
0024 {
0025
0026
0027 template<typename P, typename It>
0028 struct transform_iterator_gen
0029 {
0030 typedef transform_iterator<
0031 typename default_constructible_unary_fn_gen<
0032 P,
0033 typename transform_iterator<P, It>::reference
0034 >::type,
0035 It
0036 > type;
0037 };
0038
0039 template< class F, class R >
0040 struct transformed_range :
0041 public boost::iterator_range<
0042 typename transform_iterator_gen<
0043 F, typename range_iterator<R>::type>::type>
0044 {
0045 private:
0046 typedef typename transform_iterator_gen<
0047 F, typename range_iterator<R>::type>::type transform_iter_t;
0048
0049 typedef boost::iterator_range<transform_iter_t> base;
0050
0051 public:
0052 typedef typename default_constructible_unary_fn_gen<
0053 F,
0054 typename transform_iterator<
0055 F,
0056 typename range_iterator<R>::type
0057 >::reference
0058 >::type transform_fn_type;
0059
0060 typedef R source_range_type;
0061
0062 transformed_range(transform_fn_type f, R& r)
0063 : base(transform_iter_t(boost::begin(r), f),
0064 transform_iter_t(boost::end(r), f))
0065 {
0066 }
0067 };
0068
0069 template< class T >
0070 struct transform_holder : holder<T>
0071 {
0072 transform_holder( T r ) : holder<T>(r)
0073 {
0074 }
0075 };
0076
0077 template< class SinglePassRange, class UnaryFunction >
0078 inline transformed_range<UnaryFunction,SinglePassRange>
0079 operator|( SinglePassRange& r,
0080 const transform_holder<UnaryFunction>& f )
0081 {
0082 BOOST_RANGE_CONCEPT_ASSERT((
0083 SinglePassRangeConcept<SinglePassRange>));
0084
0085 return transformed_range<UnaryFunction,SinglePassRange>( f.val, r );
0086 }
0087
0088 template< class SinglePassRange, class UnaryFunction >
0089 inline transformed_range<UnaryFunction, const SinglePassRange>
0090 operator|( const SinglePassRange& r,
0091 const transform_holder<UnaryFunction>& f )
0092 {
0093 BOOST_RANGE_CONCEPT_ASSERT((
0094 SinglePassRangeConcept<const SinglePassRange>));
0095
0096 return transformed_range<UnaryFunction, const SinglePassRange>(
0097 f.val, r);
0098 }
0099
0100 }
0101
0102 using range_detail::transformed_range;
0103
0104 namespace adaptors
0105 {
0106 namespace
0107 {
0108 const range_detail::forwarder<range_detail::transform_holder>
0109 transformed =
0110 range_detail::forwarder<range_detail::transform_holder>();
0111 }
0112
0113 template<class UnaryFunction, class SinglePassRange>
0114 inline transformed_range<UnaryFunction, SinglePassRange>
0115 transform(SinglePassRange& rng, UnaryFunction fn)
0116 {
0117 BOOST_RANGE_CONCEPT_ASSERT((
0118 SinglePassRangeConcept<SinglePassRange>));
0119
0120 return transformed_range<UnaryFunction, SinglePassRange>(fn, rng);
0121 }
0122
0123 template<class UnaryFunction, class SinglePassRange>
0124 inline transformed_range<UnaryFunction, const SinglePassRange>
0125 transform(const SinglePassRange& rng, UnaryFunction fn)
0126 {
0127 BOOST_RANGE_CONCEPT_ASSERT((
0128 SinglePassRangeConcept<const SinglePassRange>));
0129
0130 return transformed_range<UnaryFunction, const SinglePassRange>(
0131 fn, rng);
0132 }
0133 }
0134
0135 }
0136
0137 #endif