How to use phoenix expression with boost :: transform_iterator?

<Update> As usual for me, the question was wrong. The actual question is: why does transform_iterator not use the usual result_of <> metafunction to determine the type of the return value, and not directly access UnaryFunc :: result_type. Wrote an answer with work. </ Update>

In particular, is there a way to make the phoenix expression express the type result_typeas expected for the concept of std :: unary_function? boost :: transform_iterator seems to be expecting this, and looking at src I don't see a simple job.

Here is some code that reproduces the problem I encountered:

#include <boost/iterator/transform_iterator.hpp>
#include <boost/spirit/home/phoenix.hpp>
#include <numeric>
#include <iostream>

using namespace boost::phoenix;
using namespace boost::phoenix::arg_names;

int main(void){
   int i[] = {4,2,5,3};

   std::cout <<
      std::accumulate(
         boost::make_transform_iterator(i,   _1*_1),
         boost::make_transform_iterator(i+4, _1*_1),
         0
      ) << std::endl;

   return 0;
}

(gcc 4.3.4, boost 1.43):

/usr/include/boost/iterator/transform_iterator.hpp:43: error: no type named ‘result_type’ in ‘struct boost::phoenix::actor<...

boost:: lambda ( result_type). , make_transform_iterator , , .

- phoenix , result_type?

+5
1

, boost trunk (. 51, result_of<> UnaryFunc::result_type). 1.44 .

< 1,44. transform_iterator UnaryFunc::result_type, Reference . , make_transform_iterator , result_of < > meta UnaryFunc Reference.

#include <boost/iterator/transform_iterator.hpp>
#include <boost/utility.hpp>
#include <iterator>

template <class UnaryFunc, class Iterator>
boost::transform_iterator<
   UnaryFunc,
   Iterator,
   typename boost::result_of<
      UnaryFunc(typename std::iterator_traits<Iterator>::value_type)
   >::type
>
make_trans_it(Iterator it, UnaryFunc fun){
   return
      boost::transform_iterator<
         UnaryFunc,
         Iterator,
         typename boost::result_of<
            UnaryFunc(typename std::iterator_traits<Iterator>::value_type)
         >::type
      >(it, fun);
};
+4

All Articles