Is it possible to iterate over a tuple with a lambda using boost::mpl::for_each? MPL documentation creates a separate class away from the call size which iterates over types given to for_each, can a lambda be used instead? Or can the separate class be written to take as an argument a lambda that would be applied with all types given to for_each? Something like this, except that incrementer should take a lambda (in constructor?) which defines the operations to do and which could be written at the call site of for_each:
#include "boost/mpl/for_each.hpp"
#include "tuple"
using namespace std;
using namespace boost::mpl;
template<class Tuple_T>
struct incrementer
{
incrementer(Tuple_T& given) : tuple(given){}
template<class T> void operator()(const T&)
{
// how to write this in main() instead?
// [&](?){? += 1}?
get<T>(this->tuple) += 1;
}
Tuple_T& tuple;
};
int main(){
tuple<int, float, double> t{1, 2, 3};
for_each<int, double>(incrementer<decltype(t)>(t));
assert(get<0>(t) == 2);
assert(get<1>(t) == 2);
assert(get<2>(t) == 4);
return 0;
}