0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Attributes | List of all members
clanguml::util::memoized< T, Ret, Args > Class Template Reference

Simple memoization implementation for expensive methods. More...

Detailed Description

template<typename T, typename Ret, typename... Args>
class clanguml::util::memoized< T, Ret, Args >

Simple memoization implementation for expensive methods.

Template Parameters
TTag type to allow multiple memoizations per class
RetReturn type of the memoized method F
ArgsArguments the memoized method F

Definition at line 32 of file memoized.h.

#include <memoized.h>

Public Types

using key_t = std::tuple< Args... >
 
using value_t = Ret
 

Public Member Functions

template<typename F >
auto memoize (bool is_complete, F &&f, Args... args) const
 
void invalidate (Args... args) const
 

Private Attributes

std::map< key_t, value_tcache_
 

Member Typedef Documentation

◆ key_t

template<typename T , typename Ret , typename... Args>
using clanguml::util::memoized< T, Ret, Args >::key_t = std::tuple<Args...>

Definition at line 34 of file memoized.h.

◆ value_t

template<typename T , typename Ret , typename... Args>
using clanguml::util::memoized< T, Ret, Args >::value_t = Ret

Definition at line 35 of file memoized.h.

Member Function Documentation

◆ invalidate()

template<typename T , typename Ret , typename... Args>
void clanguml::util::memoized< T, Ret, Args >::invalidate ( Args...  args) const
inline

Definition at line 50 of file memoized.h.

50{ cache_.erase(args...); }

◆ memoize()

template<typename T , typename Ret , typename... Args>
template<typename F >
auto clanguml::util::memoized< T, Ret, Args >::memoize ( bool  is_complete,
F &&  f,
Args...  args 
) const
inline

Definition at line 38 of file memoized.h.

39 {
40 if (!is_complete)
41 return f(std::forward<Args>(args)...);
42
43 const auto key = key_t{std::forward<Args>(args)...};
44 if (cache_.find(key) == cache_.end())
45 cache_[key] = std::apply(f, key);
46
47 return cache_.at(key);
48 }

Member Data Documentation

◆ cache_

template<typename T , typename Ret , typename... Args>
std::map<key_t, value_t> clanguml::util::memoized< T, Ret, Args >::cache_
mutableprivate

Definition at line 53 of file memoized.h.


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