Simbody
3.7
|
Ensures that a data member of type T
is automatically reset to its default value upon copy construction or copy assignment. This allows the compiler-generated default copy methods to be used.
More...
Public Member Functions | |
ResetOnCopy () | |
Default constructor performs zero-initialization for built-in types; default initialization for class types. More... | |
ResetOnCopy (const T &value) | |
Construct or implicitly convert from an object of type T if there is a suitable copy constructor available. More... | |
ResetOnCopy (T &&value) | |
Construct or implicitly convert from an rvalue object of type T if thereis a suitable move constructor available, otherwise use the copy constructor if available, otherwise fails to compile. More... | |
ResetOnCopy (const ResetOnCopy &) | |
Copy constructor behaves identically to the default constructor; the supplied source argument is ignored. More... | |
ResetOnCopy (ResetOnCopy &&source) | |
Move constructor is simply a pass-through to the move constructor of the contained object so behaves normally. More... | |
ResetOnCopy & | operator= (const ResetOnCopy &ignored) |
Copy assignment reinitializes this object to its default-constructed condition; the source argument is ignored. More... | |
ResetOnCopy & | operator= (ResetOnCopy &&source) |
Move assignment is simply a pass-through to the move assignment of the contained object so behaves normally. More... | |
ResetOnCopy & | operator= (const T &value) |
Assignment from an object of type T uses T 's copy assignment operator if there is a suitable copy assignment operator available. More... | |
ResetOnCopy & | operator= (T &&value) |
Assignment from an rvalue object of type T uses T 's move assignment operator if available, otherwise uses copy assignment if available, otherwise fails to compile. More... | |
const T & | getT () const |
Return a const reference to the contained object of type T . More... | |
T & | updT () |
Return a writable reference to the contained object of type T . More... | |
Ensures that a data member of type T
is automatically reset to its default value upon copy construction or copy assignment. This allows the compiler-generated default copy methods to be used.
Here are some usage examples:
Other than copy behavior, an object of type ResetOnCopy<T>
behaves just like the underlying object of type T
. It will implicitly convert to T
when needed, and inherit constructors, assignment, and other methods from T
. Move construction and move assignment behave as they would for T
, and an assignment from an object of type T
to an object of type ResetOnCopy<T>
will invoke T
's ordinary copy assignment operator if there is one, and fail to compile if an attempt is made to use a non-existent assignment operator.
If T
is a C++ built-in "scalar" type (arithmetic, character, or pointer type) it will be reset to T(0)
or nullptr
when copy constructed or copy assigned. We don't allow T
to be an enumerated type here since resetting an enum to zero isn't always reasonable; use ReinitOnCopy<T>
instead and provide an initializing enumerator. For class types T
, copy construction and copy assignment will use the default constructor. ResetOnCopy<T>
adds CopyConstructible
and CopyAssignable
concepts to move-only classes like std::unique_ptr
, but those operations just reset the object to its default-constructed condition.
T | Template type that is a numeric, character, or pointer built-in type, or a class type that is DefaultConstructible and Destructible . Enum and array types are not allowed. |
|
inline |
Default constructor performs zero-initialization for built-in types; default initialization for class types.
|
inline |
Construct or implicitly convert from an object of type T
if there is a suitable copy constructor available.
|
inline |
Construct or implicitly convert from an rvalue object of type T
if thereis a suitable move constructor available, otherwise use the copy constructor if available, otherwise fails to compile.
|
inline |
Copy constructor behaves identically to the default constructor; the supplied source argument is ignored.
|
inline |
Move constructor is simply a pass-through to the move constructor of the contained object so behaves normally.
|
inline |
Copy assignment reinitializes this object to its default-constructed condition; the source argument is ignored.
|
inline |
Move assignment is simply a pass-through to the move assignment of the contained object so behaves normally.
|
inline |
Assignment from an object of type T
uses T
's copy assignment operator if there is a suitable copy assignment operator available.
|
inline |
Assignment from an rvalue object of type T
uses T
's move assignment operator if available, otherwise uses copy assignment if available, otherwise fails to compile.
|
inline |
Return a const reference to the contained object of type T
.
|
inline |
Return a writable reference to the contained object of type T
.