Re:Named tuple for C++
by GreaterFool on Saturday January 02, 2016 @05:05PM
(#10828220)
One great use of named tuples would be named function arguments. I've grown tired of seeing functions that take a bunch of doubles and always checking which argument is which.
[ Parent
| on HN ]
This would be a case where C99 style designated initializers would come in handy in C++.
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.
Don't forget that you can also have functions return a struct.
I'd rather have something like Strong Typdef for that. Maybe we will get it eventually.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p010...