mardi 30 mai 2017

C++ type deduction in variadic templates

I started experimenting with variadic templates in C++11 and now I have a following method:

template <typename... TPath>
void Bind(PropertyPath<TPath...> propertyPath);

and currently I have to call this this way:

myItem.Value.Bind<Item *, string, int>(PropertyPath<Item *, string, int>(...));

where PropertyPath is a variadic template class with any number of parameters (and the three dots are whatever arguments I put in the constructor)

The compiler doesn't seem to be able to infer the template types for Bind based on what PropertyPath I pass in. Is there no way to make this work without specifying the parameters twice? This is what I would like to be able to do:

myItem.Value.Bind(PropertyPath<Item *, string, int>(...));

Aucun commentaire:

Enregistrer un commentaire