stlab-copy-on-write 1.0.4
Copy-on-write wrapper for any type
Loading...
Searching...
No Matches
stlab::copy_on_write< T > Class Template Reference

#include <copy_on_write.hpp>

Public Types

using value_type = T
using element_type = T

Public Member Functions

 copy_on_write () noexcept(std::is_nothrow_constructible_v< T >)
template<class U>
 copy_on_write (U &&x, disable_copy< U >=nullptr)
template<class U, class V, class... Args>
 copy_on_write (U &&x, V &&y, Args &&... args)
 copy_on_write (const copy_on_write &x) noexcept
 copy_on_write (copy_on_write &&x) noexcept
auto operator= (const copy_on_write &x) noexcept -> copy_on_write &
auto operator= (copy_on_write &&x) noexcept -> copy_on_write &
template<class U>
auto operator= (U &&x) -> disable_copy_assign< U >
auto write () -> element_type &
template<class Transform, class Inplace>
auto write (Transform transform, Inplace inplace) -> element_type &
auto read () const noexcept -> const element_type &
 operator const element_type & () const noexcept
auto operator* () const noexcept -> const element_type &
auto operator-> () const noexcept -> const element_type *
auto unique () const noexcept -> bool
auto unique_instance () const noexcept -> bool
auto identity (const copy_on_write &x) const noexcept -> bool

Friends

void swap (copy_on_write &x, copy_on_write &y) noexcept
auto operator< (const copy_on_write &x, const copy_on_write &y) noexcept -> bool
auto operator< (const copy_on_write &x, const element_type &y) noexcept -> bool
auto operator< (const element_type &x, const copy_on_write &y) noexcept -> bool
auto operator> (const copy_on_write &x, const copy_on_write &y) noexcept -> bool
auto operator> (const copy_on_write &x, const element_type &y) noexcept -> bool
auto operator> (const element_type &x, const copy_on_write &y) noexcept -> bool
auto operator<= (const copy_on_write &x, const copy_on_write &y) noexcept -> bool
auto operator<= (const copy_on_write &x, const element_type &y) noexcept -> bool
auto operator<= (const element_type &x, const copy_on_write &y) noexcept -> bool
auto operator>= (const copy_on_write &x, const copy_on_write &y) noexcept -> bool
auto operator>= (const copy_on_write &x, const element_type &y) noexcept -> bool
auto operator>= (const element_type &x, const copy_on_write &y) noexcept -> bool
auto operator== (const copy_on_write &x, const copy_on_write &y) noexcept -> bool
auto operator== (const copy_on_write &x, const element_type &y) noexcept -> bool
auto operator== (const element_type &x, const copy_on_write &y) noexcept -> bool
auto operator!= (const copy_on_write &x, const copy_on_write &y) noexcept -> bool
auto operator!= (const copy_on_write &x, const element_type &y) noexcept -> bool
auto operator!= (const element_type &x, const copy_on_write &y) noexcept -> bool

Detailed Description

template<typename T>
class stlab::copy_on_write< T >

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.

Examples
basic_usage_test.cpp.

Member Typedef Documentation

◆ element_type

template<typename T>
using stlab::copy_on_write< T >::element_type = T

The type of value stored.

◆ value_type

template<typename T>
using stlab::copy_on_write< T >::value_type = T
Deprecated
Use element_type instead. The type of value stored.

Constructor & Destructor Documentation

◆ copy_on_write() [1/5]

template<typename T>
stlab::copy_on_write< T >::copy_on_write ( )
inlinenoexcept

Default constructs the wrapped value.

◆ copy_on_write() [2/5]

template<typename T>
template<class U>
stlab::copy_on_write< T >::copy_on_write ( U && x,
disable_copy< U > = nullptr )
inline

Constructs a new instance by forwarding arguments to the wrapped value constructor.

◆ copy_on_write() [3/5]

template<typename T>
template<class U, class V, class... Args>
stlab::copy_on_write< T >::copy_on_write ( U && x,
V && y,
Args &&... args )
inline

Constructs a new instance by forwarding multiple arguments to the wrapped value constructor.

◆ copy_on_write() [4/5]

template<typename T>
stlab::copy_on_write< T >::copy_on_write ( const copy_on_write< T > & x)
inlinenoexcept

Copy constructor that shares the underlying data with the source object.

◆ copy_on_write() [5/5]

template<typename T>
stlab::copy_on_write< T >::copy_on_write ( copy_on_write< T > && x)
inlinenoexcept

Move constructor that takes ownership of the source object's data.

Member Function Documentation

◆ identity()

template<typename T>
auto stlab::copy_on_write< T >::identity ( const copy_on_write< T > & x) const -> bool
inlinenodiscardnoexcept

Returns true if this object and the given object share the same underlying data.

Examples
basic_usage_test.cpp.

◆ operator const element_type &()

template<typename T>
stlab::copy_on_write< T >::operator const element_type & ( ) const
inlinenoexcept

Implicit conversion to const reference of the underlying value.

◆ operator*()

template<typename T>
auto stlab::copy_on_write< T >::operator* ( ) const -> const element_type&
inlinenoexcept

Dereference operator that returns a const reference to the underlying value.

◆ operator->()

template<typename T>
auto stlab::copy_on_write< T >::operator-> ( ) const -> const element_type*
inlinenoexcept

Arrow operator that returns a const pointer to the underlying value.

◆ operator=() [1/3]

template<typename T>
auto stlab::copy_on_write< T >::operator= ( const copy_on_write< T > & x) -> copy_on_write&
inlinenoexcept

Copy assignment operator that shares the underlying data with the source object.

◆ operator=() [2/3]

template<typename T>
auto stlab::copy_on_write< T >::operator= ( copy_on_write< T > && x) -> copy_on_write&
inlinenoexcept

Move assignment operator that takes ownership of the source object's data.

◆ operator=() [3/3]

template<typename T>
template<class U>
auto stlab::copy_on_write< T >::operator= ( U && x) -> disable_copy_assign<U>
inline

Assigns a new value to the wrapped object, optimizing for in-place assignment when unique.

◆ read()

template<typename T>
auto stlab::copy_on_write< T >::read ( ) const -> const element_type&
inlinenodiscardnoexcept

Returns a const reference to the underlying value for read-only access.

Examples
basic_usage_test.cpp.

◆ 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.

◆ operator!= [1/3]

template<typename T>
auto operator!= ( const copy_on_write< T > & x,
const copy_on_write< T > & y ) -> bool
friend

Comparisons can be done with the underlying value or the copy_on_write object.

◆ operator!= [2/3]

template<typename T>
auto operator!= ( const copy_on_write< T > & x,
const element_type & y ) -> bool
friend

Comparisons can be done with the underlying value or the copy_on_write object.

◆ operator!= [3/3]

template<typename T>
auto operator!= ( const element_type & x,
const copy_on_write< T > & y ) -> bool
friend

Comparisons can be done with the underlying value or the copy_on_write object.

◆ operator< [1/3]

template<typename T>
auto operator< ( const copy_on_write< T > & x,
const copy_on_write< T > & y ) -> bool
friend

Comparisons can be done with the underlying value or the copy_on_write object.

◆ operator< [2/3]

template<typename T>
auto operator< ( const copy_on_write< T > & x,
const element_type & y ) -> bool
friend

Comparisons can be done with the underlying value or the copy_on_write object.

◆ operator< [3/3]

template<typename T>
auto operator< ( const element_type & x,
const copy_on_write< T > & y ) -> bool
friend

Comparisons can be done with the underlying value or the copy_on_write object.

◆ operator<= [1/3]

template<typename T>
auto operator<= ( const copy_on_write< T > & x,
const copy_on_write< T > & y ) -> bool
friend

Comparisons can be done with the underlying value or the copy_on_write object.

◆ operator<= [2/3]

template<typename T>
auto operator<= ( const copy_on_write< T > & x,
const element_type & y ) -> bool
friend

Comparisons can be done with the underlying value or the copy_on_write object.

◆ operator<= [3/3]

template<typename T>
auto operator<= ( const element_type & x,
const copy_on_write< T > & y ) -> bool
friend

Comparisons can be done with the underlying value or the copy_on_write object.

◆ operator== [1/3]

template<typename T>
auto operator== ( const copy_on_write< T > & x,
const copy_on_write< T > & y ) -> bool
friend

Comparisons can be done with the underlying value or the copy_on_write object.

◆ operator== [2/3]

template<typename T>
auto operator== ( const copy_on_write< T > & x,
const element_type & y ) -> bool
friend

Comparisons can be done with the underlying value or the copy_on_write object.

◆ operator== [3/3]

template<typename T>
auto operator== ( const element_type & x,
const copy_on_write< T > & y ) -> bool
friend

Comparisons can be done with the underlying value or the copy_on_write object.

◆ operator> [1/3]

template<typename T>
auto operator> ( const copy_on_write< T > & x,
const copy_on_write< T > & y ) -> bool
friend

Comparisons can be done with the underlying value or the copy_on_write object.

◆ operator> [2/3]

template<typename T>
auto operator> ( const copy_on_write< T > & x,
const element_type & y ) -> bool
friend

Comparisons can be done with the underlying value or the copy_on_write object.

◆ operator> [3/3]

template<typename T>
auto operator> ( const element_type & x,
const copy_on_write< T > & y ) -> bool
friend

Comparisons can be done with the underlying value or the copy_on_write object.

◆ operator>= [1/3]

template<typename T>
auto operator>= ( const copy_on_write< T > & x,
const copy_on_write< T > & y ) -> bool
friend

Comparisons can be done with the underlying value or the copy_on_write object.

◆ operator>= [2/3]

template<typename T>
auto operator>= ( const copy_on_write< T > & x,
const element_type & y ) -> bool
friend

Comparisons can be done with the underlying value or the copy_on_write object.

◆ operator>= [3/3]

template<typename T>
auto operator>= ( const element_type & x,
const copy_on_write< T > & y ) -> bool
friend

Comparisons can be done with the underlying value or the copy_on_write object.

◆ swap

template<typename T>
void swap ( copy_on_write< T > & x,
copy_on_write< T > & y )
friend

Efficiently swaps the contents of two copy_on_write objects.


The documentation for this class was generated from the following file: