cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
toolbox::functional::detail::MemoizeState< Func, R, Args > Struct Template Reference

记忆化的内部状态 / Internal state for memoization More...

#include <functional.hpp>

Public Types

using KeyType = std::tuple< std::decay_t< Args >... >
 
using ResultType = R
 

Public Member Functions

 MemoizeState (Func &&f)
 

Public Attributes

Func original_func
 
std::map< KeyType, ResultTypecache
 
std::mutex cache_mutex
 

Detailed Description

template<typename Func, typename R, typename... Args>
struct toolbox::functional::detail::MemoizeState< Func, R, Args >

记忆化的内部状态 / Internal state for memoization

MemoizeState<int(int), int, int> state{[](int x) { return x*x; }};
auto result = state.original_func(5); // 返回25 / Returns 25
记忆化的内部状态 / Internal state for memoization
Definition functional.hpp:203
Func original_func
Definition functional.hpp:207

Member Typedef Documentation

◆ KeyType

template<typename Func , typename R , typename... Args>
using toolbox::functional::detail::MemoizeState< Func, R, Args >::KeyType = std::tuple<std::decay_t<Args>...>

◆ ResultType

template<typename Func , typename R , typename... Args>
using toolbox::functional::detail::MemoizeState< Func, R, Args >::ResultType = R

Constructor & Destructor Documentation

◆ MemoizeState()

template<typename Func , typename R , typename... Args>
toolbox::functional::detail::MemoizeState< Func, R, Args >::MemoizeState ( Func &&  f)
inline

Member Data Documentation

◆ cache

template<typename Func , typename R , typename... Args>
std::map<KeyType, ResultType> toolbox::functional::detail::MemoizeState< Func, R, Args >::cache

◆ cache_mutex

template<typename Func , typename R , typename... Args>
std::mutex toolbox::functional::detail::MemoizeState< Func, R, Args >::cache_mutex

◆ original_func

template<typename Func , typename R , typename... Args>
Func toolbox::functional::detail::MemoizeState< Func, R, Args >::original_func

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