Make Dictionary function parameters all passed by reference
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-04-21 13:59:01 +02:00
parent 96995d071f
commit 5e3b067452
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
1 changed files with 10 additions and 9 deletions

View File

@ -19,7 +19,7 @@ namespace Arbutils::Collections {
_map.clear();
}
inline void Insert(KeyT key, ValueT value) {
inline void Insert(const KeyT& key, const ValueT& value) {
auto v = _map.insert({key, value});
#ifndef NO_ASSERT
if (!v.second)
@ -27,9 +27,10 @@ namespace Arbutils::Collections {
#endif
}
inline void Set(KeyT key, ValueT value) { _map[key] = value; }
[[nodiscard]] inline ValueT& Get(KeyT key) {
inline void Set(const KeyT& key, const ValueT& value) { _map[key] = value; }
[[nodiscard]] inline ValueT& Get(const KeyT& key) {
#ifndef NO_ASSERT
auto find = _map.find(key);
if (find == _map.end()) {
@ -41,7 +42,7 @@ namespace Arbutils::Collections {
#endif
}
[[nodiscard]] inline const ValueT& Get(KeyT key) const {
[[nodiscard]] inline const ValueT& Get(const KeyT& key) const {
#ifndef NO_ASSERT
auto find = _map.find(key);
if (find == _map.end()) {
@ -53,7 +54,7 @@ namespace Arbutils::Collections {
#endif
}
inline bool TryGet(KeyT key, ValueT& out) const {
inline bool TryGet(const KeyT& key, ValueT& out) const {
auto find = _map.find(key);
if (find == _map.end()) {
return false;
@ -62,16 +63,16 @@ namespace Arbutils::Collections {
return true;
}
inline void Remove(KeyT key){
inline void Remove(const KeyT& key){
_map.erase(key);
}
[[nodiscard]] inline size_t Count() const { return _map.size(); }
inline bool Has(KeyT key) const noexcept { return _map.find(key) != _map.end(); }
inline bool Has(const KeyT& key) const noexcept { return _map.find(key) != _map.end(); }
inline ValueT& operator[](KeyT key) { return Get(key); }
inline const ValueT& operator[](KeyT key) const { return Get(key); }
inline ValueT& operator[](const KeyT& key) { return Get(key); }
inline const ValueT& operator[](const KeyT& key) const { return Get(key); }
iterator begin() { return _map.begin(); }
const_iterator begin() const { return _map.begin(); }