Thoth
A functional, expressive, asynchronous C++26 webdev library
Loading...
Searching...
No Matches
Thoth::Dsa::Cow< RefT, OwnT > Struct Template Reference

Like Rust's cow (copy on write). More...

#include <Cow.hpp>

Public Types

using ValueType = std::variant< RefT, OwnT >
 
using RefType = RefT
 
using OwnType = OwnT
 

Public Member Functions

constexpr Cow ()=default
 
constexpr Cow (RefT) noexcept
 
constexpr Cow (Cow &&) noexcept=default
 
constexpr Cow (const Cow &other)
 
constexpr Cowoperator= (Cow &&other) noexcept=default
 
constexpr Cowoperator= (const Cow &other)
 
constexpr CowSetRef (RefT ref)
 Sets the value to a new RefT.
 
constexpr bool IsRef () const
 Check if the value is a RefT or OwnT.
 
constexpr CowSetOwned (const OwnT &own)
 Set value to a new OwnT from another OwnT.
 
constexpr CowSetOwned (OwnT &&own)
 Set value to a new OwnT from another OwnT.
 
constexpr OwnT & AsOwned ()
 Converts the RefT type to a OwnT.
 
constexpr OwnT AsCopy () const
 Returns a copy of the value as OwnT without modifying it.
 
constexpr RefT AsRef () const
 Returns a reference of the value as RefT without modifying it.
 
template<class Callable >
constexpr decltype(auto) Visit (Callable &&callable)
 convenient call to std::visit() on _value.
 
template<class Callable >
constexpr decltype(auto) Visit (Callable &&callable) const
 convenient call to std::visit() on _value.
 

Static Public Member Functions

static constexpr Cow FromRef (RefT ref)
 Constructs a Cow from a RefT.
 
static constexpr bool IsRefType (const Cow &cow)
 Check if the value is a RefT or OwnT.
 
static constexpr Cow FromOwned (const OwnT &own)
 Create a OwnT value from another OwnT.
 
static constexpr Cow FromOwned (OwnT &&own)
 Create a OwnT value from another OwnT.
 

Detailed Description

template<class RefT, class OwnT>
requires std::constructible_from<OwnT, RefT>
struct Thoth::Dsa::Cow< RefT, OwnT >

Like Rust's cow (copy on write).

The value can a RefT or a OwnT. RefT are lightweight objects designed to reference external buffers, while OwnT are objects that stores it own data so they can be heavy to create and copy. Editing the Cow triggers transform the RefT in OwnT. You need to be able to construct OwnT from RefT and RefT from OwnT.

Member Typedef Documentation

◆ OwnType

template<class RefT , class OwnT >
using Thoth::Dsa::Cow< RefT, OwnT >::OwnType = OwnT

◆ RefType

template<class RefT , class OwnT >
using Thoth::Dsa::Cow< RefT, OwnT >::RefType = RefT

◆ ValueType

template<class RefT , class OwnT >
using Thoth::Dsa::Cow< RefT, OwnT >::ValueType = std::variant<RefT, OwnT>

Constructor & Destructor Documentation

◆ Cow() [1/4]

template<class RefT , class OwnT >
constexpr Thoth::Dsa::Cow< RefT, OwnT >::Cow ( )
constexprdefault

◆ Cow() [2/4]

template<class RefT , class OwnT >
constexpr Thoth::Dsa::Cow< RefT, OwnT >::Cow ( RefT  )
constexprnoexcept

◆ Cow() [3/4]

template<class RefT , class OwnT >
constexpr Thoth::Dsa::Cow< RefT, OwnT >::Cow ( Cow< RefT, OwnT > &&  )
constexprdefaultnoexcept

◆ Cow() [4/4]

template<class RefT , class OwnT >
constexpr Thoth::Dsa::Cow< RefT, OwnT >::Cow ( const Cow< RefT, OwnT > &  other)
constexpr

Member Function Documentation

◆ AsCopy()

template<class RefT , class OwnT >
constexpr OwnT Thoth::Dsa::Cow< RefT, OwnT >::AsCopy ( ) const
constexpr

Returns a copy of the value as OwnT without modifying it.

◆ AsOwned()

template<class RefT , class OwnT >
constexpr OwnT & Thoth::Dsa::Cow< RefT, OwnT >::AsOwned ( )
constexpr

Converts the RefT type to a OwnT.

◆ AsRef()

template<class RefT , class OwnT >
constexpr RefT Thoth::Dsa::Cow< RefT, OwnT >::AsRef ( ) const
constexpr

Returns a reference of the value as RefT without modifying it.

◆ FromOwned() [1/2]

template<class RefT , class OwnT >
static constexpr Cow Thoth::Dsa::Cow< RefT, OwnT >::FromOwned ( const OwnT &  own)
staticconstexpr

Create a OwnT value from another OwnT.

◆ FromOwned() [2/2]

template<class RefT , class OwnT >
static constexpr Cow Thoth::Dsa::Cow< RefT, OwnT >::FromOwned ( OwnT &&  own)
staticconstexpr

Create a OwnT value from another OwnT.

◆ FromRef()

template<class RefT , class OwnT >
static constexpr Cow Thoth::Dsa::Cow< RefT, OwnT >::FromRef ( RefT  ref)
staticconstexpr

Constructs a Cow from a RefT.

◆ IsRef()

template<class RefT , class OwnT >
constexpr bool Thoth::Dsa::Cow< RefT, OwnT >::IsRef ( ) const
constexpr

Check if the value is a RefT or OwnT.

◆ IsRefType()

template<class RefT , class OwnT >
static constexpr bool Thoth::Dsa::Cow< RefT, OwnT >::IsRefType ( const Cow< RefT, OwnT > &  cow)
staticconstexpr

Check if the value is a RefT or OwnT.

◆ operator=() [1/2]

template<class RefT , class OwnT >
constexpr Cow & Thoth::Dsa::Cow< RefT, OwnT >::operator= ( const Cow< RefT, OwnT > &  other)
constexpr

◆ operator=() [2/2]

template<class RefT , class OwnT >
constexpr Cow & Thoth::Dsa::Cow< RefT, OwnT >::operator= ( Cow< RefT, OwnT > &&  other)
constexprdefaultnoexcept

◆ SetOwned() [1/2]

template<class RefT , class OwnT >
constexpr Cow & Thoth::Dsa::Cow< RefT, OwnT >::SetOwned ( const OwnT &  own)
constexpr

Set value to a new OwnT from another OwnT.

◆ SetOwned() [2/2]

template<class RefT , class OwnT >
constexpr Cow & Thoth::Dsa::Cow< RefT, OwnT >::SetOwned ( OwnT &&  own)
constexpr

Set value to a new OwnT from another OwnT.

◆ SetRef()

template<class RefT , class OwnT >
constexpr Cow & Thoth::Dsa::Cow< RefT, OwnT >::SetRef ( RefT  ref)
constexpr

Sets the value to a new RefT.

◆ Visit() [1/2]

template<class RefT , class OwnT >
template<class Callable >
constexpr decltype(auto) Thoth::Dsa::Cow< RefT, OwnT >::Visit ( Callable &&  callable)
constexpr

convenient call to std::visit() on _value.

◆ Visit() [2/2]

template<class RefT , class OwnT >
template<class Callable >
constexpr decltype(auto) Thoth::Dsa::Cow< RefT, OwnT >::Visit ( Callable &&  callable) const
constexpr

convenient call to std::visit() on _value.


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