What if You by mistake switch ‘GPA’ and ‘grade’ inside your function? Nothing will happen to inform You that something went wrong.
I don't know if there's a specific name for it, but "what if you did X" arguments like this fail to convince me.
At work we use kind of a hybrid approach. We have generator macros that spit out named tuple classes that use a bunch of magic and template meta-programming.
It should go without saying that the macro implementation is ugly and only a few people understand it very well, but we don't have to change them much any more, and the resulting named tuples are easy to use and generally work exactly as expected.
That said, most everyone who's looked at the problem has ended up going with macros instead. :-)
return (firstPlayer:localPlayer, secondPlayer:connectedPlayer).
You'd have to create the struct before you can use it? Tuples allows usage a couple of times before you'd define a struct/class.
This article is interesting to explore the technical capabilities of modern C++, but not to use the result...
Remains "iterable". Given how modern compiler works, I'm still convinced you should convert plain tuples back and to a struct for source code simplicity and build time speed -- because it won't even do extra copies in most cases (and even if it does, who cares?)
Now until I know I need one, it's unnecessary to clutter the namespace with yet another container class/struct.
Named Tuple has a few benefits, that's all. Until they don't.
auto f() -> decltype(auto) {
...
return (struct {
int firstPlayer;
int secondPlayer;
}) {localPlayer, connectedPlayer};
}For example if you have a struct like:
struct data {
double w;
double x;
double y;
double z;
};
You can then create a struct of that type using syntax like: struct data d = {.w = 1.0, .x = 1.0, .y = 1.0, .z = 1.0};
Then you could have your functions take a struct data as a parameter, and use designated initializers to have syntax for keyword parameters.I'm not sure why this feature never made its way into a C++ standard over the years.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p010...
Just don't use it to replace structs, it doesn't make sense.