📄 typelist.h
字号:
{
template <class TList>
struct EraseImpl
{ // TList is not NullType.
// Check if TList::Head is equal to T
// if T is the same as TList::Head, then the Result is TList::Tail
//
// if TList is not NullType and TList::Head is not equal to T,
// then the Result is a Typelist having TList::Head as its Head
// and the result of applying Erase to the tail of list as its
// tail.
template <class T>
struct In
{
ASSERT_TYPELIST(TList);
typedef typename TList::Head Head;
typedef typename TList::Tail Tail;
typedef typename Select
<
IsEqualType<Head, T>::value, // is T equal to Head?
Tail, // Yes. Result is tail
Typelist<typename TList::Head, // No. recurse
typename Erase<typename TList::Tail, T>::Result>
>::Result Result;
};
};
// if TList is NullType the result is NullType.
template <>
struct EraseImpl<NullType>
{
template <class T>
struct In
{
typedef NullType Result;
};
};
} // end of namespace Private
template <class TList, class T>
struct Erase
{
typedef typename Private::EraseImpl<TList>::template In<T>::Result Result;
};
////////////////////////////////////////////////////////////////////////////////
// class template EraseAll
// Erases all 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;
namespace Private
{
template <class TList>
struct EraseAllImpl
{ // TList is not NullType.
// Check if TList::Head is equal to T
// If T is equal to TLIst::Head the result is the result of EraseAll
// applied to TList::Tail
//
// If T is not equal to TList::Head the result is a Typelist with
// TList::Head as its head and the result of applying EraseAll to TList::Tail
// as its tail.
template <class T>
struct In
{
ASSERT_TYPELIST(TList);
typedef typename TList::Head Head;
typedef typename TList::Tail Tail;
typedef typename Select
<
IsEqualType<Head, T>::value, // is T == Head?
typename EraseAll<Tail, T>::Result, // Yes
Typelist<Head, typename // No
EraseAll<Tail, T>::Result>
>::Result Result;
};
};
// if TList is NullType the result is NullType.
template <>
struct EraseAllImpl<NullType>
{
template <class T>
struct In
{
typedef NullType Result;
};
};
} // end of namespace Private
template <class TList, class T>
struct EraseAll
{
typedef typename Private::EraseAllImpl<TList>::template In<T>::Result Result;
};
////////////////////////////////////////////////////////////////////////////////
// class template NoDuplicates
// Removes all duplicate types in a typelist
// Invocation (TList is a typelist):
// NoDuplicates<TList, T>::Result
////////////////////////////////////////////////////////////////////////////////
// NoDuplicates taken from Rani Sharoni's Loki VC7-Port.
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;
namespace Private
{
// If TList is not NullType, check if T is equal to TList::Head
template <class TList>
struct ReplaceImpl
{
template <class T, class U>
struct In
{
// If TList::Head is equal to T, the result is a typelist
// with U as its head an TList::Tail as its tail.
// If T is not equal to TList::Head, the result is a typelist
// with TList::Head as its head and the result of applying
// Replace to TList::Tail, T, U as its tail
ASSERT_TYPELIST(TList);
typedef typename TList::Head Head;
typedef typename TList::Tail Tail;
typedef typename Select
<
IsEqualType<T, Head>::value, // Is T == Head?
Typelist<U, Tail>, // yes
Typelist<Head, typename Replace<Tail, T, U>::Result>
>::Result Result;
};
};
// If TList is NullType the result is NullType
template <>
struct ReplaceImpl<NullType>
{
template <class T, class U>
struct In
{
typedef NullType Result;
};
};
} // end of namespace Private
template <class TList, class T, class U>
struct Replace
{
typedef typename
Private::ReplaceImpl<TList>::template In<T, U>::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;
namespace Private
{
// If TList is not NullType, check if T is equal to TList::Head
template <class TList>
struct ReplaceAllImpl
{
template <class T, class U>
struct In
{
ASSERT_TYPELIST(TList);
typedef typename TList::Head Head;
typedef typename TList::Tail Tail;
typedef typename Select
<
IsEqualType<T, Head>::value, // Is T == Head?
Typelist<U, typename ReplaceAll<Tail, T, U>::Result>, // yes
Typelist<Head, typename ReplaceAll<Tail, T, U>::Result>
>::Result Result;
};
};
// If TList is NullType the result is NullType
template <>
struct ReplaceAllImpl<NullType>
{
template <class T, class U>
struct In
{
typedef NullType Result;
};
};
}
template <class TList, class T, class U>
struct ReplaceAll
{
typedef typename
Private::ReplaceAllImpl<TList>::template In<T, U>::Result Result;
};
////////////////////////////////////////////////////////////////////////////////
// class template Reverse
// Reverses a typelist
// Invocation (TList is a typelist):
// Reverse<TList>::Result
// returns a typelist that is TList reversed
////////////////////////////////////////////////////////////////////////////////
// Reverse taken from Rani Sharoni's Loki VC7-Port.
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):
// MostDerived<TList, T>::Result
// returns the type in TList that's the most derived from T
////////////////////////////////////////////////////////////////////////////////
template <class TList, class T> struct MostDerived;
namespace Private
{
template <class TList>
struct MostDerivedImpl
{
template <class T>
struct In
{
private:
ASSERT_TYPELIST(TList);
typedef typename TList::Head Head;
typedef typename TList::Tail Tail;
typedef typename MostDerived<Tail, T>::Result Candidate;
public:
typedef typename Select
<
SUPERSUBCLASS(Candidate, Head),
Head,
Candidate
>::Result Result;
};
};
template <>
struct MostDerivedImpl<NullType>
{
template <class T>
struct In {typedef T Result;};
};
} // end of namespace Private
template <class TList, class T>
struct MostDerived
{
typedef typename
Private::MostDerivedImpl<TList>::template In<T>::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
{
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;
};
template <>
struct DerivedToFront<NullType>
{
typedef NullType 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
////////////////////////////////////////////////////////////////////////////////
// DerivedToFrontAll taken from Rani Sharoni's Loki VC7-Port.
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;
};
template <>
struct DerivedToFrontAll<NullType>
{
typedef NullType Result;
};
} // end of namespace TL
} // end of 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)
// Sept 29, 2002: ported by Benjamin Kaufmann to MSVC 6.0
// Feb 24, 2003: renamed MakeTypeList to MakeTypelist. Fixed a bug in
// DerivedToFront.
////////////////////////////////////////////////////////////////////////////////
#endif // TYPELIST_INC_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -