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
Post a Comment