SpECTRE  v2026.04.01
Loading...
Searching...
No Matches
StaticCache< Generator, T, Ranges > Class Template Reference

A cache of objects intended to be stored in a static variable. More...

#include <StaticCache.hpp>

Public Member Functions

template<typename Gen>
 StaticCache (Gen &&generator)
template<typename... Args>
const T & operator() (const Args... parameters) const

Detailed Description

template<typename Generator, typename T, typename... Ranges>
class StaticCache< Generator, T, Ranges >

A cache of objects intended to be stored in a static variable.

Objects can be accessed via a combination of several size_t and enum arguments. The range of each integral argument is specified via a template parameter of type CacheRange<start, end>, giving the first and one-past-last values for the range. Each enum argument is specified by a template parameter of type CacheEnumeration<EnumerationType, Members...> giving the enumeration type and an explicit set of every enum member to be cached.

Example

A cache with only numeric indices:

const static auto cache =
[](const size_t a, const size_t b) { return a + b; });
CHECK(cache(0, 3) == 3); // smallest entry
CHECK(cache(2, 4) == 6); // largest entry

Example

A cache with enumeration indices:

const auto simple_enum_cache = make_static_cache<
[](const Color color) { return std::string{MakeString{} << color}; });
CHECK(simple_enum_cache(Color::Red) == "Red");

Example

A cache with mixed numeric and enumeration indices:

const auto simple_enum_size_t_enum_cache = make_static_cache<
CacheEnumeration<Animal, Animal::Goldendoodle, Animal::Labradoodle,
Animal::Poodle>>(
[](const Color color, const size_t value, const Animal animal) {
return std::string{MakeString{} << color << value << animal};
});
CHECK(simple_enum_size_t_enum_cache(Color::Red, 3, Animal::Labradoodle) ==
"Red3Labradoodle");
CHECK(simple_enum_size_t_enum_cache(Color::Purple, 4, Animal::Poodle) ==
"Purple4Poodle");

Example

A cache with no arguments at all (caching only a single object)

const auto simple_small_cache =
make_static_cache([]() { return size_t{10}; });
CHECK(simple_small_cache() == 10);
See also
make_static_cache
Template Parameters
Ttype held in the cache
Rangesranges of valid indices

The documentation for this class was generated from the following file:
  • src/Utilities/StaticCache.hpp