Privacy policyContactsAbout siteOpinionsGitHubDonate
© EVILEG 2015-2018
Recommend hosting
TIMEWEB

Александр Панюшкин

eska2000

  • 1
  • 0
Feb. 26, 2019, 10:22 a.m.

C++

SFINAE, C++17, template

There was a problem: "write the second implementation of the template function", in which the same arguments are passed. That is, the signature of both functions completely coincides. The difference is that, as an argument, the std::vector containers and the std::map containers can be passed to the function. And depending on whether std::vector is or std::map, this or that implementation should be selected.

In this case, the SFINAE rule will be used, which states: If the final types of arguments cannot be calculated (to perform substitution of template parameters) of an overloaded template function, the compiler does not throw an error, but searches for another suitable overload. The error will be in three cases:

  • No suitable overload was found.
  • Several such overloads were found, and C ++ cannot decide which one to take.
  • The overload was found, it turned out to be a template, and an error occurred when instantiating the template.

Our case will be the second. There are two overload template functions.

Join us in social networks

For registered users on the site there is a minimum amount of advertising