#include <iostream>
#include <variant>
using MyVariant = std::variant<int, double, std::string>;
void AcceptAnyType(const MyVariant& x) {
std::visit([](auto&& val) {
std::cout << "Value is: " << val << '\n';
}, x);
}
int main() {
AcceptAnyType(9001);
AcceptAnyType(3.14);
AcceptAnyType('a');
AcceptAnyType("XYZ");
AcceptAnyType(std::string("ABCD"));
AcceptAnyType(true);
}
/*
run:
Value is: 9001
Value is: 3.14
Value is: 97
Value is: XYZ
Value is: ABCD
Value is: 1
*/