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::Cache< ENTRIES > Class Template Reference

Heterogeneous cache indexed by entry ID. More...

#include <helpers.hpp>

Inheritance diagram for CECCO::details::Cache< ENTRIES >:
Inheritance graph

Public Member Functions

 Cache ()=default
template<auto ID>
bool is_set () const noexcept
template<auto ID, typename TYPE>
void set (TYPE &&value) const
template<auto ID>
bool invalidate () const noexcept
bool invalidate () const noexcept
template<auto ID>
const type_for< ID > & operator() (auto &&calculate_func) const
template<auto ID>
std::optional< type_for< ID > > get () const
template<auto ID>
const type_for< ID > & get_or_compute (auto &&calculate_func) const

Detailed Description

template<typename... ENTRIES>
class CECCO::details::Cache< ENTRIES >

Heterogeneous cache indexed by entry ID.

Template Parameters
ENTRIESPack of CacheEntry types

Each ID gets its own std::optional<T> slot in a std::tuple, so different IDs may share the same value type without ambiguity. Lookup is by compile-time ID; an unknown ID is a compile-time error.

Warning
Not thread-safe for concurrent writes. Use external synchronisation if multiple threads may call set(), invalidate(), or operator() simultaneously.

Usage_Example

using Entry2 = CacheEntry<1, double>;
using Entry3 = CacheEntry<5, std::string>; // IDs need not be consecutive
cache.set<0>(std::vector<int>{1, 2, 3});
auto& vec = cache.get_or_compute<0>([] { return std::vector<int>{4, 5, 6}; });
if (cache.is_set<0>()) cache.invalidate<0>();
bool is_set() const noexcept
Definition helpers.hpp:442
bool invalidate() const noexcept
Definition helpers.hpp:452
const type_for< ID > & get_or_compute(auto &&calculate_func) const
Definition helpers.hpp:482
void set(TYPE &&value) const
Definition helpers.hpp:447
Cache entry specification.
Definition helpers.hpp:377

Definition at line 408 of file helpers.hpp.

Constructor & Destructor Documentation

◆ Cache()

template<typename... ENTRIES>
CECCO::details::Cache< ENTRIES >::Cache ( )
default

Member Function Documentation

◆ get()

template<typename... ENTRIES>
template<auto ID>
std::optional< type_for< ID > > CECCO::details::Cache< ENTRIES >::get ( ) const
inline

Definition at line 477 of file helpers.hpp.

◆ get_or_compute()

template<typename... ENTRIES>
template<auto ID>
const type_for< ID > & CECCO::details::Cache< ENTRIES >::get_or_compute ( auto && calculate_func) const
inline

Definition at line 482 of file helpers.hpp.

◆ invalidate() [1/2]

template<typename... ENTRIES>
bool CECCO::details::Cache< ENTRIES >::invalidate ( ) const
inlinenoexcept

Definition at line 459 of file helpers.hpp.

◆ invalidate() [2/2]

template<typename... ENTRIES>
template<auto ID>
bool CECCO::details::Cache< ENTRIES >::invalidate ( ) const
inlinenoexcept

Definition at line 452 of file helpers.hpp.

◆ is_set()

template<typename... ENTRIES>
template<auto ID>
bool CECCO::details::Cache< ENTRIES >::is_set ( ) const
inlinenoexcept

Definition at line 442 of file helpers.hpp.

◆ operator()()

template<typename... ENTRIES>
template<auto ID>
const type_for< ID > & CECCO::details::Cache< ENTRIES >::operator() ( auto && calculate_func) const
inline

Definition at line 470 of file helpers.hpp.

◆ set()

template<typename... ENTRIES>
template<auto ID, typename TYPE>
void CECCO::details::Cache< ENTRIES >::set ( TYPE && value) const
inline

Definition at line 447 of file helpers.hpp.


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