News for hackers. Stuff that matters.
Re:Named tuple for C++ by userbinator on Saturday January 02, 2016 @09:44PM (#10829259)
Indeed, a structure is a named tuple. I think there's a subset of C++ users who pride themselves on creating massively complex solutions, as if they're trying to use as much of the features of the language as they can, instead of going for the simple, straightforward solution. AFAIK std::tuple does compile into the same code as if you declared a struct yourself, but I'd like to see what this convoluted solution compiles to... if I'm reading it correctly, this turns into an O(n) structure member access!?

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.

Re:Named tuple for C++ by tcbawo on Saturday January 02, 2016 @11:15PM (#10829464)
That variadic expansion happens at compile time, so it's still O(1) access. In my experience, the effects of something like this won't be immediately visible. You might start to notice compile times creeping up as the project grows. YMMV.
Re:Named tuple for C++ by KayEss on Sunday January 03, 2016 @12:48AM (#10829684)
This does seem a bit crazy, but it's worth remembering that the named tuple is copied from Python. Although I suppose the excuse there is a lack of structs.
Re:Named tuple for C++ by scriptdevil on Saturday January 02, 2016 @10:55PM (#10829429)
Does O(n) even matter when you only store a small number of elmeents in the tuple anyway?