显式移动ctor是否消除隐式复制ctor

显式移动ctor是否消除隐式复制ctor

本文介绍了显式移动ctor是否消除隐式复制ctor?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在已接受的答案中阅读 :

我注意到(g ++ 4.7.2),如果你定义一个移动构造函数,与 push_back()一起使用,如果你所做的一切都是 = delete 复制构造函数,得到一个隐式移动构造函数 - 你得到一个错误。 [...如果你没有明确地做任何事情,这让我想知道是哪个(移动或复制)实际使用...]



但是,不同



因此,我的问题是,第一个引号是保证的,而不是在定义一个移动构造函数时隐式定义的。标准(包括)?对于一些需要显式析构函数的类,我宁愿用一个move构造函数和一个(删除)移动操作符来完成规则五,并且依赖于定义的隐式复制方法 。如果我不能依赖,那么我必须明确地 = delete 他们 - 但这是很多潜在的冗余的东西。

$ b $所以我的问题是,标准保证的第一个报价(包括


是的,您的第一个报价是由标准保证的。



标准报价(草案n3690):


I read in the accepted answer here that:

I do notice (g++ 4.7.2) that if you define a move constructor, it will be used with, e.g., push_back(), whereas if all you do is = delete the copy constructor, you don't get an implicit move constructor -- you get an error. [...which leads me to wonder which one (move or copy) is actually used if you don't do anything explicitly...]

However, this online reference does not make the same explicit promises about the copy constructor not being implicitly defined when you define a move constructor.

So my question is, is the first quote guaranteed by the standard (including the "or")? I would prefer, with some classes which need an explicit destructor, to complete the "rule of five" with just a move constructor and a (deleted) move operator and rely on the implicit copy methods not being defined. If I can't rely on that, then I'll have to explicitly =delete them -- but that's a lot of potentially redundant stuff.

解决方案

Yes, your first quote is guaranted by the standard.

Quote from the standard (draft n3690):

这篇关于显式移动ctor是否消除隐式复制ctor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 12:53