SFINAE working in return type but not as template parameter

后端 未结 3 2058
情深已故
情深已故 2020-11-22 14:20

I already used the SFINAE idiom quite a few times and I got used to put my std::enable_if<> in template parameters rather than in return types. However, I

3条回答
  •  感动是毒
    2020-11-22 14:52

    You should take a look at 14.5.6.1 Function template overloading (C++11 standard) where function templates equivalency is defined. In short, default template arguments are not considered, so in the 1st case you have the same function template defined twice. In the 2nd case you have expression referring template parameters used in the return type (again see 14.5.6.1/4). Since this expression is part of signature you get two different function template declarations and thus SFINAE get a chance to work.

提交回复
热议问题