Is the default Move constructor defined as noexcept?(默认的 Move 构造函数是否定义为 noexcept?)
问题描述
在重新分配时决定是移动还是复制元素之前,向量似乎会检查移动构造函数是否标记为 noexcept .默认移动构造函数是否定义为 noexcept?我看到了以下文档,但没有说明这一点.http://en.cppreference.com/w/cpp/language/move_constructor
It seems that a vector will check if the move constructor is labeled as noexcept before deciding on whether to move or copy elements when reallocating. Is the default move constructor defined as noexcept? I saw the following documentation but it didn't specify this.http://en.cppreference.com/w/cpp/language/move_constructor
隐式声明的移动构造函数
Implicitly-declared move constructor
如果没有用户定义的移动为类类型(结构、类或联合)提供构造函数,并且以下所有情况都为真:没有用户声明的副本构造函数没有用户声明的复制赋值运算符没有用户声明的移动赋值运算符用户声明的析构函数隐式声明的移动构造函数是由于下一节中详述的条件,未定义为已删除然后编译器会将移动构造函数声明为内联公共具有签名 T::T(T&&) 的类的成员多个移动构造函数,例如T::T(const T&&) 和 T::T(T&&).如果存在一些用户定义的移动构造函数,用户可能仍然强制生成隐式声明的移动构造函数关键字默认.
If no user-defined move constructors are provided for a class type (struct, class, or union), and all of the following is true: there are no user-declared copy constructors there are no user-declared copy assignment operators there are no user-declared move assignment operators there are no user-declared destructors the implicitly-declared move constructor is not defined as deleted due to conditions detailed in the next section then the compiler will declare a move constructor as an inline public member of its class with the signature T::T(T&&) A class can have multiple move constructors, e.g. both T::T(const T&&) and T::T(T&&). If some user-defined move constructors are present, the user may still force the generation of the implicitly declared move constructor with the keyword default.
推荐答案
我认为答案是 15.4/14(异常规范):
I think the answer is 15.4/14 (Exception specifications):
继承构造函数 (12.9) 和隐式声明的特殊成员函数(第 12 条)具有异常规范.如果 f
是继承构造函数或隐式声明的默认构造函数、复制构造函数、移动构造函数、析构函数、复制赋值运算符或移动赋值运算符,则其隐式异常-specification 指定 type-id T
当且仅当 T
被 exception-specification 允许f
的隐式定义直接调用的函数;f
允许所有异常,如果它直接调用的任何函数允许所有异常,并且 f
具有 exception-specification noexcept(true)
如果它直接调用的每个函数都不允许例外.
An inheriting constructor (12.9) and an implicitly declared special member function (Clause 12) have an exception-specification. If
f
is an inheriting constructor or an implicitly declared default constructor, copy constructor, move constructor, destructor, copy assignment operator, or move assignment operator, its implicit exception-specification specifies the type-idT
if and only ifT
is allowed by the exception-specification of a function directly invoked byf
’s implicit definition;f
allows all exceptions if any function it directly invokes allows all exceptions, andf
has the exception-specificationnoexcept(true)
if every function it directly invokes allows no exceptions.
基本上,它按你的想法行事,并且隐式声明的移动构造函数是 noexcept
.
Basically, it Does What You Think, and the implicitly-declared move constructor is noexcept
whenever it can be.
这篇关于默认的 Move 构造函数是否定义为 noexcept?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:默认的 Move 构造函数是否定义为 noexcept?
基础教程推荐
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01