Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <lazy_mutable_copy.h>
Public Member Functions | |
LazyMutableCopy (const T &obj) | |
LazyMutableCopy (T &&obj) | |
LazyMutableCopy (LazyMutableCopy &&)=default | |
LazyMutableCopy (const LazyMutableCopy &)=delete | |
class LazyMutableCopy< T > & | operator= (LazyMutableCopy< T > &&)=default |
class LazyMutableCopy< T > & | operator= (const LazyMutableCopy< T > &)=delete |
T * | get_mutable () |
This will copy the object if we don't already have ownership. | |
std::unique_ptr< T > | copy_or_move_as_unique_ptr () && |
bool | has_ownership () const |
const T * | get () const |
const T & | operator* () const |
const T * | operator-> () const |
void | dispose () && |
LazyMutableCopy<T> is a helper class for making an on-demand copy of an object of arbitrary type T. Type T must have a copy constructor.
Sample usage: const Proto& original_input = ...; LazyMutableCopy<Proto> input(original_input); if (input.get().foo() == BAD_VALUE) { input.get_mutable()->set_foo(GOOD_VALUE); ///< Copies the object. } ///< Process "input" here without worrying about BAD_VALUE. A good pattern is to have function taking LazyMutableCopy<> as argument: void ProcessProto(LazyMutableCopy<Proto> input) { ///< pass by copy ... } At the call site: ProcessProto(const_ref_to_my_proto);
In basic usage, a LazyMutableCopy is in one of two states:
Definition at line 44 of file lazy_mutable_copy.h.
|
inline |
You can construct a LazyMutableCopy with a const reference to an object, which must outlive this class (unless get_mutable() was called).
Definition at line 48 of file lazy_mutable_copy.h.
|
inline |
The other option is to construct a LazyMutableCopy with a std::move(T). In this case you transfer ownership and you can mutate it for free.
Definition at line 53 of file lazy_mutable_copy.h.
|
default |
You can move a LazyMutableCopy but not copy it, much like a std::unique_ptr<>.
|
delete |
|
inline |
Lazily make a copy if not already done and transfer ownership from this class to the returned std::unique_ptr<T>. Calling this function leaves the class in a state where the only valid operations is to assign it a new value.
We force a call via std::move(lazy_mutable_copy).copy_or_move_as_unique_ptr() to make it clearer that lazy_mutable_copy shouldn't really be used after this.
Definition at line 80 of file lazy_mutable_copy.h.
|
inline |
Destroys any owned value. Calling this function leaves the class in a state where the only valid operations is to assign it a new value.
We force a call via std::move(lazy_mutable_copy).dispose() to make it clearer that lazy_mutable_copy shouldn't really be used after this.
Definition at line 105 of file lazy_mutable_copy.h.
|
inline |
Standard smart pointer accessor, but only for const purpose. Undefined if the class contains no object.
Definition at line 96 of file lazy_mutable_copy.h.
|
inline |
This will copy the object if we don't already have ownership.
Definition at line 64 of file lazy_mutable_copy.h.
|
inline |
True iff get_mutable() was called at least once (in which case the object was copied) or if we constructed this via std::move().
Definition at line 92 of file lazy_mutable_copy.h.
|
inline |
Definition at line 97 of file lazy_mutable_copy.h.
|
inline |
Definition at line 98 of file lazy_mutable_copy.h.
|
delete |
|
default |