Guest User

Untitled

a guest
Aug 6th, 2020
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. template<typename Variant, typename ... F>
  2. constexpr auto match(Variant&& v, F&& ... f)
  3. noexcept(noexcept(std::visit(overloaded{ std::forward<decltype(f)>(f)... },
  4.                              std::forward<decltype(v)>(v))))
  5. {
  6.     return std::visit(overloaded{ std::forward<decltype(f)>(f)... },
  7.                       std::forward<decltype(v)>(v));
  8. }
  9.  
  10. // ...
  11. std::variant<int, double> variant;
  12. match(
  13.     variant,
  14.     [](int){ /* code */ },
  15.     [](double){ /* code */ }
  16. );
Advertisement
Add Comment
Please, Sign In to add comment