+ 2
Is template function now needed with features from c++ 14?
Hi All As we have now provision to have auto as input parameter and return type, we can have generic function as below: https://code.sololearn.com/ck23Bq5MTFkZ Do we still need template function? I guess we can handle each scenario with the auto keyword. Do we have some special requirement which cannot be fulfilled by auto and only template function is the way? Please share your view.
2 Respuestas
+ 2
Yes.In a situation where a function requires a variable number of arguments probably of varying types then we would have to use a template(a variadic template)
+ 2
Also a function like get<N>(tuple) that's used to retrieve elements of different types based on only the integer N can only be implemented using a template..If you tried using auto you will most likely get a compilation error like "inconsistent deduction for auto return type:..."