aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic
diff options
context:
space:
mode:
authorswarmer <swarmer@yandex-team.com>2023-12-15 17:08:08 +0300
committerswarmer <swarmer@yandex-team.com>2023-12-15 19:34:46 +0300
commitb009ee7c484628cd91409b1d7b328e38aa4e4079 (patch)
treea4a338cad0c4aa623db34614ce28535c3177302f /util/generic
parented88f5773993cad8389038c006bbad44bb757ad5 (diff)
downloadydb-b009ee7c484628cd91409b1d7b328e38aa4e4079.tar.gz
detect dangling references in MapFindPtr and utility helpers
Diffstat (limited to 'util/generic')
-rw-r--r--util/generic/mapfindptr.h14
-rw-r--r--util/generic/utility.h12
2 files changed, 15 insertions, 11 deletions
diff --git a/util/generic/mapfindptr.h b/util/generic/mapfindptr.h
index 57a5805de4..bb6dc61755 100644
--- a/util/generic/mapfindptr.h
+++ b/util/generic/mapfindptr.h
@@ -1,5 +1,7 @@
#pragma once
+#include <util/system/compiler.h>
+
#include <type_traits>
#include <utility>
@@ -12,14 +14,14 @@ if (T* value = MapFindPtr(myMap, someKey) {
*/
template <class Map, class K>
-inline auto MapFindPtr(Map& map, const K& key) {
+inline auto MapFindPtr(Map& map Y_LIFETIME_BOUND, 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 Y_LIFETIME_BOUND, const K& key) {
auto i = map.find(key);
return (i == map.end() ? nullptr : &i->second);
@@ -29,12 +31,12 @@ inline auto MapFindPtr(const Map& map, const K& key) {
template <class Derived>
struct TMapOps {
template <class K>
- inline auto FindPtr(const K& key) {
+ inline auto FindPtr(const K& key) Y_LIFETIME_BOUND {
return MapFindPtr(static_cast<Derived&>(*this), key);
}
template <class K>
- inline auto FindPtr(const K& key) const {
+ inline auto FindPtr(const K& key) const Y_LIFETIME_BOUND {
return MapFindPtr(static_cast<const Derived&>(*this), key);
}
@@ -45,7 +47,7 @@ struct TMapOps {
}
template <class K, class V>
- inline const V& ValueRef(const K& key, V& defaultValue) const {
+ inline const V& ValueRef(const K& key, V& defaultValue Y_LIFETIME_BOUND) const Y_LIFETIME_BOUND {
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)) {
@@ -55,5 +57,5 @@ struct TMapOps {
}
template <class K, class V>
- inline const V& ValueRef(const K& key, V&& defaultValue) const = delete;
+ inline const V& ValueRef(const K& key, V&& defaultValue Y_LIFETIME_BOUND) const Y_LIFETIME_BOUND = delete;
};
diff --git a/util/generic/utility.h b/util/generic/utility.h
index 43b98eeafc..5362fd4e42 100644
--- a/util/generic/utility.h
+++ b/util/generic/utility.h
@@ -2,31 +2,33 @@
#include "typetraits.h"
+#include <util/system/compiler.h>
+
#include <cstring>
template <class T>
-static constexpr const T& Min(const T& l, const T& r) {
+static constexpr const T& Min(const T& l Y_LIFETIME_BOUND, const T& r Y_LIFETIME_BOUND) {
return r < l ? r : l;
}
template <typename T, typename... Args>
-static constexpr const T& Min(const T& a, const T& b, const Args&... args) {
+static constexpr const T& Min(const T& a Y_LIFETIME_BOUND, const T& b Y_LIFETIME_BOUND, const Args&... args Y_LIFETIME_BOUND) {
return Min(a, Min(b, args...));
}
template <class T>
-static constexpr const T& Max(const T& l, const T& r) {
+static constexpr const T& Max(const T& l Y_LIFETIME_BOUND, const T& r Y_LIFETIME_BOUND) {
return l < r ? r : l;
}
template <typename T, typename... Args>
-static constexpr const T& Max(const T& a, const T& b, const Args&... args) {
+static constexpr const T& Max(const T& a Y_LIFETIME_BOUND, const T& b Y_LIFETIME_BOUND, const Args&... args Y_LIFETIME_BOUND) {
return Max(a, Max(b, args...));
}
// replace with http://en.cppreference.com/w/cpp/algorithm/clamp in c++17
template <class T>
-constexpr const T& ClampVal(const T& val, const T& min, const T& max) {
+constexpr const T& ClampVal(const T& val Y_LIFETIME_BOUND, const T& min Y_LIFETIME_BOUND, const T& max Y_LIFETIME_BOUND) {
return val < min ? min : (max < val ? max : val);
}