shunsuke wrote:
Sohail Somani wrote:
Hi,
Say I have a function "int add(int, int)" and want to use it in a call to std::transform with zip_iterators. Is there a way to do it without writing an intermediate function object?
If not, would it be sensible to write a generic one using the function_types library? I can't imagine this would be too hard but just wanted to know if there is anything I can leverage before writing it myself.
I guess what you're looking for is...
http://tinyurl.com/26t9dd =http://lists.boost.org/Archives/boost/2007/01/115135.php
http://tinyurl.com/y9ax7t =http://boost.cvs.sourceforge.net/boost/boost/boost/iterator/zip_iterator.hpp?view=log&pathrev=zip_iterator_fusion
It seems not so easy because of the Forwarding Problem.
Forwarding doesn't seem a problem to me since you already have the argument tuple. The return type inference is painful to get right, though. On the surface it seems as easy as template<class F, class Tp> ... unpack_and_call( F f, Tp const & tp ) { return unpack_and_call_( tuple_size<Tp>(), f, tp ); } template<class F, class Tp> ... unpack_and_call_( mpl::int_<0>, F f, Tp const & tp ) { return f(); } template<class F, class Tp> ... unpack_and_call_( mpl::int_<1>, F f, Tp const & tp ) { return f( get<0>(tp) ); } // and so on but the ... part is more involved if one decides to use result_of. boost::bind-style inference is of course easier since it only needs to look at F.