Stopped reading here. std::variant and std::tuple.
Stopped reading here. std::variant and std::tuple.
Edit: It's really important to read criticisms of your favorite language. Often, it can help you find a better language for the task you're trying to accomplish.
When people talk about first-class support for tuples, std::tuple does not fit that bill.
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.
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/Koa4zYT99I 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.
Why are you assuming I don't use them? Sum types are great.