aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/unified_agent_client/variant.h
diff options
context:
space:
mode:
authorhor911 <hor911@ydb.tech>2023-02-09 12:40:11 +0300
committerhor911 <hor911@ydb.tech>2023-02-09 12:40:11 +0300
commit24689527cd888aa8a640ecb5077e656b3520d373 (patch)
treea613ff4cd9567b7113e8376a17f8b85897a42790 /library/cpp/unified_agent_client/variant.h
parent8642d3642932f03663ba7d2d9670707c192207fd (diff)
downloadydb-24689527cd888aa8a640ecb5077e656b3520d373.tar.gz
Log backend move
Diffstat (limited to 'library/cpp/unified_agent_client/variant.h')
-rw-r--r--library/cpp/unified_agent_client/variant.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/library/cpp/unified_agent_client/variant.h b/library/cpp/unified_agent_client/variant.h
new file mode 100644
index 0000000000..e261aa9af3
--- /dev/null
+++ b/library/cpp/unified_agent_client/variant.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include <variant>
+
+namespace NUnifiedAgent {
+ template<class... Ts> struct TOverloaded : Ts... { using Ts::operator()...; };
+ template<class... Ts> TOverloaded(Ts...) -> TOverloaded<Ts...>;
+
+ template <class T, class... U>
+ auto Visit(T&& variant, U&&... visitorOverloads) {
+ return std::visit(TOverloaded{std::forward<U>(visitorOverloads)...}, std::forward<T>(variant));
+ }
+
+ template <typename TTarget, typename... TSourceTypes>
+ auto CastTo(std::variant<TSourceTypes...>&& variant) {
+ return Visit(variant, [](auto& p) -> TTarget { return std::move(p); });
+ }
+}