aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-03-08 12:14:09 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-03-08 12:22:31 +0300
commit9584fd808b5bbcd989348a67768064134e3341d9 (patch)
tree601ec8deabb8dcdca66d4123cd7a0dcf7d804243 /library/cpp/yt
parente8116f70daae60dcbf13132581dba893802ce3fe (diff)
downloadydb-9584fd808b5bbcd989348a67768064134e3341d9.tar.gz
Intermediate changes
Diffstat (limited to 'library/cpp/yt')
-rw-r--r--library/cpp/yt/misc/optional.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/library/cpp/yt/misc/optional.h b/library/cpp/yt/misc/optional.h
new file mode 100644
index 0000000000..cfae5c36d5
--- /dev/null
+++ b/library/cpp/yt/misc/optional.h
@@ -0,0 +1,72 @@
+#pragma once
+
+#include <util/string/cast.h>
+
+#include <optional>
+
+namespace NYT {
+
+////////////////////////////////////////////////////////////////////////////////
+
+template <class T>
+struct TOptionalTraits
+{
+ using TOptional = std::optional<T>;
+ using TValue = T;
+};
+
+template <class T>
+struct TOptionalTraits<std::optional<T>>
+{
+ using TOptional = std::optional<T>;
+ using TValue = T;
+};
+
+template <class T>
+struct TOptionalTraits<T*>
+{
+ using TOptional = T*;
+ using TValue = T*;
+};
+
+template <class T>
+struct TOptionalTraits<TIntrusivePtr<T>>
+{
+ using TOptional = TIntrusivePtr<T>;
+ using TValue = TIntrusivePtr<T>;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
+template <class T>
+struct TStdOptionalTraits
+{
+ static constexpr bool IsStdOptional = false;
+ using TValueType = T;
+};
+
+template <class T>
+struct TStdOptionalTraits<std::optional<T>>
+{
+ static constexpr bool IsStdOptional = true;
+ using TValueType = T;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT
+
+template <class T>
+TString ToString(const std::optional<T>& nullable)
+{
+ return nullable ? ToString(*nullable) : "<Null>";
+}
+
+template <class T>
+struct THash<std::optional<T>>
+{
+ size_t operator()(const std::optional<T>& nullable) const
+ {
+ return nullable ? THash<T>()(*nullable) : 0;
+ }
+};