Function Templates vs. Auto Keyword

前端 未结 3 2066
抹茶落季
抹茶落季 2021-01-31 17:15

Can the auto keyword in C++11 replace function templates and specializations? If yes, what are the advantages of using template functions and specializations over

3条回答
  •  遥遥无期
    2021-01-31 17:38

    Can the auto keyword in C++11 replace function templates and specializations?

    No. There are proposals to use the keyword for this purpose, but it's not in C++11, and I think C++14 will only allow it for polymorphic lambdas, not function templates.

    If yes, What are the advantages of using template functions and specializations over simply typing a function parameter as auto.

    You might still want a named template parameter if you want to refer to the type; that would be more convenient than std::remove_reference::type or whatever.

提交回复
热议问题