c++ - Creating this function template -


i have simple class template tuples of vectors:

template <typename... t> struct tupleofvectors {   std::tuple<std::vector<t>...> tuple; }; 

i can use this:

tupleofvectors<double, std::string> tuple;  auto vec0 = std::get<0>(tuple.tuple); vec0.push_back(1.2);  auto vec1 = std::get<1>(tuple.tuple); vec1.push_back("foo"); 

i want encapsulate class template itself. how i'd use class template:

tuple.vec<0>.push_back(1.2); tuple.vec<1>.push_back("foo"); 

how develop such vec() template member function?

template <typename... ts> struct tupleofvectors {     std::tuple<std::vector<ts>...> tuple;      template< size_t n >     auto vec() -> decltype( std::get<n>(tuple) ) {         return std::get<n>(tuple);     }  };  tupleofvectors<int, short, double, float> t;  t.vec<3>().push_back( 3.14f ); 

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

How to call a javascript function after the page loads with a chrome extension? -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -