mirror of
https://github.com/cemu-project/vcpkg.git
synced 2025-02-24 11:37:12 +01:00
22 lines
459 B
C
22 lines
459 B
C
![]() |
#pragma once
|
||
|
|
||
|
#include <map>
|
||
|
|
||
|
namespace vcpkg
|
||
|
{
|
||
|
template<class Key, class Value>
|
||
|
struct Cache
|
||
|
{
|
||
|
template<class F>
|
||
|
Value const& get_lazy(const Key& k, const F& f) const
|
||
|
{
|
||
|
auto it = m_cache.find(k);
|
||
|
if (it != m_cache.end()) return it->second;
|
||
|
return m_cache.emplace(k, f()).first->second;
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
mutable std::map<Key, Value> m_cache;
|
||
|
};
|
||
|
}
|