Loki的TypeList技术解析(三)

2014-11-23 23:41:32 · 作者: · 浏览: 2
, T> { // Go all the way down the list removing the type typedef typename EraseAll ::Result Result; }; template struct EraseAll , T> { // Go all the way down the list removing the type typedef Typelist ::Result> Result; }; //////////////////////////////////////////////////////////////////////////////// // class template NoDuplicates // Removes all duplicate types in a typelist // Invocation (TList is a typelist): // NoDuplicates ::Result //////////////////////////////////////////////////////////////////////////////// template struct NoDuplicates; template <> struct NoDuplicates { typedef NullType Result; }; template struct NoDuplicates< Typelist > { private: typedef typename NoDuplicates ::Result L1; typedef typename Erase ::Result L2; public: typedef Typelist 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 ::Result // returns a typelist in which the first occurence of T is replaced with U //////////////////////////////////////////////////////////////////////////////// template struct Replace; template struct Replace { typedef NullType Result; }; template struct Replace , T, U> { typedef Typelist Result; }; template struct Replace , T, U> { typedef Typelist ::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 ::Result // returns a typelist in which all occurences of T is replaced with U //////////////////////////////////////////////////////////////////////////////// template struct ReplaceAll; template
struct ReplaceAll { typedef NullType Result; }; template struct ReplaceAll , T, U> { typedef Typelist ::Result> Result; }; template struct ReplaceAll , T, U> { typedef Typelist ::Result> Result; }; //////////////////////////////////////////////////////////////////////////////// // class template Reverse // Reverses a typelist // Invocation (TList is a typelist): // Reverse ::Result // returns a typelist that is TList reversed //////////////////////////////////////////////////////////////////////////////// template struct Reverse; template <> struct Reverse { typedef NullType Result; }; template struct Reverse< Typelist > { typedef typename Append< typename Reverse ::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 ::Result // returns the type in TList that's the most derived from T //////////////////////////////////////////////////////////////////////////////// template struct MostDerived; template struct MostDerived { typedef T Result; }; template struct MostDerived , T> { private: typedef typename MostDerived ::Result Candidate; public: typedef typename Select< SuperSubclass ::value, Head, Candidate>::Result Result; }; //////////////////////////////////////////////////////////////////////////////// // class template DerivedToFront // Arranges the types in a typelis