Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r70715 - in branches/release: boost/iterator libs/iterator libs/iterator/test
From: dnljms_at_[hidden]
Date: 2011-03-29 17:31:30


Author: danieljames
Date: 2011-03-29 17:31:29 EDT (Tue, 29 Mar 2011)
New Revision: 70715
URL: http://svn.boost.org/trac/boost/changeset/70715

Log:
Iterator: Use boost::result_of to determine nested result type of function in transform_iterator. Fixes #1427.

Properties modified:
   branches/release/boost/iterator/ (props changed)
   branches/release/boost/iterator/iterator_facade.hpp (props changed)
   branches/release/libs/iterator/ (props changed)
Text files modified:
   branches/release/boost/iterator/transform_iterator.hpp | 25 +++++--------------------
   branches/release/libs/iterator/test/transform_iterator_test.cpp | 31 +++++++++++++++++++++++++++++++
   2 files changed, 36 insertions(+), 20 deletions(-)

Modified: branches/release/boost/iterator/transform_iterator.hpp
==============================================================================
--- branches/release/boost/iterator/transform_iterator.hpp (original)
+++ branches/release/boost/iterator/transform_iterator.hpp 2011-03-29 17:31:29 EDT (Tue, 29 Mar 2011)
@@ -20,6 +20,8 @@
 #include <boost/type_traits/is_reference.hpp>
 #include <boost/type_traits/remove_const.hpp>
 #include <boost/type_traits/remove_reference.hpp>
+#include <boost/utility/result_of.hpp>
+
 
 #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
 # include <boost/type_traits/is_base_and_derived.hpp>
@@ -35,33 +37,16 @@
 
   namespace detail
   {
-
- template <class UnaryFunc>
- struct function_object_result
- {
- typedef typename UnaryFunc::result_type type;
- };
-
-#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
- template <class Return, class Argument>
- struct function_object_result<Return(*)(Argument)>
- {
- typedef Return type;
- };
-#endif
-
     // Compute the iterator_adaptor instantiation to be used for transform_iterator
     template <class UnaryFunc, class Iterator, class Reference, class Value>
     struct transform_iterator_base
     {
      private:
         // 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<UnaryFunc>
+ , result_of<UnaryFunc(typename std::iterator_traits<Iterator>::reference)>
>::type reference;
 
         // To get the default for Value: remove any reference on the
@@ -113,7 +98,7 @@
 #endif
     }
 
- template<
+ template <
         class OtherUnaryFunction
       , class OtherIterator
       , class OtherReference

Modified: branches/release/libs/iterator/test/transform_iterator_test.cpp
==============================================================================
--- branches/release/libs/iterator/test/transform_iterator_test.cpp (original)
+++ branches/release/libs/iterator/test/transform_iterator_test.cpp 2011-03-29 17:31:29 EDT (Tue, 29 Mar 2011)
@@ -102,6 +102,17 @@
   return arg*2;
 }
 
+struct polymorphic_mult_functor
+{
+ //Implement result_of protocol
+ template <class FArgs> struct result;
+ template <class F, class T> struct result<F(T )> {typedef T type;};
+ template <class F, class T> struct result<F(T& )> {typedef T type;};
+ template <class F, class T> struct result<F(const T&)> {typedef T type;};
+
+ template <class T>
+ T operator()(const T& _arg) const {return _arg*2;}
+};
 
 int
 main()
@@ -244,5 +255,25 @@
     );
   }
 
+ // 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();
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk