[C++] Support C++ object copies and moves (#5988)
authorJean-François Roy <jf@devklog.net>
Sat, 29 Jan 2022 22:24:24 +0000 (14:24 -0800)
committerGitHub <noreply@github.com>
Sat, 29 Jan 2022 22:24:24 +0000 (14:24 -0800)
commit43203984f7e7095435e849ad09c363b16325aa2b
treeb2bb4b42f80dbb2d0ea073714c4972604fd4fa0f
parent5993338ee378836f47ca31ee0a57a58e287d3a65
[C++] Support C++ object copies and moves (#5988)

Augment the C++ generator to emit a C++ copy constructor and a by-value
copy assignment operator. This is enabled by default when the C++
standard is C++11 or later. These additional functions are only emitted
for objects that need it, typically tables containing other tables.

These new functions are declared in the object table type and are
defined as inline functions after table declarations.

When these new functions are declared, a user-defined
explicitly-defaulted default constructor and move constructor are also
emitted.

The copy assignment operator uses the copy-and-swap idiom to provide
strong exception safety, at the expense of keeping 2 full table copies
in memory temporarily.

fixes #5783
samples/monster_generated.h
src/idl_gen_cpp.cpp
tests/arrays_test_generated.h
tests/cpp17/generated_cpp17/monster_test_generated.h
tests/monster_test_generated.h
tests/namespace_test/namespace_test2_generated.h
tests/test.cpp