std::variant not matching types correctly in C++17 when used with std::visit
I'm working with an scenario with `std::variant` in C++17 where it doesn't seem to match the correct type when used with `std::visit`. I have a variant that can hold either an `int` or a `std::string`, but it seems that my `visit` function is not being called as expected. Hereβs a simplified version of my code: ```cpp #include <variant> #include <string> #include <iostream> std::variant<int, std::string> myVariant; void processVariant(const std::variant<int, std::string>& v) { std::visit([](auto&& arg) { std::cout << arg << '\n'; }, v); } int main() { myVariant = 42; // Setting to an int processVariant(myVariant); myVariant = "Hello, World!"; // Setting to a string processVariant(myVariant); return 0; } ``` When I run the program, it prints the integer `42` correctly, but when I set it to the string, it gives me an behavior: `behavior: no matching function for call to 'std::visit(...)'`. I suspect that it might be related to how the lambda in `std::visit` is defined, but I haven't been able to figure it out. I've also tried explicitly specifying the types in the lambda like this: ```cpp std::visit([](int arg) { std::cout << arg << '\n'; }, v); std::visit([](std::string arg) { std::cout << arg << '\n'; }, v); ``` but that resulted in a similar behavior. The lambda seems to not be deducing the types correctly based on the variant content. Is there something Iβm missing, maybe an scenario with the way `std::variant` is being used or `std::visit` in this context? Any help would be appreciated!