vso*_*tco 2 c++ exception c++11 nothrow
我试图指定一个函数是nothrow每当析构函数Foo不抛出时.我可以通过使用类型特征来做到这一点std::is_nothrow_destructible<>.我怎么能直接这样做?我已经尝试了以下内容,但如果我取消注释注释行,则无法编译
#include <iostream>
#include <type_traits>
class Foo
{
public:
~Foo() noexcept {}
};
// void f() noexcept(noexcept(~Foo{})) { } // error here
void g() noexcept(std::is_nothrow_destructible<Foo>::value)
{
}
int main()
{
g();
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误
error: no match for 'operator~' (operand type is 'Foo')
Run Code Online (Sandbox Code Playgroud)
错误说明符noexcept(noexcept(~Foo()))不正常,但对于我可以使用的构造函数noexcept(noexcept(Foo())).我在这里错过了一些明显的语法吗?
只能通过成员访问表达式调用析构函数.所以语法是:
void f() noexcept(noexcept(std::declval<Foo>().~Foo()))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
175 次 |
| 最近记录: |