X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fcore%2Ftypelist.h;fp=source%2Fcore%2Ftypelist.h;h=0000000000000000000000000000000000000000;hp=ecc28faf64b1d41d2ca20e599ef1aac8935238e5;hb=9f754b788b872f9768af8c3a4f9e001a588e011a;hpb=f7087c847a03a2bb4e9392e41eac4cb1ec37172c diff --git a/source/core/typelist.h b/source/core/typelist.h deleted file mode 100644 index ecc28fa..0000000 --- a/source/core/typelist.h +++ /dev/null @@ -1,130 +0,0 @@ -#ifndef MSP_CORE_TYPELIST_H_ -#define MSP_CORE_TYPELIST_H_ - -namespace Msp { - -/** Sentinel type for type lists */ -struct NullType { }; - - -/** A "cons cell" for types. Composed of a head and a tail. To construct -longer lists, use another TypeCons as the tail. The tail of the last TypeCons -should by NullType. */ -template -struct TypeCons -{ - typedef H Head; - typedef T Tail; -}; - - -/** Basic terminated type list of one element. */ -template -struct TypeList1 -{ - typedef TypeCons Type; -}; - -/** Specialization to avoid creating a TypeCons with two NullTypes. */ -template<> -struct TypeList1 -{ - typedef NullType Type; -}; - -/** Specialization to avoid creating a TypeCons with another TypeCons as its -head. */ -template -struct TypeList1 > -{ - typedef TypeCons Type; -}; - -/** Basic terminated type list of two elements. */ -template -struct TypeList2 -{ - typedef TypeCons::Type> Type; -}; - -/** Specialization to ignore an initial NullType. */ -template -struct TypeList2 -{ - typedef typename TypeList1::Type Type; -}; - -/** Specialization to flatten an initial TypeCons. */ -template -struct TypeList2, T3> -{ - typedef typename TypeList2::Type>::Type Type; -}; - - -/** A terminated type list of five elements. Use the typedef Type inside to -obtain the actual list type. If any of the types is a type list itself, the -entire structure is flattened to a single list. */ -template -struct TypeList -{ - typedef typename TypeList::Type>::Type Type; -}; - -/** Specialization of TypeList for one element. */ -template -struct TypeList -{ - typedef typename TypeList1::Type Type; -}; - -/** Specialization of TypeList for two elements. */ -template -struct TypeList -{ - typedef typename TypeList2::Type Type; -}; - -/** Specialization of TypeList for three elements. */ -template -struct TypeList -{ - typedef typename TypeList::Type>::Type Type; -}; - -/** Specialization of TypeList for four elements. */ -template -struct TypeList -{ - typedef typename TypeList::Type>::Type Type; -}; - - -/** A helper for selecting a type from a list based on a predicate. The -predicate should be a template taking a single type argument and defining a -compile-time constant with the name "value", which evaluates to true if the -type is considered a match. The result can be obtained from the member -typedef Type. If the list contains no matching type, an ugly and confusing -compiler error will result. */ -template class P, bool f = P::value> -struct TypeChooser; - -/** Specialization for a matching type. Picks the head of the list as the -result. */ -template class P> -struct TypeChooser -{ - typedef typename L::Head Type; -}; - -/** Specialization for a non-matchin type. Recursively inspects the tail of -the list. */ -template class P> -struct TypeChooser -{ - typedef typename TypeChooser::Type Type; -}; - -} // namespace Msp - -#endif