C++17 has granted us with std::variant. Simply put, it is a type-safe union. To access the value it stores, you can either request a specific type ...
For further actions, you may consider blocking this person and/or reporting abuse
It would be nice to mention why we changed () to {} when we switched to deduction guide. E.g. if you add constructor
then you can use () again. At least I was curious about this.
I did mention that we need to use aggregate initialization. Though I now think my reasoning for it is wrong. Also - I never tried making it work with ().
This also works without deduction guide:
I'm confused with this part:
The braces indicate a constructor call, but there is none. There is a non-member helper template though, but it has no body. So, what's happening here?
It's not a non-member helper template, it's a user defined deduction guide. See this article:
arne-mertz.de/2017/06/class-templa...
It works also without deduction guide and the 'using' fix is for g++. 'operator()' cannot be ambiguous in visitors but gcc is very careful with overloading derived functions. In clang we can easily have the same results with minimal code (checked output assembler with Compiler Explorer):
There is needed aggregate Initialisation + variadic templates.
Very cool code transformations. :) Thank you.
Excellent brake-down, ta!
You don't need
using Ts::operator()...;
That's just... weird...
PS: (...) this in the comment is not fold expression
What's weird?
Where the standard is going to :) nevertheless the implementation is cool!
(2) and (3) in second code snippet are mixed up.
Fixed. Thank you!