News for hackers. Stuff that matters.
Re:C++17 is formally approved by zelos on Thursday September 07, 2017 @07:07AM (#15190662)
There are some nice things in there, but the destructuring looks a bit odd:

  struct S { int x1 : 2; volatile double y1; };
  S f();
  const auto [ x, y ] = f();
So it's just ordering based, I can't pull out one member by name?
Re:C++17 is formally approved by m-ou-se on Thursday September 07, 2017 @07:54AM (#15190939)
C++ already had syntax for pulling out one member by name: ;)

    const auto x = f().x1;
Re:C++17 is formally approved by faitswulff on Thursday September 07, 2017 @09:19AM (#15191522)
I'm not sure what the wink means, but I think gp might be talking about destructuring like what you'd find in Javascript:

  > const {a, b} = {a: 'hey', b: 'there'}
  undefined
  > a
  'hey'
  > b
  'there'
Re:C++17 is formally approved by 21 on Thursday September 07, 2017 @11:13AM (#15192576)
It's yet another feature stolen from Python.

Next version maybe they will even allow stuff like

  [x, [y, z]] = f()
or

  [x, y, z...] = f()
Re:C++17 is formally approved by ska on Thursday September 07, 2017 @12:11PM (#15193142)
These ideas are a lot older than python, about as old as multiple return values.
Re:C++17 is formally approved by nly on Thursday September 07, 2017 @07:30PM (#15196722)
C++ has tuple<> for this.
Re:C++17 is formally approved by jcelerier on Thursday September 07, 2017 @10:37AM (#15192218)
it has to work with unnamed tuples:

const auto [ x, y ] = make_tuple(1, 23);

Re:C++17 is formally approved by dvlsg on Thursday September 07, 2017 @11:05AM (#15192493)
Tuples are ordered though. I don't usually think of structs by the order the properties are declared - I usually think of them by name.

I am, admittedly, not primarily a c++ dev though. Are structs typically ordered data structures in c++?

Re:C++17 is formally approved by nly on Thursday September 07, 2017 @07:32PM (#15196736)
> I don't usually think of structs by the order the properties are declared

In C++ you have to, since it's guaranteed by the language that members are initialized in order of declaration (within the struct). And, like C of course, it also determines memory layout, padding and alignment

> Are structs typically ordered data structures in c++

Yes, and compilers like Clang even let you inspect their memory layout

Re:C++17 is formally approved by jcelerier on Thursday September 07, 2017 @02:32PM (#15194543)
> Tuples are ordered though. I don't usually think of structs by the order the properties are declared - I usually think of them by name.

Think for instance of a 2D point structure. There are tons of implementations, all with different naming conventions ; or sometimes storing them in an array. This allows to just do :

    auto [x, y] = someRandomLibraryPoint();
Re:C++17 is formally approved by 21 on Thursday September 07, 2017 @11:16AM (#15192598)
There is no struct here.

x will be an independent variable which will take the first value from the tuple, and y the second one.

Re:C++17 is formally approved by euyyn on Thursday September 07, 2017 @12:26PM (#15193311)
His point is that it makes sense to destructure in order for tuples, but what makes sense for structs is destructuring by field name.