Zth (libzth)
zth::cow_string Class Reference

Copy-on-write string. More...

#include <util.h>

Public Member Functions

 cow_string ()
 
 cow_string (char const *s)
 
 cow_string (string const &s)
 
 cow_string (cow_string const &s)
 
cow_stringoperator= (cow_string const &s)
 
cow_stringoperator= (char const *s)
 
cow_stringoperator= (string const &s)
 
 cow_string (cow_string &&s)=default
 
cow_stringoperator= (cow_string &&s)=default
 
 cow_string (string &&s)
 
cow_stringoperator= (string &&s)
 
string str () &&
 
string const & str () const &
 
char const * c_str () const
 
 operator string const & () const
 
char const & at (size_t pos) const
 
char operator[] (size_t pos) const
 
char & operator[] (size_t pos)
 
char const * data () const
 
bool empty () const noexcept
 
size_t size () const noexcept
 
size_t length () const noexcept
 
void clear () noexcept
 
bool isConst () const noexcept
 
bool isLocal () const noexcept
 

Protected Member Functions

string const & local () const
 
stringlocal ()
 

Detailed Description

Copy-on-write string.

It holds either a pointer to the a const char array, or a string instance. So, it is cheap for string literals, avoids duplicating these into std::string, but still allows to do so when required.

Examples
measure.cpp.

Definition at line 344 of file util.h.

Constructor & Destructor Documentation

◆ cow_string() [1/6]

zth::cow_string::cow_string ( )
inline

Definition at line 346 of file util.h.

◆ cow_string() [2/6]

zth::cow_string::cow_string ( char const *  s)
inline

Definition at line 351 of file util.h.

◆ cow_string() [3/6]

zth::cow_string::cow_string ( string const &  s)
inline

Definition at line 356 of file util.h.

◆ cow_string() [4/6]

zth::cow_string::cow_string ( cow_string const &  s)
inline

Definition at line 361 of file util.h.

◆ cow_string() [5/6]

zth::cow_string::cow_string ( cow_string &&  s)
default

◆ cow_string() [6/6]

zth::cow_string::cow_string ( string &&  s)
inline

Definition at line 392 of file util.h.

Member Function Documentation

◆ at()

char const& zth::cow_string::at ( size_t  pos) const
inline

Definition at line 426 of file util.h.

◆ c_str()

char const* zth::cow_string::c_str ( ) const
inline

Definition at line 416 of file util.h.

◆ clear()

void zth::cow_string::clear ( )
inlinenoexcept

Definition at line 461 of file util.h.

◆ data()

char const* zth::cow_string::data ( ) const
inline

Definition at line 441 of file util.h.

◆ empty()

bool zth::cow_string::empty ( ) const
inlinenoexcept

Definition at line 446 of file util.h.

◆ isConst()

bool zth::cow_string::isConst ( ) const
inlinenoexcept

Definition at line 467 of file util.h.

◆ isLocal()

bool zth::cow_string::isLocal ( ) const
inlinenoexcept

Definition at line 472 of file util.h.

◆ length()

size_t zth::cow_string::length ( ) const
inlinenoexcept

Definition at line 456 of file util.h.

◆ local() [1/2]

string& zth::cow_string::local ( )
inlineprotected

Definition at line 487 of file util.h.

◆ local() [2/2]

string const& zth::cow_string::local ( ) const
inlineprotected

Definition at line 478 of file util.h.

◆ operator string const &()

zth::cow_string::operator string const & ( ) const
inline

Definition at line 421 of file util.h.

◆ operator=() [1/5]

cow_string& zth::cow_string::operator= ( char const *  s)
inline

Definition at line 373 of file util.h.

◆ operator=() [2/5]

cow_string& zth::cow_string::operator= ( cow_string &&  s)
default

◆ operator=() [3/5]

cow_string& zth::cow_string::operator= ( cow_string const &  s)
inline

Definition at line 366 of file util.h.

◆ operator=() [4/5]

cow_string& zth::cow_string::operator= ( string &&  s)
inline

Definition at line 397 of file util.h.

◆ operator=() [5/5]

cow_string& zth::cow_string::operator= ( string const &  s)
inline

Definition at line 380 of file util.h.

◆ operator[]() [1/2]

char& zth::cow_string::operator[] ( size_t  pos)
inline

Definition at line 436 of file util.h.

◆ operator[]() [2/2]

char zth::cow_string::operator[] ( size_t  pos) const
inline

Definition at line 431 of file util.h.

◆ size()

size_t zth::cow_string::size ( ) const
inlinenoexcept

Definition at line 451 of file util.h.

◆ str() [1/2]

string zth::cow_string::str ( ) &&
inline

Definition at line 404 of file util.h.

◆ str() [2/2]

string const& zth::cow_string::str ( ) const &
inline

Definition at line 411 of file util.h.


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