News for hackers. Stuff that matters.
Re:Named tuple for C++ by seivan on Saturday January 02, 2016 @03:33PM (#10827775)
Can you create a named struct on the fly? Don't you have to define struct before?

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.

Re:Named tuple for C++ by mgraczyk on Saturday January 02, 2016 @04:11PM (#10827968)
You can do this in C++ 14.

   auto f() -> decltype(auto) {
     ...
     return (struct {
       int firstPlayer;
       int secondPlayer;
     }) {localPlayer, connectedPlayer};
   }
Re:Named tuple for C++ by temac on Saturday January 02, 2016 @03:46PM (#10827858)
Why would you want to create a named tuple by invoking convoluted code (and arguable with the end result being also not trivial to use) instead of just declaring a structure?

This article is interesting to explore the technical capabilities of modern C++, but not to use the result...

Re:Named tuple for C++ by seivan on Sunday January 03, 2016 @09:23AM (#10830685)
Because I don't know what I want until I want it. I do a similar Tuple a couple of times I know I am going to need a container class/struct to avoid rewriting the same Tuple over and over again and it would also make things clearer as I know got a class/struct for that particular use case.

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.

Re:Named tuple for C++ by bpicolo on Saturday January 02, 2016 @03:54PM (#10827896)
Lightweight, low-overhead to use, iterable, self-documenting object
Re:Named tuple for C++ by temac on Saturday January 02, 2016 @07:26PM (#10828791)
Given the implementation, there is nothing lightweight and low-overhead to use at build time, and at runtime how exactly is this lighter than a struct? As for self-documenting, I don't even know what it would mean here.

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?)