3 ms·
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 arg
by GreaterFool 11y ago
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.
- tbirdz 11y agoThis 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.
- J_Darnley 11y agoDon't forget that you can also have functions return a struct.
- petke 11y agoI'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/p0109r0.pdf http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p010...