如果函数模板返回 decltype(auto)
(或另一个使用 auto
的类型说明符)但返回语句格式不正确,SFINAE 会导致结果吗? return
语句是否被认为是函数签名的直接上下文?
N3690 草案中似乎没有任何要求。默认情况下,我猜 SFINAE 不适用。
这似乎很不幸,因为您可以编写一个函数来转发到另一个函数,但是您不能像以手写方式编写时那样使其存在以委托(delegate)为条件。此外,如果没有 decltype(auto)
,则无法检查对等非静态成员函数的存在,因为 this
不能在函数签名中使用。然而,这表明存在一个基本问题,因为 decltype(auto)
提供了一条路径,可以在成员签名中将类类型视为完整,而事实并非如此。
有没有写过提案,或者有没有在任何地方正式分析过问题?
在成员签名中将类类型视为完整的能力可能具有其他含义……但这只是另一个问题的素材。
最佳答案
but the return statement would be ill-formed, does SFINAE result?
SFINAE
Since the return type is deduced by instantiating the template, if the instantiation is ill-formed, this causes an error rather than a substitution failure. This allows an auto function to return a lambda, which is not possible using the decltype(returned expression) pattern.
希望这就是您想要的。
关于c++ - SFINAE 和 decltype(自动),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17608637/