|
| | 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...
|
| |
template<class T>
class SimTK::ResetOnCopy< T >
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:
class Thing {
ResetOnCopy<int> m_defint;
ResetOnCopy<char> m_charZ = 'z';
ResetOnCopy<string> m_defstr;
ResetOnCopy<string> m_strHelloC = "hello";
ResetOnCopy<string> m_strGoodbyeS = "goodbye"s;
ResetOnCopy<short> m_shArr[3] = {9,8,7};
ResetOnCopy<SubsystemIndex> m_subIx{5};
ResetOnCopy<std::vector<string>> m_vstr {"one", "two", "three"};
ResetOnCopy<const int*> m_ptr;
ResetOnCopy<unique_ptr<Array_<int>>> m_up{new Array_<int>({1,2,3})};
};
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.
- Template Parameters
-
| 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. |
- See also
- ReinitOnCopy if you want to reset to a non-default value or use an enum.