vinay patel
vinay patel

Reputation: 175

Erasing type from a typelist c++ metaprogramming

What is the meaning of Erasing type from a typelist in c++ meta programming. Can any one suggest any simple example.

    class null_typelist {};

    template <class H, class T>
    struct typelist
    {
        typedef H head;
        typedef T tail;

    };
template<class T1, class T2=null_typelist, class T3=null_typelist, class T4=null_typelist> struct List;

    template <class T1, class T2, class T3>
    struct List<T1, T2, T3, null_typelist>
    {
        typedef typelist<T1, typelist<T2, typelist<T3,null_typelist> > > type;

    };


    template <class H, class T>
    class ABC< typelist<H, T> > : public ABC<T>
    {
        ...
    };


    template <class H>
    class ABC< typelist<H, null_typelist> >
    {
    ...
    };

    struct Elements{};
    struct A: Elements{};
    struct B: Elements{};
    struct C: Elements{};

 typedef List<A,B,C>::type MyOBJ;

     struct Createobject : ABC<MyOBJ>
    { 
        ...

    };

    int main()
    {

        Createobject obj;

    }

Here in this case if i have to remove B from type list. is it possible to remove it ? and how i can remove type B.

Upvotes: 0

Views: 400

Answers (1)

Tony Delroy
Tony Delroy

Reputation: 106068

From Loki's Typelist.h:

00233 // class template Erase
00234 // Erases the first occurence, if any, of a type in a typelist
00235 // Invocation (TList is a typelist and T is a type):
00236 // Erase<TList, T>::Result
00237 // returns a typelist that is TList without the first occurence of T

So, if a typelist TList mentions say int, double, and char - Erase<TList, double>::Result would return a typelist for just int and char.

If you just don't understand what a typelist is, then perhaps you should post that as a separate question or ask that here as well....

Upvotes: 1

Related Questions