24 #include <boost/any.hpp>
54 template <
typename KeyType = std::
string>
63 boost::any_cast<T>(a);
66 catch (
const boost::bad_any_cast &)
73 using Clock = std::chrono::steady_clock;
78 std::enable_if_t<std::is_same<KeyType, std::string>::value &&
79 !std::is_same<KeyType, const char *>::value,
81 get(
const std::string &key)
const
83 auto itr =
store_.find(key);
88 "The object type for key " << key
89 <<
" mismatch the required type.");
90 return boost::any_cast<T>(itr->second);
97 std::enable_if_t<std::is_same<KeyType, const char *>::value &&
98 !std::is_same<KeyType, std::string>::value,
100 get(
const char *key)
const
102 return get<T>(std::string(key));
105 template <
typename T>
106 std::enable_if_t<!std::is_same<KeyType, const char *>::value &&
107 !std::is_same<KeyType, std::string>::value,
109 get(
const KeyType &key)
const
111 auto itr =
store_.find(key);
114 "NOT_SPECIFIED_BECAUSE_IS_NOT_STRING");
117 "The object type for key " << key
118 <<
" mismatch the required type.");
119 return boost::any_cast<T>(itr->second);
122 template <
typename T>
123 void set(
const KeyType &key,
const T &obj)
126 store_[key] = boost::any(obj);
129 template <
typename T>
130 void set(
const KeyType &key,
const T &obj,
131 const std::chrono::steady_clock::time_point &expire_at)
134 store_[key] = boost::any(obj);
149 bool has(
const KeyType &key)
const
159 std::vector<KeyType> to_remove;
161 auto now = Clock::now();
162 for (
const auto &expiry_info :
expiry_)
164 if (now > expiry_info.second)
166 to_remove.push_back(expiry_info.first);
170 for (
const auto &key : to_remove)