SFINAE和decltype(auto) [英] SFINAE and decltype(auto)

查看:198
本文介绍了SFINAE和decltype(auto)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果函数模板返回 decltype(auto)(或使用 auto 的另一个类型说明符)会不会形成,SFINAE结果吗?是 return 语句被认为是函数签名的直接上下文吗?

If a function template returns decltype(auto) (or another type specifier using auto) but the return statement would be ill-formed, does SFINAE result? Is the return statement considered to be the immediate context of the function signature?

N3690草案中没有什么似乎需要这个。默认情况下,我猜SFINAE不适用。

Nothing in the N3690 draft seems to require this. By default, I guess SFINAE does not apply.

这似乎不幸,因为你可以写一个函数转发到另一个函数,但你不能让它的存在条件的代理当写长文时。此外,无法使用 decltype(auto)检查对等非静态成员函数的存在,因为不能使用 this 在函数签名中。然而,这表明一个根本问题,因为 decltype(auto)提供了一个路径来考虑类类型在成员签名中是完整的,而不是成员签名。

This seems unfortunate because you can write a function to forward to another function, but you cannot make its existence conditional on the delegate as when writing longhand. Furthermore, checking the existence of a peer nonstatic member function cannot be done without decltype(auto) because this cannot be used in a function signature. However this indicates a fundamental problem, as decltype(auto) provides a path to considering the class type as complete within a member signature, where it's not.

是否已写入提案,或者已在任何地方正式分析问题?

Has a proposal been written, or has the problem been formally analyzed anywhere?

能够将类类型视为完整的成员签名可能有其他影响...但是这只是另一个问题的饲料。

The ability to treat the class type as complete within a member signature may have other implications… but that's just fodder for another question.

推荐答案


语句将是不成形的,SFINAE是否结果?

but the return statement would be ill-formed, does SFINAE result?

proposal-n3638 说,


SFINAE

由于通过实例化模板来推导返回类型,如果实例化不成功,则会导致错误,而不是替换失败。这允许一个自动函数返回一个lambda,这是不可能使用decltype(返回的表达式)模式。

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.

希望这是什么您正在寻找。

Hope that is what you're looking for.

这篇关于SFINAE和decltype(auto)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆