3 ms·
>There are so many features I miss from Rust, not only the obvious safety features, or even primarily those, but also features that C++ could easily add, like s
by meindnoch 3y ago
>There are so many features I miss from Rust, not only the obvious safety features, or even primarily those, but also features that C++ could easily add, like sum types (called enums in Rust), or first-class support for tuples.
Stopped reading here. std::variant and std::tuple.
- jprete 3y agostd::variant is really cumbersome to use. When people talk about first-class support for tuples, std::tuple does not fit that bill.
- gwbas1c 3y ago> It can be done, but the calls to std::tie and std::make_tuple are long-winded and distracting 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.
- mempko 3y agoYou don't need to use tie and make_tuple. Another person posted a nice example.
- thecodedmessage 3y agoWhat 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.