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; });
Parallel::GlobalCache< Metavariables > & cache(MockRuntimeSystem< Metavariables > &runner, const ArrayIndex &array_index)
Returns the GlobalCache of Component with index array_index.
Definition: MockRuntimeSystemFreeFunctions.hpp:379
Range of integral values for StaticCache indices. The Start is inclusive and the End is exclusive....
Definition: StaticCache.hpp:19
Example
A cache with enumeration indices:
CHECK(simple_enum_cache(Color::Red) == "Red" );
Make a string by streaming into object.
Definition: MakeString.hpp:18
auto make_static_cache(Generator &&generator)
Create a StaticCache, inferring the cached type from the generator.
Definition: StaticCache.hpp:198
Possible enumeration values for the StaticCache. Only values specified here are retrievable.
Definition: StaticCache.hpp:34
Example
A cache with mixed numeric and enumeration indices:
Animal::Poodle>>(
[](
const Color color,
const size_t value ,
const Animal 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" );
constexpr T & value(T &t)
Returns t.value() if t is a std::optional otherwise returns t.
Definition: OptionalHelpers.hpp:32
Example
A cache with no arguments at all (caching only a single object)
const auto simple_small_cache =
CHECK(simple_small_cache() == 10);
See also make_static_cache
Template Parameters
T type held in the cache
Ranges ranges of valid indices