C(++)ECCO
C++ Error Control COding: a header-only library for ECC simulations and experiments, modeling complete coding systems across arbitrary finite fields and complex inter-field relationships - Christian Senger <senger@inue.uni-stuttgart.de>
Loading...
Searching...
No Matches
CECCO::details::OnceCache< T > Class Template Reference

Thread-safe single-value cache. More...

#include <helpers.hpp>

Inheritance diagram for CECCO::details::OnceCache< T >:
Inheritance graph

Public Member Functions

 OnceCache ()=default
 OnceCache (const OnceCache &other)
 OnceCache (OnceCache &&other)
OnceCacheoperator= (const OnceCache &other)
OnceCacheoperator= (OnceCache &&other)
OnceCacheoperator= (const T &value)
OnceCacheoperator= (T &&value)
template<class F>
void call_once (F &&f) const
template<class... Args>
T & emplace (Args &&... args) const
bool has_value () const noexcept
 operator bool () const noexcept
T & value ()
const T & value () const
T & operator* ()
const T & operator* () const
T * operator-> ()
const T * operator-> () const
void reset () const

Detailed Description

template<class T>
class CECCO::details::OnceCache< T >

Thread-safe single-value cache.

Template Parameters
TValue type stored in the cache

Stores one optional value together with a std::once_flag. Use call_once() to guard lazy initialization when multiple threads may read the same object. Copying or moving a cache copies or moves the stored value, if any, and creates a fresh once flag.

Warning
Concurrent reads through call_once() are thread-safe. Assignment, emplace(), and manual value changes are not synchronization points and must not race with other operations.

Usage_Example

mutable OnceCache<size_t> weight;
weight.call_once([this] {
if (weight.has_value()) return;
weight.emplace(calculate_weight());
});
return weight.value();
void call_once(F &&f) const
Definition helpers.hpp:551
T & emplace(Args &&... args) const
Definition helpers.hpp:556
bool has_value() const noexcept
Definition helpers.hpp:560

Definition at line 512 of file helpers.hpp.

Constructor & Destructor Documentation

◆ OnceCache() [1/3]

template<class T>
CECCO::details::OnceCache< T >::OnceCache ( )
default

◆ OnceCache() [2/3]

template<class T>
CECCO::details::OnceCache< T >::OnceCache ( const OnceCache< T > & other)
inline

Definition at line 516 of file helpers.hpp.

◆ OnceCache() [3/3]

template<class T>
CECCO::details::OnceCache< T >::OnceCache ( OnceCache< T > && other)
inline

Definition at line 520 of file helpers.hpp.

Member Function Documentation

◆ call_once()

template<class T>
template<class F>
void CECCO::details::OnceCache< T >::call_once ( F && f) const
inline

Definition at line 551 of file helpers.hpp.

◆ emplace()

template<class T>
template<class... Args>
T & CECCO::details::OnceCache< T >::emplace ( Args &&... args) const
inline

Definition at line 556 of file helpers.hpp.

◆ has_value()

template<class T>
bool CECCO::details::OnceCache< T >::has_value ( ) const
inlinenoexcept

Definition at line 560 of file helpers.hpp.

Here is the caller graph for this function:

◆ operator bool()

template<class T>
CECCO::details::OnceCache< T >::operator bool ( ) const
inlineexplicitnoexcept

Definition at line 562 of file helpers.hpp.

Here is the call graph for this function:

◆ operator*() [1/2]

template<class T>
T & CECCO::details::OnceCache< T >::operator* ( )
inline

Definition at line 568 of file helpers.hpp.

◆ operator*() [2/2]

template<class T>
const T & CECCO::details::OnceCache< T >::operator* ( ) const
inline

Definition at line 570 of file helpers.hpp.

◆ operator->() [1/2]

template<class T>
T * CECCO::details::OnceCache< T >::operator-> ( )
inline

Definition at line 572 of file helpers.hpp.

◆ operator->() [2/2]

template<class T>
const T * CECCO::details::OnceCache< T >::operator-> ( ) const
inline

Definition at line 574 of file helpers.hpp.

◆ operator=() [1/4]

template<class T>
OnceCache & CECCO::details::OnceCache< T >::operator= ( const OnceCache< T > & other)
inline

Definition at line 524 of file helpers.hpp.

◆ operator=() [2/4]

template<class T>
OnceCache & CECCO::details::OnceCache< T >::operator= ( const T & value)
inline

Definition at line 540 of file helpers.hpp.

◆ operator=() [3/4]

template<class T>
OnceCache & CECCO::details::OnceCache< T >::operator= ( OnceCache< T > && other)
inline

Definition at line 532 of file helpers.hpp.

◆ operator=() [4/4]

template<class T>
OnceCache & CECCO::details::OnceCache< T >::operator= ( T && value)
inline

Definition at line 545 of file helpers.hpp.

◆ reset()

template<class T>
void CECCO::details::OnceCache< T >::reset ( ) const
inline

Definition at line 576 of file helpers.hpp.

◆ value() [1/2]

template<class T>
T & CECCO::details::OnceCache< T >::value ( )
inline

Definition at line 564 of file helpers.hpp.

◆ value() [2/2]

template<class T>
const T & CECCO::details::OnceCache< T >::value ( ) const
inline

Definition at line 566 of file helpers.hpp.


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