Rework Dictionary::TryGet to use std::optional.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-12-12 12:53:47 +01:00
parent 362e4bf59b
commit 96315cb857
2 changed files with 7 additions and 10 deletions

View File

@@ -46,13 +46,12 @@ namespace ArbUt {
/// @brief Try to get an item from the dictionary using a key. Returns false if no item is found, and out will
/// not be touched in that case.
inline bool TryGet(const KeyT& key, ValueT& out) const noexcept {
inline std::optional<std::reference_wrapper<const ValueT>> TryGet(const KeyT& key) const noexcept {
const auto& find = _map.find(key);
if (find == _map.end()) {
return false;
return {};
}
out = find->second;
return true;
return std::ref(find->second);
}
/// @brief Removes an item with a certain key from the dictionary