I have a class with variadic type parameters. Inside that class I have a method that takes arguments of those types, makes a tuple of them and stores them in a vector. What I want is to use perfect forwarding to avoid unnecessary copies. I solved it by prefixing the method with another variadic template and I forward these new types instead of old ones, but I wonder if there is a better way.
Let me show you an example of my code:
template<typename ... Tlist>
class A{
public:
template<typename ... Xlist>
void method(Xlist && ... plist){
// some code
std::vector<std::tuple<Tlist...>> vec;
vec.push_back(std::make_tuple(std::forward<Xlist>(plist)...));
// some other code
}
};
This works with correct types and it doesn't compile with incorrect types anyway so I guess it's ok. But what I'd like is to somehow use the Tlist
types in method header, something like this:
template<typename ... Tlist>
class A{
public:
void method(Tlist && ... plist){
// some code
std::vector<std::tuple<Tlist...>> vec;
vec.push_back(std::make_tuple(std::forward<Tlist>(plist)...));
// some other code
}
};
But that only works with rvalues.
So is there a way to avoid using another template while still making perfect forwarding possible?
Aucun commentaire:
Enregistrer un commentaire