007
13.03.2010, 21:16 Uhr
Prog
|
Ich muss noch mal korrigieren:
C++: |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include <cstddef> #include <iostream> #include <tuple> #include <typeinfo> #include <utility>
template< typename, typename > struct append_to_tuple_type; template<template <typename...> class, typename...> struct assemble_tuple_type; template<std::size_t, std::size_t, template <typename...> class, typename...> struct init_func_tuple; template< typename...> struct make_function_pointer; template< typename...> struct vt_count; template< std::size_t, typename...> struct vt_deref;
template < typename ... Types > struct Klasse { template < ::std::size_t Index > struct Result{ typedef typename ::std::tuple_element< Index, ::std::tuple< Types ... > >::type type; };
template < ::std::size_t Index > typename Result< Index >::type funktion(){ // Zum testen beispielsweise: return static_cast< typename Result< Index >::type >(Index); } };
template <template <typename...> class C, typename ...T> struct func_tuple_t { typedef typename assemble_tuple_type<C, T...>::type type; };
template <template <typename...> class C, typename ...T> typename func_tuple_t<C, T...>::type func_tuple() { typename func_tuple_t<C, T...>::type f; init_func_tuple<0, vt_count<T...>::val, C, T...>::doit(f); return f; }
template<std::size_t pos, std::size_t max, template <typename...> class C, typename... T> struct init_func_tuple { static void doit(typename func_tuple_t<C, T...>::type &f) { init_func_tuple<pos + 1, max, C, T...>::doit(f); std::get<pos>(f) = &C<T...>::template funktion<pos>; } };
template<std::size_t pos, template <typename...> class C, typename... T> struct init_func_tuple<pos, pos, C, T...> { static void doit(typename func_tuple_t<C, T...>::type &f) { } };
template < typename Type, typename ReturnType, typename ... Parameters > struct make_function_pointer<Type, ReturnType, Parameters...> { typedef ReturnType(Type::*type)(Parameters ...); };
template<typename... T> struct vt_count { static std::size_t const val = sizeof...(T); };
template<typename... T, typename V> struct append_to_tuple_type<std::tuple<T...>, V> { typedef std::tuple<T..., V> type; };
template<std::size_t pos, typename T, typename... U> struct vt_deref<pos, T, U...> { typedef typename vt_deref<pos - 1, U...>::type type; }; template<typename T, typename... U> struct vt_deref<0, T, U...> { typedef T type; };
template<template <typename...> class C, std::size_t pos, typename... T> struct assemble_tuple_type_be { typedef typename append_to_tuple_type<typename assemble_tuple_type_be<C, pos - 1, T...>::type, typename make_function_pointer<C<T...>, typename vt_deref<pos - 1, T...>::type>::type>::type type; };
template<template <typename...> class C, typename... T> struct assemble_tuple_type_be<C, 1, T...> { typedef std::tuple<typename make_function_pointer<C<T...>, typename vt_deref<0, T...>::type>::type> type; };
template<template <typename...> class C, typename... T> struct assemble_tuple_type { typedef typename assemble_tuple_type_be<C, vt_count<T...>::val, T...>::type type; };
int main() { typedef Klasse<int, short, long, int> kt; typedef func_tuple_t<Klasse, int, short, long, int>::type tt;
auto x = func_tuple<Klasse, int, short, long, int>(); kt k;
std::cout << (k.*std::get<0>(x))() << std::endl << (k.*std::get<1>(x))() << std::endl << (k.*std::get<2>(x))() << std::endl << (k.*std::get<3>(x))() << std::endl;
std::cout << typeid(tt).name() << std::endl << typeid(std::tuple_element<0, tt>::type).name() << std::endl << typeid(std::tuple_element<1, tt>::type).name() << std::endl << typeid(std::tuple_element<2, tt>::type).name() << std::endl << typeid(std::tuple_element<3, tt>::type).name() << std::endl; }
|
Das mit den Fehlermeldungen hat sich somit auch geklärt, func_tuple_t ist ja jetzt eine Templateklassen und nicht mehr der Typ selbst. Dieser Post wurde am 13.03.2010 um 21:55 Uhr von Prog editiert. |