12 #include <type_traits> 13 #include <unordered_map> 18 template <
typename Enumeration>
20 typename std::underlying_type<Enumeration>::type {
21 return static_cast<typename std::underlying_type<Enumeration>::type
>(value);
26 template <
class Function>
38 : guardFunction_(
std::move(rhs.guardFunction_)), active_(rhs.active_) {
47 Function guardFunction_;
55 template <
class Function>
60 template <
typename K,
typename V>
68 std::pair<typename std::list<K>::iterator, std::unique_ptr<V>>>
76 inline V*
put(K k, std::unique_ptr<V>&& v) {
77 if (map_.find(k) == map_.end()) {
79 if (dq_.size() == csize_) {
80 map_.erase(dq_.back());
84 dq_.erase(map_[k].first);
88 map_[k] = std::make_pair(dq_.begin(), std::move(v));
89 return map_[k].second.get();
92 inline V*
get(K
const& k) {
93 if (map_.find(k) == map_.end()) {
97 auto& it = map_[k].first;
98 dq_.splice(dq_.begin(), dq_, it);
99 return map_[k].second.get();
Definition: language.h:27
ScopeGuard< Function > makeGuard(Function f)
Definition: language.h:56
LRUCache(int n)
Definition: language.h:74
~ScopeGuard()
Definition: language.h:31
auto enumAsInt(Enumeration const value) -> typename std::underlying_type< Enumeration >::type
Definition: language.h:19
Definition: language.h:61
General utilities.
Definition: assert.cpp:7
void dismiss()
Definition: language.h:42
ScopeGuard(Function f)
Definition: language.h:29
ScopeGuard(ScopeGuard &&rhs)
Definition: language.h:37
V * put(K k, std::unique_ptr< V > &&v)
Definition: language.h:76