C++17 std::variant causing compilation errors when used with custom types and std::visit
I'm dealing with I'm trying to use `std::variant` in C++17 to hold either a `std::string` or a user-defined type, but I'm running into compilation errors when I try to use `std::visit` with it. Hereโs a simplified version of my code: ```cpp #include <iostream> #include <variant> #include <string> struct MyType { int id; MyType(int id) : id(id) {} }; using MyVariant = std::variant<std::string, MyType>; void processVariant(MyVariant v) { std::visit([](auto&& arg) { std::cout << arg << '\n'; }, v); } int main() { MyVariant v1 = std::string("Hello"); MyVariant v2 = MyType(42); processVariant(v1); processVariant(v2); return 0; } ``` When I try to compile this, I get an behavior: ``` behavior: no matching function for call to โstd::visit(...)โ ``` I suspect that the scenario is related to how I'm trying to print `MyType` inside the lambda function. However, Iโve also tried to add a `std::ostream& operator<<` overload for `MyType`, but the scenario continues. Hereโs what I added: ```cpp std::ostream& operator<<(std::ostream& os, const MyType& myType) { os << "MyType with id: " << myType.id; return os; } ``` Even after adding this overload, the compilation behavior remains. I've double-checked that the `operator<<` function is in the same namespace and accessible. What am I missing here? Is there a specific rule about accessing custom types with `std::visit`? Any help would be appreciated! Could someone point me to the right documentation? Is this even possible?