mirror of
https://github.com/jslightham/cpp-utils.git
synced 2026-03-09 18:12:26 +01:00
24 lines
525 B
C++
24 lines
525 B
C++
|
|
// Helper to make it easier to use std::visit with std::variant
|
|
// For example,
|
|
// std::visit(
|
|
// overloaded{
|
|
// [](int i) { std::cout << "int: " << i << std::endl; },
|
|
// [](double d) { std::cout << "double: " << d << std::endl; },
|
|
// },
|
|
// variant
|
|
// );
|
|
|
|
#ifndef VARIANT_H
|
|
#define VARIANT_H
|
|
|
|
#include <variant> // NOLINT
|
|
|
|
template <class... Ts> struct overloaded : Ts... {
|
|
using Ts::operator()...;
|
|
};
|
|
|
|
template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
|
|
|
|
#endif // VARIANT_H
|