GENERATING TUPLES
Many of the readers would have studied tuples in python. They are immutable set of values stored in one variable name in a ordered manner.
Loki library introduces tuples which is similar to GenScatterHierarchy and provides direct field access.
Let us understand how it gives the direct Field access through an example code
template <class T>
struct Holder
{
T value_;
};
typedef GenScatterHierarchy<
TYPELIST_3(int, int, int),
Holder>
Point3D;
To access the field of object , the syntax would be using the static case of the representation of class template and the value_.
static_cast<Holder<string>&>(obj)).value_
But through Field access functions it returns the reference of the value_. Like here it returns Holder<int>& instead of int&.
Through tuples we get the direct access using the index of the type provided as shown below:
typedef Tuple<TYPELIST_3(int, int, int)>
Point3D;
Point3D pt;
Field<0>(pt) = 0;
Field<1>(pt) = 100;
Field<2>(pt) = 300;
The tuple functions in the Loki library are stacked in "Tuple.h".
Comments