You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// std::map<enum, T>
template <typename TK, typename TV>
struct is_xpack_xtype<std::map<TK, TV>> {
static bool const value = true;
};
template <class OBJ, typename TK, typename TV>
bool xpack_xtype_decode(OBJ& obj, const char* key, std::map<TK, TV>& val, const Extend* ext) {
if constexpr (std::is_enum_v<TK>) {
std::map<int64_t, TV> tmp;
if (!obj.decode(key, tmp, ext)) {
return false;
}
val.clear();
for (auto&& item : tmp) {
val[item.first] = item.second;
}
return true;
} else {
static_assert(false, "std::map with this key type is not supported to decode");
return false;
}
}
template <class OBJ, typename TK, typename TV>
bool xpack_xtype_encode(OBJ& obj, const char* key, const std::map<TK, TV>& val, const Extend* ext) {
if constexpr (std::is_enum_v<TK>) {
std::map<TK, TV> tmp;
for (auto&& item : val) {
tmp[item.first] = item.second;
}
return obj.encode(key, tmp, ext);
} else {
static_assert(false, "std::map with this key type is not supported to encode");
return false;
}
}
The text was updated successfully, but these errors were encountered:
Zvicii
changed the title
Is it possible to add support for enum key based std::map
Is it possible to add support for enum key based std::map?
Jul 6, 2022
Currently Im using the following workaround.
The text was updated successfully, but these errors were encountered: