diff --git a/src/Collections/Dictionary.hpp b/src/Collections/Dictionary.hpp index 1cfd742..44a25d4 100644 --- a/src/Collections/Dictionary.hpp +++ b/src/Collections/Dictionary.hpp @@ -1,6 +1,7 @@ #ifndef ARBUTILS_DICTIONARY_HPP #define ARBUTILS_DICTIONARY_HPP #include +#include "../Assert.hpp" namespace Arbutils::Collections { template 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 {