Make NO_ASSERT disable a lot of Dictionary safety in exchange for a bit more speed.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
5de26d0866
commit
e4c203027b
|
@ -1,6 +1,7 @@
|
|||
#ifndef ARBUTILS_DICTIONARY_HPP
|
||||
#define ARBUTILS_DICTIONARY_HPP
|
||||
#include <unordered_map>
|
||||
#include "../Assert.hpp"
|
||||
|
||||
namespace Arbutils::Collections {
|
||||
template <class KeyT, class ValueT> class Dictionary {
|
||||
|
@ -15,26 +16,36 @@ namespace Arbutils::Collections {
|
|||
|
||||
inline void Insert(KeyT key, ValueT value) {
|
||||
auto v = _map.insert({key, value});
|
||||
#ifndef NO_ASSERT
|
||||
if (!v.second)
|
||||
throw std::logic_error("Key already exists");
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void Set(KeyT key, ValueT value) { _map[key] = value; }
|
||||
|
||||
[[nodiscard]] inline ValueT& Get(KeyT key) {
|
||||
#ifndef NO_ASSERT
|
||||
auto find = _map.find(key);
|
||||
if (find == _map.end()) {
|
||||
throw std::logic_error("Key not found");
|
||||
}
|
||||
return find->second;
|
||||
#else
|
||||
return _map[key];
|
||||
#endif
|
||||
}
|
||||
|
||||
[[nodiscard]] inline const ValueT& Get(KeyT key) const {
|
||||
#ifndef NO_ASSERT
|
||||
auto find = _map.find(key);
|
||||
if (find == _map.end()) {
|
||||
throw std::logic_error("Key not found");
|
||||
}
|
||||
return find->second;
|
||||
#else
|
||||
return _map[key];
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool TryGet(KeyT key, ValueT& out) const {
|
||||
|
|
Loading…
Reference in New Issue