struct Type
{
Type(Type&&) noexcept {}
~Type() noexcept(false) {}
};
static_assert(std::is_nothrow_move_constructible<Type>::value, "Type should be nothrow-move-constructible");
static_assert(std::is_nothrow_constructible<Type, Type&&>::value, "Type should be nothrow-constructible from Type&&");
这是否符合C++标准?
std::is_nothrow_move_constructible
是否需要一个noexcept析构函数?为什么?如果我这样使用:
Type a;
Type b(std::move(a));
a
的析构函数在第二个语句中不会被调用。
std::is_nothrow_move_constructible
->std::is_nothrow_constructible
这条链,你会看到这里的注释:_"在许多实现中,is_nothrow_constructible 还会检查析构函数是否抛出异常..."_,链接为 http://en.cppreference.com/w/cpp/types/is_constructible。 - Richard Critten