#ifndef CACHE_H #define CACHE_H #include "special_members.hpp" #include #include #include template class Cache { public: using Ptr = std::shared_ptr; Cache() = default; virtual ~Cache() = default; DEFAULT_MOVE(Cache); NO_COPY(Cache); [[nodiscard]] Ptr get(const std::string & key) { if (auto e = cached.find(key); e != cached.end()) { return e->second; } return cached.emplace(key, construct(key)).first->second; } [[nodiscard]] virtual Ptr construct(const std::string & key) const { return std::make_shared(key); } private: std::map cached; }; #endif