c++ - Create a tuple from the results of a callable tuple -


i have tuple of callable types.

std::tuple<std::function<int(int)>, std::function<std::string(double)>> funcs; 

i want create tuple has type of result of each callable. example, funcs contains int->int , double->std::string

how can create results tuple depend on each element in funcs, .

std::tuple<int, std::string> results; 

#include <tuple> #include <functional> #include <string>   // takes arbitrary tuple of std::functions , creates //   tuple of return types of std::functions template<class t, class... types> struct tuplehandler;  // handles recursive inheritance base case when //   elements of tuple have been processed template<class... types>   struct tuplehandler<std::tuple<>, types...> {     using returntypetuple = std::tuple<types...>;   };  // strips off first std::function in tuple, determines //   return type , passes remaining parts on have next element //   processed template<class return, class... rest, class... tail, class... types> struct tuplehandler<std::tuple<std::function<return(rest...)>, tail...>, types...> : tuplehandler<std::tuple<tail...>, types..., return> {      using returntypetuple = typename tuplehandler<std::tuple<tail...>, types...,  return>::returntypetuple; };  int main() {     std::tuple<std::function<int(int)>, std::function<std::string(double)>> funcs;      // of course simple use case have used std::make_tuple, still demonstrates solution     tuplehandler<decltype(funcs)>::returntypetuple return_value_tuple(std::get<0>(funcs)(1), std::get<1>(funcs)(4.4));      // added per comment     auto x = [](auto funcs){ typename tuplehandler<decltype(funcs)>::returntypetuple results; };  } 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -