2013-02-08 57 views
0

什麼意思是從類型列表中刪除類型在C++元編程中。任何人都可以提出任何簡單的例子。從類型列表中刪除類型C++元編程

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; 

    } 

在這種情況下,如果我必須從類型列表中刪除B.是否有可能將其刪除?以及如何我可以刪除類型B.

+0

[鏈接](http://books.google .co.in /書?ID = aJ1av7UFBPwC&PG = PA58&LPG = PA58&DQ =擦除+型+從+α+類型串&源= BL&OTS = YRgDZnTf51&SIG = L_n6EQJeIfQvGhuaZdeNr3_JH1g&HL = EN&SA = X&EI = xZwUUdasAoWKrgfJlYDgCA&VED = 0CDUQ6AEwAQ#v = onepage&q =擦除%20type%20from%20A %20typelist&F =假) – 2013-02-08 06:37:24

回答

1

從Loki的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 

所以,如果TList提到了一個類型串說intdouble,並char - Erase<TList, double>::Result將返回一個類型串只是intchar

如果你只是不明白一個類型串是什麼,那麼也許你應該張貼,作爲一個單獨的問題或要求,這裏還有....