4 ms·
What part of "first-class" don't you understand?? ETA: std::variant is one of the least ergonomic user interfaces I've ever seen. std::tuple seems great until
by thecodedmessage 3y ago
What part of "first-class" don't you understand??
ETA: std::variant is one of the least ergonomic user interfaces I've ever seen. std::tuple seems great until you realize that most PLs that support tuples just do "(,)"s for them, in creating, binding, and naming the type. C++'s versions are just unacceptable, and structured bindings only help on the binding side.
First-class support for these is important. There's no reason they should be in the standard library rather than built into the language itself, besides historical mistakes.
- nwallin 3y ago> std::tuple seems great until you realize that most PLs that support tuples just do "(,)"s for them, in creating, binding, and naming the type. This C++ code compiles and does what a casual reader would expect it to do: #include <string> #include <tuple> using Foo = std::tuple<int, std::string, float>; Foo foo(int a, const char* b, double c) { return {a,b,c}; } godbolt: https://godbolt.org/z/Koa4zYT99 https://godbolt.org/z/Koa4zYT99 I gotta be honest, this interface is exactly what I would like a tuple API to look like. I want to declare my tuple as a `tuple`, I want to give it a friendly name, and I want to explicitly declare the types in the tuple, and I want to all of that at compile time. This API is exactly the verbosity that I want; I would be unhappy with either more or less boilerplate than this. > First-class support for these is important. Agree to disagree.
- thecodedmessage 3y agoHow do you represent state machines, ASTs, or messages of different types? Sum types are great for those! I assume you don’t use std::variant for that? Have you ever written a tagged union when std::variant was available for clarity? Why the tagging boilerplate?
- nwallin 3y agoI use std::variant for all that. Why are you assuming I don't use them? Sum types are great.