diff --git a/include/boost/iterator/transform_iterator.hpp b/include/boost/iterator/transform_iterator.hpp index c365fe0..1a229e2 100644 --- a/include/boost/iterator/transform_iterator.hpp +++ b/include/boost/iterator/transform_iterator.hpp @@ -20,6 +20,8 @@ #include #include #include +#include + #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310)) # include @@ -35,33 +37,18 @@ namespace boost namespace detail { - - template - struct function_object_result - { - typedef typename UnaryFunc::result_type type; - }; - -#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - template - struct function_object_result - { - typedef Return type; - }; -#endif - // Compute the iterator_adaptor instantiation to be used for transform_iterator template struct transform_iterator_base { private: + typedef typename std::iterator_traits::reference Arg1; + // By default, dereferencing the iterator yields the same as - // the function. Do we need to adjust the way - // function_object_result is computed for the standard - // proposal (e.g. using Doug's result_of)? + // the function. typedef typename ia_dflt_help< Reference - , function_object_result + , result_of::value_type)> >::type reference; // To get the default for Value: remove any reference on the @@ -113,7 +100,7 @@ namespace boost #endif } - template< + template < class OtherUnaryFunction , class OtherIterator , class OtherReference diff --git a/test/transform_iterator_test.cpp b/test/transform_iterator_test.cpp index bf08dd2..e72fc79 100644 --- a/test/transform_iterator_test.cpp +++ b/test/transform_iterator_test.cpp @@ -102,6 +102,16 @@ int mult_2(int arg) return arg*2; } +struct polymorphic_mult_functor +{ + //Implement result_of protocol + template struct result; + template struct result {typedef T type;}; + + template + typename result::type + operator()(const T& _arg) const {return _arg*2;} +}; int main() @@ -244,5 +254,25 @@ main() ); } + // Test transform_iterator with polymorphic object function + { + int x[N], y[N]; + for (int k = 0; k < N; ++k) + x[k] = k; + std::copy(x, x + N, y); + + for (int k2 = 0; k2 < N; ++k2) + x[k2] = x[k2] * 2; + + boost::input_iterator_test( + boost::make_transform_iterator(y, polymorphic_mult_functor()), x[0], x[1]); + + boost::input_iterator_test( + boost::make_transform_iterator(&y[0], polymorphic_mult_functor()), x[0], x[1]); + + boost::random_access_readable_iterator_test( + boost::make_transform_iterator(y, polymorphic_mult_functor()), N, x); + } + return boost::report_errors(); }