Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <typeinfo>
- class NullType {};
- template<typename T=NullType, typename ... U>
- struct TypeList {
- using head = T;
- using tail = TypeList<U ...>;
- };
- template<typename T>
- struct TypeList<T> {
- using head = T;
- using tail = NullType;
- };
- using CharList = TypeList<char, signed char, unsigned char>;
- using EmptyList = TypeList<>;
- // struct TypeAt<unsigned int i, class T>;
- template<unsigned int i, typename T, typename ... U>
- struct TypeAt<0, TypeList<T, U...>> {
- using Result = T;
- };
- template<unsigned int i, class T, class ... U>
- struct TypeAt<i, TypeList<T, U ...>> {
- using Result = typename TypeAt<i - 1, U...>::Result;
- };
- // template <typename Head, typename Tail>
- // struct Length<TypeList<Head, Tail>> {
- // enum { value = Length<Tail>::value + 1};
- // };
- // template <typename Head, typename Tail>
- // struct Length<TypeList<NullType, NullType>> {
- // enum { value = 0};
- // };
- int main() {
- std::cout << typeid(EmptyList::head).name() << std::endl;
- std::cout << typeid(EmptyList::tail).name() << std::endl;
- // std::cout << Length<EmptyList>::value << std::endl;
- std::cout << typeid(TypeAt<0, CharList>::Result).name() << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement