aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkvk1920 <kvk1920@yandex-team.com>2023-06-08 18:30:56 +0300
committerkvk1920 <kvk1920@yandex-team.com>2023-06-08 18:30:56 +0300
commitbb56a84dcf62e1f592b6be5a8fbc8298ee9478b0 (patch)
treeffa6684ecb5980ef3bfc7a1d55af3c6ad8acfaf8
parentef7da4cd6164363ba6bf9c4ab31d2736fc25d71e (diff)
downloadydb-bb56a84dcf62e1f592b6be5a8fbc8298ee9478b0.tar.gz
YT-19300: Various helpers for TStrongTypedef
-rw-r--r--library/cpp/yt/misc/strong_typedef-inl.h57
-rw-r--r--library/cpp/yt/misc/strong_typedef.h1
2 files changed, 57 insertions, 1 deletions
diff --git a/library/cpp/yt/misc/strong_typedef-inl.h b/library/cpp/yt/misc/strong_typedef-inl.h
index 836be91776..63914b321c 100644
--- a/library/cpp/yt/misc/strong_typedef-inl.h
+++ b/library/cpp/yt/misc/strong_typedef-inl.h
@@ -4,6 +4,9 @@
#include "strong_typedef.h"
#endif
+#include <util/generic/strbuf.h>
+#include <util/stream/fwd.h>
+
#include <functional>
namespace NYT {
@@ -60,6 +63,40 @@ constexpr T&& TStrongTypedef<T, TTag>::Underlying() &&
////////////////////////////////////////////////////////////////////////////////
+template <class T>
+struct TStrongTypedefTraits
+{
+ constexpr static bool IsStrongTypedef = false;
+};
+
+template <class T, class TTag>
+struct TStrongTypedefTraits<TStrongTypedef<T, TTag>>
+{
+ constexpr static bool IsStrongTypedef = true;
+ using TUnderlying = T;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
+template <class T, class TChar>
+ requires TStrongTypedefTraits<T>::IsStrongTypedef
+bool TryFromStringImpl(const TChar* data, size_t size, T& value)
+{
+ return TryFromString(data, size, value.Underlying());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+class TStringBuilderBase;
+
+template <class T, class TTag>
+void FormatValue(TStringBuilderBase* builder, const TStrongTypedef<T, TTag>& value, TStringBuf format)
+{
+ FormatValue(builder, value.Underlying(), format);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
} // namespace NYT
namespace std {
@@ -78,3 +115,23 @@ struct hash<NYT::TStrongTypedef<T, TTag>>
////////////////////////////////////////////////////////////////////////////////
} // namespace std
+
+////////////////////////////////////////////////////////////////////////////////
+
+template <class T>
+struct THash;
+
+template <class T, class TTag>
+struct THash<NYT::TStrongTypedef<T, TTag>>
+ : public std::hash<NYT::TStrongTypedef<T, TTag>>
+{ };
+
+////////////////////////////////////////////////////////////////////////////////
+
+template <class T, class TTag>
+IOutputStream& operator<<(IOutputStream& out, const NYT::TStrongTypedef<T, TTag>& value)
+{
+ return out << value.Underlying();
+}
+
+////////////////////////////////////////////////////////////////////////////////
diff --git a/library/cpp/yt/misc/strong_typedef.h b/library/cpp/yt/misc/strong_typedef.h
index cf0de6de12..545029db8d 100644
--- a/library/cpp/yt/misc/strong_typedef.h
+++ b/library/cpp/yt/misc/strong_typedef.h
@@ -1,6 +1,5 @@
#pragma once
-#include <type_traits>
#include <utility>
namespace NYT {