Stroika Library 3.0d23
 
Loading...
Searching...
No Matches
Stroika::Foundation::Cache::Memoizer< RESULT, CACHE, ARGS > Class Template Reference

Cache the results of expensive computations transparently. More...

#include <Memoizer.h>

Public Member Functions

nonvirtual RESULT operator() (ARGS... args)
 

Detailed Description

template<typename RESULT, template< qStroika_template_template_BWA(typename, typename)> class CACHE = LRUCache, typename... ARGS>
requires (ICache<CACHE<tuple<ARGS...>, RESULT>, tuple<ARGS...>, RESULT>)
class Stroika::Foundation::Cache::Memoizer< RESULT, CACHE, ARGS >

Cache the results of expensive computations transparently.

See also
https://en.wikipedia.org/wiki/Memoization

TODO: o

o

Example Usage
unsigned int totalCallsCount{};
Memoizer<int, LRUCache, int, int> memoizer{[&totalCallsCount](int a, int b) { ++totalCallsCount; return a + b; }};
EXPECT_TRUE (memoizer (1, 1) == 2 and totalCallsCount == 1);
EXPECT_TRUE (memoizer (1, 1) == 2 and totalCallsCount == 1);
// or even simpler declare memoizer as:
Memoizer memoizer = Cache::Factory::Memoizer::Make ([&totalCallsCount] (int a, int b) { totalCallsCount++; return a + b; });
Cache the results of expensive computations transparently.
Definition Memoizer.h:69
See also
Factory::Memoizer::Make () for more simple to use examples.
Note
Memoizer works well with LRUCache, or TimedCache.
Thread-Safety Same as (worse case of) underlying CACHE template argument, and argument function. Since the function will typically be fully reentrant, this comes down to the re-entrancy of the argument Cache.

Definition at line 69 of file Memoizer.h.

Member Function Documentation

◆ operator()()

template<typename RESULT , template< qStroika_template_template_BWA(typename, typename)> class CACHE, typename... ARGS>
requires (ICache<CACHE<tuple<ARGS...>, RESULT>, tuple<ARGS...>, RESULT>)
RESULT Stroika::Foundation::Cache::Memoizer< RESULT, CACHE, ARGS >::operator() ( ARGS...  args)
Note
this function is not const, because it modifies the state of the object/cache.

Definition at line 22 of file Memoizer.inl.


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