I am reading about template metaprogramming. I could not understand what these lines mean; the following code concerns about doing metaprogramming on a linked list.
struct NIL {
typedef NIL Head;
typedef NIL Tail;
};
template <typename H, typename T=NIL> struct Lst {
typedef H Head;
typedef T Tail;
};
template <int N> struct Int{ static const int result = N; };
typedef Lst< Int<1>, Lst< Int<2>, Lst< Int<3> > > > OneTwoThree;
The above is coming from https://monoinfinito.wordpress.com/series/introduction-to-c-template-metaprogramming/ . I would greatly appreciate any guidance as to what it means to have struct NIL, which has typedef NIL Head, and typedef NIL Tail. Nil is a type, sure, but if I have typedef NIL Head, for example, does it mean i have another recursive Head and Tail within each Head?
NIL
ism in here somewhere. – KennerNIL
is right up there as award-winningly bad. That name is astonishingly misleading. Anyone who recommends doing this is a mad scientist, and I don't mean the good kind. – SteepleNodeInList
rather thanNIL
– Ownershipstd::tuple
instantiations as type lists. The techniques from Modern C++ (and the Loki library) are no longer very relevant. You would do well to get a book from after 2011. – CartoonLst
should be renamedCons
, andHead
andTail
should beCar
andCdr
... – Donate