stlab-copy-on-write 1.0.6
Copy-on-write wrapper for any type
|
#include <copy_on_write.hpp>
Public Types | |
using | value_type |
using | element_type |
The type of value stored. |
Public Member Functions | |
copy_on_write () noexcept(std::is_nothrow_constructible_v< T >) | |
Default constructs the wrapped value. | |
template<class U> | |
copy_on_write (U &&x, disable_copy< U >=nullptr) | |
Constructs a new instance by forwarding arguments to the wrapped value constructor. | |
template<class U, class V, class... Args> | |
copy_on_write (U &&x, V &&y, Args &&... args) | |
Constructs a new instance by forwarding multiple arguments to the wrapped value constructor. | |
copy_on_write (const copy_on_write &x) noexcept | |
Copy constructor that shares the underlying data with the source object. | |
copy_on_write (copy_on_write &&x) noexcept | |
Move constructor that takes ownership of the source object's data. | |
~copy_on_write () | |
Destructor. | |
auto | operator= (const copy_on_write &x) noexcept -> copy_on_write & |
Copy assignment operator that shares the underlying data with the source object. | |
auto | operator= (copy_on_write &&x) noexcept -> copy_on_write & |
Move assignment operator that takes ownership of the source object's data. | |
template<class U> | |
auto | operator= (U &&x) -> disable_copy_assign< U > |
Assigns a new value to the wrapped object, optimizing for in-place assignment when unique. | |
auto | write () -> element_type & |
Obtains a non-const reference to the underlying value. | |
template<class Transform, class Inplace> | |
auto | write (Transform transform, Inplace inplace) -> element_type & |
If the object is not unique, the transform is applied to the underlying value to copy it and a reference to the new value is returned. If the object is unique, the inplace function is called with a reference to the underlying value and a reference to the value is returned. | |
auto | read () const noexcept -> const element_type & |
Returns a const reference to the underlying value for read-only access. | |
operator const element_type & () const noexcept | |
Implicit conversion to const reference of the underlying value. | |
auto | operator* () const noexcept -> const element_type & |
Dereference operator that returns a const reference to the underlying value. | |
auto | operator-> () const noexcept -> const element_type * |
Arrow operator that returns a const pointer to the underlying value. | |
auto | unique () const noexcept -> bool |
Returns true if this is the only reference to the underlying object. | |
auto | unique_instance () const noexcept -> bool |
auto | identity (const copy_on_write &x) const noexcept -> bool |
Returns true if this object and the given object share the same underlying data. |
Friends | |
void | swap (copy_on_write &x, copy_on_write &y) noexcept |
Efficiently swaps the contents of two copy_on_write objects. | |
auto | operator< (const copy_on_write &x, const copy_on_write &y) noexcept -> bool |
Comparisons can be done with the underlying value or the copy_on_write object. | |
auto | operator< (const copy_on_write &x, const element_type &y) noexcept -> bool |
Comparisons can be done with the underlying value or the copy_on_write object. | |
auto | operator< (const element_type &x, const copy_on_write &y) noexcept -> bool |
Comparisons can be done with the underlying value or the copy_on_write object. | |
auto | operator> (const copy_on_write &x, const copy_on_write &y) noexcept -> bool |
Comparisons can be done with the underlying value or the copy_on_write object. | |
auto | operator> (const copy_on_write &x, const element_type &y) noexcept -> bool |
Comparisons can be done with the underlying value or the copy_on_write object. | |
auto | operator> (const element_type &x, const copy_on_write &y) noexcept -> bool |
Comparisons can be done with the underlying value or the copy_on_write object. | |
auto | operator<= (const copy_on_write &x, const copy_on_write &y) noexcept -> bool |
Comparisons can be done with the underlying value or the copy_on_write object. | |
auto | operator<= (const copy_on_write &x, const element_type &y) noexcept -> bool |
Comparisons can be done with the underlying value or the copy_on_write object. | |
auto | operator<= (const element_type &x, const copy_on_write &y) noexcept -> bool |
Comparisons can be done with the underlying value or the copy_on_write object. | |
auto | operator>= (const copy_on_write &x, const copy_on_write &y) noexcept -> bool |
Comparisons can be done with the underlying value or the copy_on_write object. | |
auto | operator>= (const copy_on_write &x, const element_type &y) noexcept -> bool |
Comparisons can be done with the underlying value or the copy_on_write object. | |
auto | operator>= (const element_type &x, const copy_on_write &y) noexcept -> bool |
Comparisons can be done with the underlying value or the copy_on_write object. | |
auto | operator== (const copy_on_write &x, const copy_on_write &y) noexcept -> bool |
Comparisons can be done with the underlying value or the copy_on_write object. | |
auto | operator== (const copy_on_write &x, const element_type &y) noexcept -> bool |
Comparisons can be done with the underlying value or the copy_on_write object. | |
auto | operator== (const element_type &x, const copy_on_write &y) noexcept -> bool |
Comparisons can be done with the underlying value or the copy_on_write object. | |
auto | operator!= (const copy_on_write &x, const copy_on_write &y) noexcept -> bool |
Comparisons can be done with the underlying value or the copy_on_write object. | |
auto | operator!= (const copy_on_write &x, const element_type &y) noexcept -> bool |
Comparisons can be done with the underlying value or the copy_on_write object. | |
auto | operator!= (const element_type &x, const copy_on_write &y) noexcept -> bool |
Comparisons can be done with the underlying value or the copy_on_write object. |
A copy-on-write wrapper for any type that models Regular.
Copy-on-write semantics allow for an object to be lazily copied - only creating a copy when the value is modified and there is more than one reference to the value.
This class is thread safe and supports types that model Moveable.