Tupleoperator的实现也主要用FieldHelper来实现,借用了Loki::TL::IterateTypes的思想
template <int LastLength, class H, template <class> class Operator>
struct TupleOperator
{
typedef Loki::TL::Length<typename H::TList> lengh;
typedef Loki::FieldHelper<H,lengh::value-LastLength> head_helper;
typedef typename head_helper::ResultType head_t;
typedef TupleOperator<LastLength-1,H, Operator> tail_t;
tail_t tail;
void operator()(H& obj)
{
Operator<head_t> op;
op(head_helper::Do(obj));
tail.operator()(obj);
}
};
template <class H, template <class> class Operator>
struct TupleOperator<0,H,Operator>
{
void operator()(H& obj){}
};
template <int LastLength, class H, template <class> class Operator>
struct TupleOperator
{
typedef Loki::TL::Length<typename H::TList> lengh;
typedef Loki::FieldHelper<H,lengh::value-LastLength> head_helper;
typedef typename head_helper::ResultType head_t;
typedef TupleOperator<LastLength-1,H, Operator> tail_t;
tail_t tail;
void operator()(H& obj)
{
Operator<head_t> op;
op(head_helper::Do(obj));
tail.operator()(obj);
}
};
template <class H, template <class> class Operator>
struct TupleOperator<0,H,Operator>
{
void operator()(H& obj){}
};