3 ms·
> How would you do that without making the visitor cases explicit? See my edit. std::visit([](auto &&val) { std::cout << typeIdxToString[typeid(v
by clishem 9y ago
> How would you do that without making the visitor cases explicit?
See my edit.
std::visit([](auto &&val) {
std::cout << typeIdxToString[typeid(val)] << val;
}, var);
> E.g. you would want the '+' operator to do different things for strings and numbers.
Then overload the '+' operator, no need to put all that in the visitor lambda.
- any1 9y agoYes, this would work. I can see that variant may prove useful for the case that you present, but it is much less elegant for the usecase which the author tries to present. Edit: Replaced second "useful" with "elegant"