c++ - 我什么时候应该声明一个没有 noexcept 的移动构造函数?

标签 c++ c++11 rvalue-reference

标准不对移动构造函数强制执行 noexcept。在什么情况下可以/必须抛出移动构造函数?

最佳答案

当你真的别无选择时。大多数时候你的移动构造函数应该是noexcept。它们是默认设置。

看这个:http://www.codingstandard.com/rule/12-5-4-declare-noexcept-the-move-constructor-and-move-assignment-operator/

It is especially important to use noexcept for types that are intended to be used with the standard library containers. If the move constructor for an element type in a container is not noexcept then the container will use the copy constructor rather than the move constructor.

关于c++ - 我什么时候应该声明一个没有 noexcept 的移动构造函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26922113/

相关文章:

c++ - 不能在 cmake_pch.h 中包含标准库

c++ - 如何使用顶点缓冲区对象

c++ - 使用 std::forward 的主要目的是什么以及它解决了哪些问题?

c++ - 如何从 C++ 正确实例化 QQuickItem 派生对象?

gcc - 在 Debian 上安装 gcc 4.8

c++ - 在 C++11 中,将引用/指针返回到 std::string 中某个位置的最高效方法是什么?

c++ - C++11 的三规则变成五规则?

c++ - std::thread 和右值引用

c++ - 右值引用被视为左值?

c++ - 将 std::vector 转换为 CComSafeArray 的任何快速方法