gpt4 book ai didi

c++ - 为什么 `is_­destructible` 使用 `declval().~U()` 而不是 `declval().~U()` 定义?

转载 作者:IT老高 更新时间:2023-10-28 22:05:33 29 4
gpt4 key购买 nike

根据 is_destructible 的定义( http://eel.is/c++draft/meta.unary.prop#lib:is_destructible ), is_­destructible_v<T>true什么时候:

Either T is a reference type, or T is a complete object type for which the expression declval<U&>().~U() is well-formed when treated as an unevaluated operand, where U is remove_­all_­extents_­t<T>.

为什么使用 declval<U&>().~U()而不是 declval<U>().~U() ?

declval 的措辞已添加到 https://cplusplus.github.io/LWG/issue2049解决定义与抽象类型有关的问题。也许作者在想declval<U>有返回类型 U所以它不适用于抽象类型?

最佳答案

所以我通过电子邮件询问了 Daniel Krügler,他允许我发表他的回答:

Good question - albeit the answer is rather trivial and doesn't reveal any language secret: I was aware that std::declval<T>() would return an rvalue reference (and thus an rvalue) in the discussed context, but in my mental imagination I wanted to express the picture of translating p->~T(), which again according to the language corresponds to (*p).~T() ([expr.ref]), so the logical consequence was to change the std::declval() call to generate an lvalue of T where the destructor was applied to.

I'm pretty sure that I didn't believe that declval() was returning the T directly, this helper function was too deeply burned into my mind ;-)

关于c++ - 为什么 `is_­destructible` 使用 `declval<U&>().~U()` 而不是 `declval<U>().~U()` 定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54699526/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com