(no title)
fgkhax | 1 year ago
Then you find out that members of a "variant" are not really variant members but just the individual types that can be assigned to a union. For example, assigning to a non-const reference does not work (and obviously cannot work once you realize that std::variant is just syntax sugar over a tagged union).
Most of these new additions since C++11 are just leaky abstractions and wrappers.
gpderetta|1 year ago
It would be easy to make it work, there isn't necessarily a strict relation between the template parameter and the actual stored object. Not having reference variant members was a conscious decision, same as optional<T&>. Hopefully this will be fixed in the future.
nly|1 year ago
I personally would have liked to see recursive variant types and multi-visitation (as supported by boost::variant).
tlhand|1 year ago
The same in C++, using assignment to a pointer to avoid the lvalue ref error that is irrelevant to this discussion:
As stated above, this obviously cannot work since C++ has no way of specifying a myint constructor that -- like in OCaml -- automatically produces the variant type foo.C++ would need true algebraic data types with compiler support (that would hopefully be as fast as switch statements). To be useful, they would need a nice syntax and not some hypothetical abomination like:
amluto|1 year ago
galkk|1 year ago
https://schneide.blog/2018/01/11/c17-the-two-line-visitor-ex...
variants are a such disappointment at every step of trying to use them