logoalt Hacker News

repelsteeltjeyesterday at 6:41 PM2 repliesview on HN

Not sure, but I think C++ actually does allow std::variant with multiple choices using the same type. You might not be able to distinguish between them by type (using get<Type>()), but you can by position (get<0>(), get<1>(), ...)


Replies

amlutoyesterday at 8:15 PM

I haven’t tried this, and I don’t intend to, because visitors and similar won’t work (how could they?) and I don’t want to have to think about which is choice 2 and which is choice 7.

NooneAtAll3yesterday at 7:38 PM

I think GP is talking about name-of-field access, not index access or name-of-type