Topic: Trivial copy/move operations


Author: =3D?ISO-8859-1?Q?Daniel_Kr=3DFCgler?=3D <daniel.kruegler@googlemail.c=.om>
Date: Thu, 8 Apr 2010 00:23:32 CST
Raw View
On 1 Apr., 02:00, Scott Meyers <NeverR...@aristeia.com> wrote:
> N3053 (about implicitly-generated move functions) says "Unions have
implicit
> deleted moves if a members has a non-trivial moves.  This rule is the sam=
e
> as for copy, and means that a user-defined union copy will not shadow a
> move."
>
> Can somebody please summarize for me what it means for a move or copy
> operation to be trivial?

I'm not sure that I understand this question properly. Are you asking
for the conditions/criteria that must be satisfied for a move or copy
function to be considered as trivial or are you asking for a summary
of all special rules that require such a trivial operation?

Without any guidance I reply to the first question:

1) For a trivial copy/move constructor ([class.copy]/13) or assignment
operator (/27) the requirements are that the c'tor is not user-
provided
nor deleted, that no virtual functions nor virtual base classes
exists, and
that all non-static data member and base class operation that will be
used for this copy/move are also trivial. It is note-worthy to
mention,
what a user-provided special member function is (I assume that the
term "deleted function" is sufficiently clear): It means that the
function
is user-declared and not explicitly defaulted on its first
declaration, e.g.

struct S {
 S(const S&) = default; // not user-provided
 S(S&) = delete; // explicitly deleted, therefore user-provided
};

It is also note-worthy to mention that a special member
function may be deleted without any explicit user-declaration.
For example the core language requires that the copy/move
assignment operator is deleted, if the class type has a
non-static data member of reference type.

2) Finally the standard distinguishes a "trivially copyable" type.
This is more than a type with trivial copy and trivial move
operations (and a trivial destructor as well), specifically there
must be *no* non-trivial copy and move operations, e.g. the type

struct Funny {
 Funny(const Funny&) = default;
 Funny(Funny&) = delete;
};

is *not* trivially copyable, because the second copy constructor
is not trivial.

HTH & Greetings from Bremen,

Daniel Kr=FCgler


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Scott Meyers <NeverRead@aristeia.com>
Date: Wed, 31 Mar 2010 18:00:23 CST
Raw View
N3053 (about implicitly-generated move functions) says "Unions have implicit
deleted moves if a members has a non-trivial moves.  This rule is the same
as for copy, and means that a user-defined union copy will not shadow a
move."

Can somebody please summarize for me what it means for a move or copy
operation to be trivial?

Thanks,

Scott

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]