variant.h 618 B

123456789101112131415161718
  1. #pragma once
  2. #include <variant>
  3. namespace NUnifiedAgent {
  4. template<class... Ts> struct TOverloaded : Ts... { using Ts::operator()...; };
  5. template<class... Ts> TOverloaded(Ts...) -> TOverloaded<Ts...>;
  6. template <class T, class... U>
  7. auto Visit(T&& variant, U&&... visitorOverloads) {
  8. return std::visit(TOverloaded{std::forward<U>(visitorOverloads)...}, std::forward<T>(variant));
  9. }
  10. template <typename TTarget, typename... TSourceTypes>
  11. auto CastTo(std::variant<TSourceTypes...>&& variant) {
  12. return Visit(variant, [](auto& p) -> TTarget { return std::move(p); });
  13. }
  14. }