【问题标题】:Erasing type from a typelist c++ metaprogramming从类型列表中擦除类型 C++ 元编程
【发布时间】:2013-01-23 21:22:34
【问题描述】:

c++元编程中Erasing type from a typelist是什么意思。任何人都可以提出任何简单的例子。

    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 型。

【问题讨论】:

标签: c++ template-meta-programming loki


【解决方案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 提到 intdoublechar - Erase&lt;TList, double&gt;::Result 将返回一个类型列表仅用于 intchar

如果您只是不了解类型列表是什么,那么也许您应该将其作为一个单独的问题发布,或者也在这里提出......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-17
    • 1970-01-01
    • 1970-01-01
    • 2016-04-21
    • 2017-08-07
    相关资源
    最近更新 更多