(POD)结构上是否需要移动构造函数
Is move constructor necessary on (POD) structs?
在C++11标准的12.8/15段中定义:
非并集类X的隐式定义的复制/移动构造函数执行其基和成员的成员式复制/移动。[…]
这是否意味着:
struct st {
int a;
int b;
// ...
};
// ...
void do_smt(st tmp) {
st lala(std::move(tmp));
// ...
}
// ...
int main(int argc, char* argv[]) {
st test(1, 2);
do_smt(std::move(test));
}
没有move构造函数会工作吗?
是的,它将在不需要指定move构造函数的情况下工作;在您的示例中,编译器可能通过初始化lala而不是测试来优化move操作;请检查汇编程序的输出。
相关文章:
- 为什么不调用移动构造函数?(默认情况下只有构造器,没有别的)
- std::vector::p ush_back() 不会在 MSVC 上编译具有已删除移动构造函数的对象
- 仅包含可移动 std::map 的类的移动构造函数不起作用
- 为什么调用复制构造函数而不是移动构造函数?
- 基类中的默认析构函数禁用子类中的移动构造函数(如果有成员)
- 从具有按值捕获的 lambda 移动构造 std::函数时,移动构造函数调用两次
- 移动构造函数和右值引用
- 为什么 std::memmove 中联合的默认非平凡移动构造函数C++?
- 具有专用化的模板类中的可靠条件复制和移动构造函数
- C++:为什么不调用移动构造函数?
- 移动构造函数永远不会被调用
- C++:关于使用 Stroustrup 示例移动构造函数/赋值的问题
- 运算符+ 的规范实现涉及额外的移动构造函数
- C ++为什么在移动构造函数中需要移动/前进
- 为什么在删除"移动构造函数"时使用"复制构造函数"?
- 为什么这里不调用移动构造函数?
- 隐式移动构造函数
- 如何为具有私有成员的派生类实现移动构造函数
- 为什么不调用移动构造函数
- 是否可以避免在以下代码中复制/移动构造函数的需要?