pr31863.c

来自「用于进行gcc测试」· C语言 代码 · 共 777 行 · 第 1/2 页

C
777
字号
/* { dg-do link } */namespace Loki{    class NullType {};    template <class T, class U>    struct Typelist    {       typedef T Head;       typedef U Tail;    };    namespace TL    {        template        <                typename T1 = NullType, typename T2 = NullType, typename T3 =NullType,                typename T4 = NullType, typename T5 = NullType, typename T6 =NullType,                typename T7 = NullType, typename T8 = NullType, typename T9 =NullType,                typename T10 = NullType, typename T11 = NullType, typename T12= NullType,                typename T13 = NullType, typename T14 = NullType, typename T15= NullType,                typename T16 = NullType, typename T17 = NullType, typename T18= NullType,                typename T19 = NullType, typename T20 = NullType, typename T21= NullType,                typename T22 = NullType, typename T23 = NullType, typename T24= NullType,                typename T25 = NullType, typename T26 = NullType, typename T27= NullType,                typename T28 = NullType, typename T29 = NullType, typename T30= NullType,                typename T31 = NullType, typename T32 = NullType, typename T33= NullType,                typename T34 = NullType, typename T35 = NullType, typename T36= NullType,                typename T37 = NullType, typename T38 = NullType, typename T39= NullType,                typename T40 = NullType        >        struct MakeTypelist        {        private:            typedef typename MakeTypelist            <                T2 , T3 , T4 ,                T5 , T6 , T7 ,                T8 , T9 , T10,                T11, T12, T13,                T14, T15, T16,                T17, T18, T19,                T20, T21, T22,                T23, T24, T25,                T26, T27, T28,                T29, T30, T31,                T32, T33, T34,                T35, T36, T37,                T38, T39, T40            >            ::Result TailResult;        public:            typedef Typelist<T1, TailResult> Result;        };        template<>        struct MakeTypelist<>        {            typedef NullType Result;        };    }}template <class Key>class Factory;template <class Key, bool iW>struct Context{    typedef Key KeyType;    enum    {        isWrite = iW    };};namespace detail{template <class Key, bool isWrite>class CreatorUnitBaseImpl{public:    typedef Context<Key, isWrite> Context_;private:    typedef void*(CreatorUnitBaseImpl::*CreateFun)(Context_&, unsigned&, constKey&);    CreateFun createFun_;protected:    virtual void* createUninitialized () = 0;    template <class Value>    void* createImpl (Context_& ctx, unsigned& ver, const Key& k)    {        return createUninitialized();    }private:    CreatorUnitBaseImpl();public:    template <class Value>    CreatorUnitBaseImpl (Value*) :        createFun_( &CreatorUnitBaseImpl::template createImpl<Value> )    {    }    virtual ~CreatorUnitBaseImpl () {}    CreatorUnitBaseImpl(const CreatorUnitBaseImpl& s)        : createFun_(s.createFun_)    {    }    CreatorUnitBaseImpl& operator=(const CreatorUnitBaseImpl& s)    {        createFun_ = s.createFun_;        return *this;    }    void* create (Context_& ctx, unsigned& ver, const Key& k)    {        return (this->*createFun_)(ctx, ver, k);    }};template <class Key>class Creator : protected CreatorUnitBaseImpl<Key, true>, protectedCreatorUnitBaseImpl<Key, false>{public:    typedef void* (*CreatorFun) ();private:    CreatorFun fun_;protected:    virtual void* createUninitialized ()    {        if (fun_)            return (*fun_)();        return 0;    }private:    Creator ();public:    template <class Value>    Creator (CreatorFun f, Value*) :        CreatorUnitBaseImpl<Key, true>((Value*)0),        CreatorUnitBaseImpl<Key, false>((Value*)0),        fun_(f)    {    }    Creator(const Creator& s) :        CreatorUnitBaseImpl<Key, true>(s),        CreatorUnitBaseImpl<Key, false>(s),        fun_(s.fun_)    {    }    Creator& operator=(const Creator& s)    {        CreatorUnitBaseImpl<Key, true>::operator=(s);        CreatorUnitBaseImpl<Key, false>::operator=(s);        fun_ = s.fun_;        return *this;    }    virtual ~Creator ()    {    }    template <class Context>    void* createObject (Context& ctx, unsigned& ver, const Key& k)    {        void* r = CreatorUnitBaseImpl<Key, Context::isWrite>::create(ctx, ver,k);        return r;    }};}template <class Key>class Factory{public:    typedef Key KeyType;    typedef void* (*CreatorFun) ();    typedef detail::Creator<Key> Creator;public:    Factory () {}    ~Factory () {}    template <class Value>    bool registerCreator (const Key& k, CreatorFun fun)    {        return true;    }    template <class Context>    void* createObject (const Key& k, Context& ctx, unsigned& ver)    {        return 0;    }};template <class Key, class Base, Key key>struct ClassSpec{    typedef Key KeyType;    typedef Base BaseType;    enum {KeyValue = key};};template <class Key, class T>class Serializer;template <class Key, class Base, Key key>class Serializer<Key, ClassSpec <Key, Base, key> >    : public virtual Factory<Key>{    typedef Key KeyType;    typedef Base BaseType;    enum {KeyValue = key};    typedef Factory<Key> Inherited;    typedef Serializer<Key, ClassSpec< Key, Base, key > > SelfType;    static void* create ()    {        return (void*) (new BaseType);    }public:    Serializer()    {        Inherited::template registerCreator<BaseType>(                KeyValue,                &SelfType::create);    }};template <class Key, class Head>class Serializer<Key, Loki::Typelist<Head, Loki::NullType> >:    public Serializer<Key, Head>{};template <class Key, class Head, class Tail>class Serializer<Key, Loki::Typelist<Head, Tail> >:    public virtual Serializer<Key, Head>,    public virtual Serializer<Key, Tail>{};template <class Key>class Serializer<Key, Loki::NullType> : public virtual Factory<Key>{};typedef unsigned KeyType;typedef Factory<KeyType> FactoryType;typedef KeyType Key;struct A001{    template <class Context>    bool serialize(Context& ctx, unsigned& ver)    {        return true;    }    static Key classId() { return 1; }    static const char* className () {return "A001";}};struct A002{    template <class Context>    bool serialize(Context& ctx, unsigned& ver)    {        return true;    }    static Key classId() { return 2; }    static const char* className () {return "A002";}};struct A003{    template <class Context>    bool serialize(Context& ctx, unsigned& ver)    {        return true;    }    static Key classId() { return 3; }    static const char* className () {return "A003";}};struct A004{    template <class Context>    bool serialize(Context& ctx, unsigned& ver)    {        return true;    }    static Key classId() { return 4; }    static const char* className () {return "A004";}};struct A005{    template <class Context>    bool serialize(Context& ctx, unsigned& ver)    {        return true;    }    static Key classId() { return 5; }    static const char* className () {return "A005";}};struct A006{    template <class Context>    bool serialize(Context& ctx, unsigned& ver)    {        return true;    }    static Key classId() { return 6; }    static const char* className () {return "A006";}};struct A007{    template <class Context>    bool serialize(Context& ctx, unsigned& ver)    {        return true;    }    static Key classId() { return 7; }    static const char* className () {return "A007";}};struct A008{    template <class Context>    bool serialize(Context& ctx, unsigned& ver)    {        return true;    }    static Key classId() { return 8; }    static const char* className () {return "A008";}};struct A009{    template <class Context>    bool serialize(Context& ctx, unsigned& ver)    {        return true;    }    static Key classId() { return 9; }    static const char* className () {return "A009";}};struct A010{    template <class Context>    bool serialize(Context& ctx, unsigned& ver)    {        return true;    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?