⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 typelist.h

📁 exmat - The Expression Template Matrix Library,是矩阵运算模板库
💻 H
📖 第 1 页 / 共 3 页
字号:
            ASSERT_TYPELIST(TList);

            template<class TList1>
            struct In
            {
                typedef typename TList1::Tail Tail;

                typedef Typelist
                <
                    Head, 
                    typename Erase<Tail, T>::Result
                >
                Result;
            };

            template<>
            struct In< Typelist<T, Tail> >
            {
                typedef Tail Result;
            };

            template<>
            struct In<NullType>
            {
                typedef NullType Result;
            };

        public:
            typedef typename In<TList>::Result Result;
        };

////////////////////////////////////////////////////////////////////////////////
// class template EraseAll
// Erases all first occurences, if any, of a type in a typelist
// Invocation (TList is a typelist and T is a type):
// EraseAll<TList, T>::Result
// returns a typelist that is TList without any occurence of T
////////////////////////////////////////////////////////////////////////////////

        template <class TList, class T> 
        struct EraseAll
        {
            typedef typename TList::Head Head;
            typedef typename TList::Tail Tail;
        
        private:
            ASSERT_TYPELIST(TList);

            template<class TList1>
            struct In
            {
            private:
                typedef typename TList1::Tail Tail;
                typedef typename EraseAll<Tail, T>::Result TailResult;
            
            public:
                typedef typename Select
                <
                    IsSameType<Head, T>::value,
                    TailResult,
                    Typelist<Head, TailResult>
                >
                ::Result Result;
            };

            template<>
            struct In<NullType>
            {
                typedef NullType Result;
            };

        public:
            typedef typename In<TList>::Result Result;
        };

////////////////////////////////////////////////////////////////////////////////
// class template NoDuplicates
// Removes all duplicate types in a typelist
// Invocation (TList is a typelist):
// NoDuplicates<TList, T>::Result
////////////////////////////////////////////////////////////////////////////////

        template <class TList> 
        struct NoDuplicates
        {
        private:
            typedef typename TList::Head Head;
            typedef typename TList::Tail Tail;
        
            ASSERT_TYPELIST(TList);

            typedef typename NoDuplicates<Tail>::Result L1;
            typedef typename Erase<L1, Head>::Result    L2;

        public:
            typedef Typelist<Head, L2> Result;
        };
        
        template <> 
        struct NoDuplicates<NullType>
        {
            typedef NullType Result;
        };

////////////////////////////////////////////////////////////////////////////////
// class template Replace
// Replaces the first occurence of a type in a typelist, with another type
// Invocation (TList is a typelist, T, U are types):
// Replace<TList, T, U>::Result
// returns a typelist in which the first occurence of T is replaced with U
////////////////////////////////////////////////////////////////////////////////

        template <class TList, class T, class U> 
        struct Replace
        {
            typedef typename TList::Head Head;
            typedef typename TList::Tail Tail;
        
        private:
            ASSERT_TYPELIST(TList);

            template<class TList1>
            struct In
            {
                typedef typename TList1::Tail Tail;

                typedef Typelist
                <
                    Head, 
                    typename Replace<Tail, T, U>::Result
                >
                Result;
            };

            template<>
            struct In< Typelist<T, Tail> >
            {
                typedef Typelist<U, Tail> Result;
            };

            template<>
            struct In<NullType>
            {
                typedef NullType Result;
            };

        public:
            typedef typename In<TList>::Result Result;
        };

////////////////////////////////////////////////////////////////////////////////
// class template ReplaceAll
// Replaces all occurences of a type in a typelist, with another type
// Invocation (TList is a typelist, T, U are types):
// Replace<TList, T, U>::Result
// returns a typelist in which all occurences of T is replaced with U
////////////////////////////////////////////////////////////////////////////////

        template <class TList, class T, class U> 
        struct ReplaceAll
        {
            typedef typename TList::Head Head;
            typedef typename TList::Tail Tail;
        
        private:
            ASSERT_TYPELIST(TList);

            template<class TList1>
            struct In
            {
            private:
                typedef typename TList1::Tail Tail;
                typedef typename ReplaceAll<Tail, T, U>::Result TailResult;
            
            public:
                typedef typename Select
                <
                    IsSameType<Head, T>::value,
                    Typelist<U,    TailResult>,
                    Typelist<Head, TailResult>
                >
                ::Result Result;
            };

            template<>
            struct In<NullType>
            {
                typedef NullType Result;
            };

        public:
            typedef typename In<TList>::Result Result;
        };

////////////////////////////////////////////////////////////////////////////////
// class template Reverse
// Reverses a typelist
// Invocation (TList is a typelist):
// Reverse<TList>::Result
// returns a typelist that is TList reversed
////////////////////////////////////////////////////////////////////////////////

        template <class TList> struct Reverse;
        
        template <>
        struct Reverse<NullType>
        {
            typedef NullType Result;
        };
        
        template <class TList> 
        struct Reverse
        {
        private:
            typedef typename TList::Head Head;
            typedef typename TList::Tail Tail;
        
            ASSERT_TYPELIST(TList);

        public:
            typedef typename Append<
                typename Reverse<Tail>::Result, Head>::Result Result;
        };


////////////////////////////////////////////////////////////////////////////////
// class template MostDerived
// Finds the type in a typelist that is the most derived from a given type
// Invocation (TList is a typelist, T is a type):
// Replace<TList, T>::Result
// returns the type in TList that's the most derived from T
////////////////////////////////////////////////////////////////////////////////

        template <class TList, class T> 
        struct MostDerived
        {
            typedef typename TList::Head Head;
            typedef typename TList::Tail Tail;
        
        private:
            ASSERT_TYPELIST(TList);

            template<class TList1>
            struct In
            {
            private:
                typedef typename TList1::Tail Tail;
                typedef typename TList1::Head Head;
                typedef typename MostDerived<Tail, T>::Result Candidate;
            
            public:
                typedef typename Select
                <
                    SUPERSUBCLASS(Candidate, Head),
                    Head, Candidate
                >
                ::Result Result;
            };

            template<>
            struct In<NullType>
            {
                typedef T Result;
            };

        public:
            typedef typename In<TList>::Result Result;
        };
        
////////////////////////////////////////////////////////////////////////////////
// class template DerivedToFront
// Arranges the types in a typelist so that the most derived types appear first
// Invocation (TList is a typelist):
// DerivedToFront<TList>::Result
// returns the reordered TList 
////////////////////////////////////////////////////////////////////////////////
        
        template <class TList> struct DerivedToFront;
        
        template <>
        struct DerivedToFront<NullType>
        {
            typedef NullType Result;
        };
        
        template <class TList>
        struct DerivedToFront
        {
        private:
            ASSERT_TYPELIST(TList);

            typedef typename TList::Head Head;
            typedef typename TList::Tail Tail;
        
            typedef typename MostDerived<Tail, Head>::Result TheMostDerived;
            typedef typename Replace<Tail, TheMostDerived, Head>::Result Temp;
            typedef typename DerivedToFront<Temp>::Result L;

        public:
            typedef Typelist<TheMostDerived, L> Result;
        };
                

////////////////////////////////////////////////////////////////////////////////
// class template DerivedToFrontAll
// Arranges all the types in a typelist so that the most derived types appear first
// Invocation (TList is a typelist):
// DerivedToFront<TList>::Result
// returns the reordered TList 
////////////////////////////////////////////////////////////////////////////////
        
        template <class TList> struct DerivedToFrontAll;
        
        template <>
        struct DerivedToFrontAll<NullType>
        {
            typedef NullType Result;
        };
        
        template <class TList>
        struct DerivedToFrontAll
        {
        private:
            ASSERT_TYPELIST(TList);

            typedef typename TList::Head Head;
            typedef typename TList::Tail Tail;
        
            typedef typename MostDerived<Tail, Head>::Result TheMostDerived;
            typedef typename Replace<Tail, TheMostDerived, Head>::Result L;
            
            typedef typename DerivedToFrontAll<L>::Result TailResult;

        public:
            typedef Typelist<TheMostDerived, TailResult> Result;
        };
                                    
    }   // namespace TL
}   // namespace Loki

////////////////////////////////////////////////////////////////////////////////
// Change log:
// June 09, 2001: Fix bug in parameter list of macros TYPELIST_23 to TYPELIST_27
//      (credit due to Dave Taylor)
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
// May  10, 2002: ported by Rani Sharoni to VC7 (RTM - 9466)
// Oct  10, 2002: added MakeTypelist (SGB/MKH)
// Oct  11, 2002: DerivedToFront was incorrectly using ReplaceAll, now uses Replace
////////////////////////////////////////////////////////////////////////////////

#endif // TYPELIST_INC_

⌨️ 快捷键说明

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