aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/mapfindptr.h
diff options
context:
space:
mode:
authorAlexander Fokin <apfokin@gmail.com>2022-02-10 16:45:38 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:38 +0300
commit863a59a65247c24db7cb06789bc5cf79d04da32f (patch)
tree139dc000c8cd4a40f5659e421b7c75135d080307 /util/generic/mapfindptr.h
parentf64e95a9eb9ab03240599eb9581c5a9102426a96 (diff)
downloadydb-863a59a65247c24db7cb06789bc5cf79d04da32f.tar.gz
Restoring authorship annotation for Alexander Fokin <apfokin@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'util/generic/mapfindptr.h')
-rw-r--r--util/generic/mapfindptr.h48
1 files changed, 24 insertions, 24 deletions
diff --git a/util/generic/mapfindptr.h b/util/generic/mapfindptr.h
index bc10cac60f..b44585af48 100644
--- a/util/generic/mapfindptr.h
+++ b/util/generic/mapfindptr.h
@@ -1,7 +1,7 @@
#pragma once
-#include <type_traits>
-
+#include <type_traits>
+
/** MapFindPtr usage:
if (T* value = MapFindPtr(myMap, someKey) {
@@ -11,50 +11,50 @@ if (T* value = MapFindPtr(myMap, someKey) {
*/
template <class Map, class K>
-inline auto MapFindPtr(Map& map, const K& key) {
+inline auto MapFindPtr(Map& map, const K& key) {
auto i = map.find(key);
return (i == map.end() ? nullptr : &i->second);
}
template <class Map, class K>
-inline auto MapFindPtr(const Map& map, const K& key) {
+inline auto MapFindPtr(const Map& map, const K& key) {
auto i = map.find(key);
return (i == map.end() ? nullptr : &i->second);
}
/** helper for THashMap/TMap */
-template <class Derived>
+template <class Derived>
struct TMapOps {
template <class K>
- inline auto FindPtr(const K& key) {
+ inline auto FindPtr(const K& key) {
return MapFindPtr(static_cast<Derived&>(*this), key);
}
template <class K>
- inline auto FindPtr(const K& key) const {
+ inline auto FindPtr(const K& key) const {
return MapFindPtr(static_cast<const Derived&>(*this), key);
}
- template <class K, class DefaultValue>
- inline auto Value(const K& key, const DefaultValue& defaultValue) const -> std::remove_reference_t<decltype(*this->FindPtr(key))> {
- if (auto found = FindPtr(key)) {
+ template <class K, class DefaultValue>
+ inline auto Value(const K& key, const DefaultValue& defaultValue) const -> std::remove_reference_t<decltype(*this->FindPtr(key))> {
+ if (auto found = FindPtr(key)) {
return *found;
}
- return defaultValue;
+ return defaultValue;
}
-
- template <class K, class V>
- inline const V& ValueRef(const K& key, V& defaultValue) const {
- static_assert(std::is_same<std::remove_const_t<V>, typename Derived::mapped_type>::value, "Passed default value must have the same type as the underlying map's mapped_type.");
-
- if (auto found = FindPtr(key)) {
- return *found;
- }
- return defaultValue;
- }
-
- template <class K, class V>
- inline const V& ValueRef(const K& key, V&& defaultValue) const = delete;
+
+ template <class K, class V>
+ inline const V& ValueRef(const K& key, V& defaultValue) const {
+ static_assert(std::is_same<std::remove_const_t<V>, typename Derived::mapped_type>::value, "Passed default value must have the same type as the underlying map's mapped_type.");
+
+ if (auto found = FindPtr(key)) {
+ return *found;
+ }
+ return defaultValue;
+ }
+
+ template <class K, class V>
+ inline const V& ValueRef(const K& key, V&& defaultValue) const = delete;
};