I try to invoke function void set (...) recursively using metaprogramming.
The problem is that it seems to invokes only once.
template <int N>
struct GEN
{
enum {value = GEN<N-1>::value};
template <typename T>
static inline void set(T& tup, int l_item)
{
cout<<"item value: "<<l_item<<", N-1: "<< N-1 << ", value: "<<value <<endl;
typedef typename boost::tuples::element<N-1, T>::type _el_type;
get<N-1>(tup) = atomic_item<N-1, _el_type>(l_item);
};
};
template<>
struct GEN<0>
{
enum {value = 0};
template <typename T>
static inline void set(T& tup, int l_item)
{
typedef typename boost::tuples::element<0, T>::type _el_type;
get<0>(tup) = atomic_item<0, _el_type>(l_item);
};
};
main(){
....
/** this is how i try to invoke it */
GEN<3>::set(w,1);
}
Output:
item value: 1, N-1: 2, value: 0
function has been invoked only once...
EDIT
is there a way to do kind of loop with for_each or anything else to get something simmilar:
for_each<range_c<int,0,3> f{operator()(T i)GEN<typename T::value>::set(w,1)}>
or something similar to achieve invoke for all of those elements?
Particularly I'd like to have this:
GEN<3>::set(w,1);
GEN<2>::set(w,1);
GEN<1>::set(w,1);
In loop.