#include <movecopywrapper.h>
This wrapper helps to capture objects which require CopyFrom() in a lambda. The get method will return an error if copying the object into the wrapper failed. Of course move construction and assignment are supported too.
T | Type of object to wrapped. JobRef EnqueueSendJob(const BaseArray<Char>& jobdata)
{
return JobRef::Enqueue(
[this, copy = CopyWrapper<BaseArray<Char>>(jobdata)]() -> Result<void>
{
const BaseArray<Char>& array = copy.Get() iferr_return;
return _stream.Write(array.GetFirst(), array.GetCount());
},
_queue);
}
JobRef & Enqueue(JobQueueInterface *queue=JOBQUEUE_CURRENT) Definition: job.h:1342 |
Public Member Functions | |
CopyWrapper () | |
CopyWrapper (const T &src) | |
CopyWrapper (T &&src) | |
CopyWrapper (const CopyWrapper &src) | |
CopyWrapper (CopyWrapper &&src) | |
CopyWrapper & | operator= (const CopyWrapper &src) |
CopyWrapper & | operator= (CopyWrapper &&src) |
ResultRef< const T > | Get () const |
ResultRef< T > | Get () |
Private Attributes | |
T | _value |
T * | _ptr |
CopyWrapper | ( | ) |
|
explicit |
Copies the source object into the wrapper. Get() will return an error if the copy failed.
[in] | src | Object to be copied into the wrapper. |
|
explicit |
Moves the source object into the wrapper. Following Get()s will succeed because the move can't fail.
[in] | src | Object to be moved into the wrapper. |
CopyWrapper | ( | const CopyWrapper< T > & | src | ) |
Copies the source wrapper. Get() will return an error if the copy failed.
[in] | src | Wrapper to be copied. |
CopyWrapper | ( | CopyWrapper< T > && | src | ) |
Moves the source wrapper. Following Get()s will succeed because the move can't fail.
[in] | src | Wrapper to be moved. |
CopyWrapper& operator= | ( | const CopyWrapper< T > & | src | ) |
Copy assigns the source wrapper. Get() will return an error if the copy failed.
[in] | src | Wrapper to be copied. |
CopyWrapper& operator= | ( | CopyWrapper< T > && | src | ) |
Move assign the source wrapper. Following Get()s will succeed because the move can't fail.
[in] | src | Wrapper to be moved. |
ResultRef<const T> Get | ( | ) | const |
Returns a reference to the wrapped object if the assignment or construction of the wrapper was successful.
ResultRef<T> Get | ( | ) |
Returns a reference to the wrapped object if the assignment or construction of the wrapper was successful.
|
mutableprivate |
|
private |