stlab-copy-on-write 1.0.6
Copy-on-write wrapper for any type
Loading...
Searching...
No Matches

Functions

auto stlab::copy_on_write< T >::write () -> element_type &
 Obtains a non-const reference to the underlying value.
template<class Transform, class Inplace>
auto stlab::copy_on_write< T >::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 stlab::copy_on_write< T >::read () const noexcept -> const element_type &
 Returns a const reference to the underlying value for read-only access.
 stlab::copy_on_write< T >::operator const element_type & () const noexcept
 Implicit conversion to const reference of the underlying value.
auto stlab::copy_on_write< T >::operator* () const noexcept -> const element_type &
 Dereference operator that returns a const reference to the underlying value.
auto stlab::copy_on_write< T >::operator-> () const noexcept -> const element_type *
 Arrow operator that returns a const pointer to the underlying value.
auto stlab::copy_on_write< T >::unique () const noexcept -> bool
 Returns true if this is the only reference to the underlying object.
auto stlab::copy_on_write< T >::unique_instance () const noexcept -> bool
auto stlab::copy_on_write< T >::identity (const copy_on_write &x) const noexcept -> bool
 Returns true if this object and the given object share the same underlying data.

Detailed Description

Function Documentation

◆ unique()

template<typename T>
auto stlab::copy_on_write< T >::unique ( ) const -> bool
inlinenodiscardnoexcept

Returns true if this is the only reference to the underlying object.

This is useful to determine if calling write() will cause a copy.

◆ unique_instance()

template<typename T>
auto stlab::copy_on_write< T >::unique_instance ( ) const -> bool
inlinenodiscardnoexcept
Deprecated
Use unique() instead. Returns true if this is the only reference to the underlying object.

◆ write() [1/2]

template<typename T>
auto stlab::copy_on_write< T >::write ( ) -> element_type&
inline

Obtains a non-const reference to the underlying value.

This will copy the underlying value if necessary so changes to the value do not affect other copy_on_write objects sharing the same data.

Examples
basic_usage_test.cpp.

◆ write() [2/2]

template<typename T>
template<class Transform, class Inplace>
auto stlab::copy_on_write< T >::write ( Transform transform,
Inplace inplace ) -> element_type&
inline

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.

Parameters
transformA function object that takes a const reference to the underlying value and returns a new value.
inplaceA function object that takes a reference to the underlying value and modifies it in place.
Returns
A reference to the underlying value.