diff options
author | shakurov <shakurov@yandex-team.ru> | 2022-02-10 16:49:23 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:23 +0300 |
commit | 296627beeba9eb1fbc3cc1ff3dbae3ff192fb2a8 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/yt/misc/variant.h | |
parent | 6750fac04a33847862ab7bfb19145f6f91207be6 (diff) | |
download | ydb-296627beeba9eb1fbc3cc1ff3dbae3ff192fb2a8.tar.gz |
Restoring authorship annotation for <shakurov@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/yt/misc/variant.h')
-rw-r--r-- | library/cpp/yt/misc/variant.h | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/library/cpp/yt/misc/variant.h b/library/cpp/yt/misc/variant.h index d5bacda74c8..27c0a2bc086 100644 --- a/library/cpp/yt/misc/variant.h +++ b/library/cpp/yt/misc/variant.h @@ -36,39 +36,39 @@ TString ToString(const std::variant<Ts...>& variant); //////////////////////////////////////////////////////////////////////////////// -//! A concise way of creating a functor with an overloaded operator(). -/*! - * Very useful for std::visit-ing variants. For example: - * - * std::visit(TOverloaded{ - * [] (int i) { printf("The variant holds an int: %d!", i); }, - * [] (const std::string& s) { printf("The variant holds a string: '%s'!", s); } - * }, variantVariable); - */ -template<class... Ts> struct TOverloaded : Ts... { using Ts::operator()...; }; -template<class... Ts> TOverloaded(Ts...) -> TOverloaded<Ts...>; - -//////////////////////////////////////////////////////////////////////////////// - -//! An alternative to std::visit that takes its variant argument first. -/*! - * This deprives it of being able to visit a Cartesian product of variants but - * in exchange allows to receive multiple visitor functors. All of operator()s - * these functors have are used to visit the variant after a single unified - * overload resolution. For example: - * - * Visit(variantVariable, - * [] (int i) { printf("The variant holds an int: %d!", i); }, - * [] (const std::string& s) { printf("The variant holds a string: '%s'!", s); }); - */ -template <class T, class... U> -auto Visit(T&& variant, U&&... visitorOverloads) -{ - return std::visit(TOverloaded{std::forward<U>(visitorOverloads)...}, std::forward<T>(variant)); -} - -//////////////////////////////////////////////////////////////////////////////// - +//! A concise way of creating a functor with an overloaded operator(). +/*! + * Very useful for std::visit-ing variants. For example: + * + * std::visit(TOverloaded{ + * [] (int i) { printf("The variant holds an int: %d!", i); }, + * [] (const std::string& s) { printf("The variant holds a string: '%s'!", s); } + * }, variantVariable); + */ +template<class... Ts> struct TOverloaded : Ts... { using Ts::operator()...; }; +template<class... Ts> TOverloaded(Ts...) -> TOverloaded<Ts...>; + +//////////////////////////////////////////////////////////////////////////////// + +//! An alternative to std::visit that takes its variant argument first. +/*! + * This deprives it of being able to visit a Cartesian product of variants but + * in exchange allows to receive multiple visitor functors. All of operator()s + * these functors have are used to visit the variant after a single unified + * overload resolution. For example: + * + * Visit(variantVariable, + * [] (int i) { printf("The variant holds an int: %d!", i); }, + * [] (const std::string& s) { printf("The variant holds a string: '%s'!", s); }); + */ +template <class T, class... U> +auto Visit(T&& variant, U&&... visitorOverloads) +{ + return std::visit(TOverloaded{std::forward<U>(visitorOverloads)...}, std::forward<T>(variant)); +} + +//////////////////////////////////////////////////////////////////////////////// + } // namespace NYT #define VARIANT_INL_H_ |