8 template<
class T,
class U>
13 using CachedData = std::pair<T, U>;
14 using Comparator = std::function<bool(T const&, T const&)>;
15 using Releaser = std::function<U(U const&)>;
16 IMPLEMENTS_STD_VECTOR(CachedData, cached)
20 Comparator &&t_comparator = [](T
const &a, T
const &b) {
return a == b; },
21 Releaser &&t_releaser = [](U
const &res) {
return res; }
23 :comparator(std::forward<Comparator>(t_comparator)),
24 releaser(std::forward<Releaser>(t_releaser))
29 template<
class Calculator>
30 U calculate(T
const &input, Calculator &&calc)
32 if (
auto pos = find(input) ; pos != end()) {
33 return releaser(pos->second);
35 return releaser(add(input, calc(input)));
38 auto find(T
const &key) {
39 return std::find_if(cached.begin(), cached.end(),
40 [&](CachedData
const &data) {
41 return comparator(data.first, key);
45 auto find(T
const &key)
const {
46 return std::find_if(cached.begin(), cached.end(),
47 [&](CachedData
const &data) {
48 return comparator(data.first, key);
54 U
const &add(T
const &key, U
const &value) {
55 if (
auto pos = find(key) ; pos == end()) {
56 cached.push_back({key, releaser(value)});
57 return cached.back().second;
66 std::vector<CachedData> cached;
67 Comparator comparator;
Namespace of MARTY.
Definition: 2HDM.h:31