What is the NIL structure {typedef NIL Head; }?

I read about metaprogramming patterns. I could not understand what these lines mean; The following code refers to performing metaprogramming in 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 comes from https://monoinfinito.wordpress.com/series/introduction-to-c-template-metaprogramming/ . I would really appreciate any guidance on what it means to have a NIL structure that has typedef NIL Head and typedef NIL Tail. Nil is a type, of course, but if I have a typedef NIL Head, for example, does this mean that I have another recursive head and tail in each head?

+6
source share
2

, typedef NIL Head; , NIL NIL.

, NIL::Head - NIL. NIL::Tail.

, , NIL::Head::Tail::Tail::Tail::Head::Head NIL. .

+7

NIL - .

NULL, .

LISP "head" "tail". , NIL.

NIL , NIL. :

struct NIL;

template <typename H, typename T=NIL> struct Lst {
  typedef H Head;
  typedef T Tail;
};

struct NIL: Lst {};

NIL .

NIL , ( ). , , , NIL ; , , NIL.

typedef "" , , . , . :

struct node {
  node* head, *tail;
};
struct NIL:node{
  NIL() : node{this, this} {}
};
+2

All Articles