Commit b8fe4467 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Fix issue with vector<tuple<...>> in gt_hash_map/set

This also transforms a run-time exception into a static_assert, in case
there is no available default empty or deleted key of the specified type.
parent b16c2341
...@@ -31,14 +31,13 @@ ...@@ -31,14 +31,13 @@
#include SPARSEHASH_INCLUDE(dense_hash_map) #include SPARSEHASH_INCLUDE(dense_hash_map)
#endif #endif
template <class Key>
struct no_empty_key : std::exception {};
template <class Key> template <class Key>
struct empty_key struct empty_key
{ {
static Key get() static Key get()
{ {
static_assert(std::is_arithmetic<Key>::value,
"no default empty key for sparsehash!");
return dispatch(typename std::is_arithmetic<Key>::type()); return dispatch(typename std::is_arithmetic<Key>::type());
} }
...@@ -49,7 +48,8 @@ struct empty_key ...@@ -49,7 +48,8 @@ struct empty_key
static Key dispatch(std::integral_constant<bool, false>) static Key dispatch(std::integral_constant<bool, false>)
{ {
throw no_empty_key<Key>(); assert(false);
return Key();
} }
}; };
...@@ -83,15 +83,23 @@ struct empty_key<std::tuple<Val, Vals...>> ...@@ -83,15 +83,23 @@ struct empty_key<std::tuple<Val, Vals...>>
} }
}; };
template <>
struct empty_key<std::tuple<>>
{
static std::tuple<> get()
{
return std::tuple<>();
}
};
template <class Key>
struct no_deleted_key : std::exception {};
template <class Key> template <class Key>
struct deleted_key struct deleted_key
{ {
static Key get() static Key get()
{ {
static_assert(std::is_arithmetic<Key>::value,
"no default deleted key for sparsehash!");
return dispatch(typename std::is_arithmetic<Key>::type()); return dispatch(typename std::is_arithmetic<Key>::type());
} }
...@@ -105,7 +113,8 @@ struct deleted_key ...@@ -105,7 +113,8 @@ struct deleted_key
static Key dispatch(std::integral_constant<bool, false>) static Key dispatch(std::integral_constant<bool, false>)
{ {
throw no_deleted_key<Key>(); assert(false);
return Key();
} }
}; };
...@@ -139,6 +148,15 @@ struct deleted_key<std::tuple<Val, Vals...>> ...@@ -139,6 +148,15 @@ struct deleted_key<std::tuple<Val, Vals...>>
} }
}; };
template <>
struct deleted_key<std::tuple<>>
{
static std::tuple<> get()
{
return std::tuple<>();
}
};
template<class Key, template<class Key,
class Hash = std::hash<Key>, class Hash = std::hash<Key>,
class Pred = std::equal_to<Key>, class Pred = std::equal_to<Key>,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment