| #include <tuple> | |
| #include <utility> | |
| #include <type_traits> | |
| #include <iostream> | |
| template<typename... T> class typelist {}; | |
| template<typename F, std::size_t I, typename... Tuples> | |
| using apply_result_type = decltype(std::declval<F>()(std::get<I>(std::declval<Tuples>())...)); | |
| template<typename F, std::size_t... Indices, typename... Tuples> | |
| typelist<apply_result_type<F, Indices, Tuples...>...> compute_result_types(typelist<F, Tuples...>, std::index_sequence<Indices...>); | |
| struct functor | |
| { | |
| int operator()(int a, int b) { return a + b; } | |
| double operator()(double a, double b) { return a + b; } | |
| void operator()(char, char) { return; } | |
| }; | |
| int main() | |
| { | |
| auto t1 = std::make_tuple(1, 2.0, 'a'); | |
| auto t2 = std::make_tuple(2, 4.0, 'b'); | |
| apply_result_type<functor, 0, decltype(t1), decltype(t2)> x; // works | |
| compute_result_types(typelist<functor, decltype(t1), decltype(t2)>{}, std::index_sequence<0, 1, 2>{}); // inference fails: | |
| // error C2893: Failed to specialize function template 'typelist<unknown-type...> compute_result_types(typelist<F,Tuples...>,std::integer_sequence<size_t,_Indexes2...>)' | |
| // seems like the non-type parameters don't get captured into size_t Indices... properly. | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment