Hi
JLBorges,
thank you for your reply.
my issue is trying to put the loop and the lambda in the same function, namely the apply() function. This was supposed to reduce dependency (i.e. I prefer depending on boost or on lambda or on the two of them in only one place in my code if it is possible rather than in two or more places. The code first posted does satisfy this demand, still, I have been forced to use a base class for A<i>.
the parent class AB with its virtual functions serve as an interface to the different functions A<i>::f1 (and eventually A<i>::f2), i=0, 1,...
Because, when calling apply, the type T (in the expression "R (T::*fm)( Args... args )") must be well defined, it can not be a template type A<size_t>, so I use T = AB (for example &AB::f1 or &AB::f2).
Since AB has virtual member functions, when calling one of them from inside the loop, the compiler select the appropriate function depending on each tuple's element "x".
PS. about the return values of f2 for the different tup elements, I'm trying to catch them in an std::vector<R>, I'm getting some kid of error saying "reference to void"!
1 2 3 4 5 6 7 8 9 10
|
template < typename Seq, typename T, typename R, typename... Args >
inline static std::vector<R> apply_( Seq &seq, R (T::*fm)( Args... args ), Args... args )
{
std::cout << "B::apply_()\n";
// std::vector< std::add_lvalue_reference<R> > r_vec;
std::vector<R> r_vec;
boost::fusion::for_each( seq, [ &, args... ] (auto& x) { r_vec.push_back( (x.*fm)( args... ) ); } );
return r_vec;
}
|
Adim