3 ms·
C++17 added std::variant (https://en.cppreference.com/w/cpp/utility/variant https://en.cppreference.com/w/cpp/utility/variant) and other types so algebraic data
by gsliepen 5y ago
C++17 added std::variant (https://en.cppreference.com/w/cpp/utility/variant https://en.cppreference.com/w/cpp/utility/variant) and other types so algebraic data types are now officially part of the standard. Of course, it's not as compact to write as in Pyret, especially since there's no pattern matching switch statement (yet).
- mlazos 5y agothey do have the godforsaken visit function which requires you to write the lambda syntax for each variant type, I end up writing chained if’s 99% of the time because it’s clearer.
- chakkepolja 5y agoThere's another way using switch if I recall properly. That said I don't like C++'s library additions just to stay modern. They are not expressive, increase build times, make debug builds slower and can fail compiler optimizers.