diff options
author | babenko <babenko@yandex-team.ru> | 2022-02-10 16:49:19 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:19 +0300 |
commit | f31097c96270919a1f49360bdaaa69ea4f3fefab (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/yt/misc/variant-inl.h | |
parent | cec37806d8847aa3db53bafc9e251d4aaf325c12 (diff) | |
download | ydb-f31097c96270919a1f49360bdaaa69ea4f3fefab.tar.gz |
Restoring authorship annotation for <babenko@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/yt/misc/variant-inl.h')
-rw-r--r-- | library/cpp/yt/misc/variant-inl.h | 136 |
1 files changed, 68 insertions, 68 deletions
diff --git a/library/cpp/yt/misc/variant-inl.h b/library/cpp/yt/misc/variant-inl.h index 73d302eece..fb7d98d4be 100644 --- a/library/cpp/yt/misc/variant-inl.h +++ b/library/cpp/yt/misc/variant-inl.h @@ -1,70 +1,70 @@ -#ifndef VARIANT_INL_H_ -#error "Direct inclusion of this file is not allowed, include variant.h" +#ifndef VARIANT_INL_H_ +#error "Direct inclusion of this file is not allowed, include variant.h" // For the sake of sane code completion. #include "variant.h" -#endif - -#include <type_traits> - -namespace NYT { - -//////////////////////////////////////////////////////////////////////////////// - -namespace NDetail { - -template <class T> -struct TIndexOf<T> -{ - static constexpr size_t Value = std::numeric_limits<size_t>::max(); -}; - -template <class T, class T0, class... Ts> -struct TIndexOf<T, T0, Ts...> -{ - static constexpr size_t Value = std::is_same_v<T, T0> - ? 0 - : 1 + TIndexOf<T, Ts...>::Value; -}; - -template <size_t Index, class... Ts> -struct TVariantFormatter; - -template <size_t Index> -struct TVariantFormatter<Index> -{ - template <class TVariant> - static void Do(TStringBuilderBase* /*builder*/, const TVariant& /*variant*/, TStringBuf /*spec*/) - { } -}; - -template <size_t Index, class T, class... Ts> -struct TVariantFormatter<Index, T, Ts...> -{ - template <class TVariant> - static void Do(TStringBuilderBase* builder, const TVariant& variant, TStringBuf spec) - { - if (variant.index() == Index) { - FormatValue(builder, std::get<Index>(variant), spec); - } else { - TVariantFormatter<Index + 1, Ts...>::Do(builder, variant, spec); - } - } -}; - -} // namespace NDetail - -template <class... Ts> -void FormatValue(TStringBuilderBase* builder, const std::variant<Ts...>& variant, TStringBuf spec) -{ - NDetail::TVariantFormatter<0, Ts...>::Do(builder, variant, spec); -} - -template <class... Ts> -TString ToString(const std::variant<Ts...>& variant) -{ - return ToStringViaBuilder(variant); -} - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT +#endif + +#include <type_traits> + +namespace NYT { + +//////////////////////////////////////////////////////////////////////////////// + +namespace NDetail { + +template <class T> +struct TIndexOf<T> +{ + static constexpr size_t Value = std::numeric_limits<size_t>::max(); +}; + +template <class T, class T0, class... Ts> +struct TIndexOf<T, T0, Ts...> +{ + static constexpr size_t Value = std::is_same_v<T, T0> + ? 0 + : 1 + TIndexOf<T, Ts...>::Value; +}; + +template <size_t Index, class... Ts> +struct TVariantFormatter; + +template <size_t Index> +struct TVariantFormatter<Index> +{ + template <class TVariant> + static void Do(TStringBuilderBase* /*builder*/, const TVariant& /*variant*/, TStringBuf /*spec*/) + { } +}; + +template <size_t Index, class T, class... Ts> +struct TVariantFormatter<Index, T, Ts...> +{ + template <class TVariant> + static void Do(TStringBuilderBase* builder, const TVariant& variant, TStringBuf spec) + { + if (variant.index() == Index) { + FormatValue(builder, std::get<Index>(variant), spec); + } else { + TVariantFormatter<Index + 1, Ts...>::Do(builder, variant, spec); + } + } +}; + +} // namespace NDetail + +template <class... Ts> +void FormatValue(TStringBuilderBase* builder, const std::variant<Ts...>& variant, TStringBuf spec) +{ + NDetail::TVariantFormatter<0, Ts...>::Do(builder, variant, spec); +} + +template <class... Ts> +TString ToString(const std::variant<Ts...>& variant) +{ + return ToStringViaBuilder(variant); +} + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT |