|
|
|
|
|
by junon
2048 days ago
|
|
You cannot trivially compare or move an array. Note that `std::array` is still allowed in `std::variant` - just not C-style arrays. As for references, you cannot re-bind references. Rationale here: https://stackoverflow.com/a/27037871/510036 As for void, apparently the reasons I had in my head are not the reasons in real life. I thought it might be because of a destructible requirement on the type, but it turns out there really isn't a good reason why they disallowed it, and that a future standard might allow it. In any event, there are a multitude of variant implementations that allow all sorts of things depending on the behavior you want. Nothing is forcing you to use the standard library. |
|
I just wonder why it is hard to make a variant-type that works with everything. Well, if the language prevents e.g. reference rebinding, there can't be done much.
But not being able to put _anything_ into a variant severely limits the way it can be used for abstraction. Especially for library authors, because they might not no what their users will pass them. So when they write a generic method, that uses variants under the hood, they would have to "pass down" the restrictions to the user and tell them not to pass e.g. void. Same for the interaction of two libraries.
Or am I misunderstanding the constraints here?