News for hackers. Stuff that matters.
Re:What's new in C++26 (part 1) by wrasee on Saturday September 07, 2024 @04:19AM (#41472389)
Yes exactly. My hunch is to remember that in `auto [to, ec] = std::to_chars(p, last, 42)` the two names `to` and `ec` are not "real" variables/objects, but names bound to parts of the object returned to by `std::to_chars`. So fundamentally, `std::to_chars` returns a `std::to_chars_result`, that _is_ the return value and what is then contextually converted to bool for evaluation of the condition. It's then some C++17 compiler thing that separately associates the two names `to` and `ec` with the two parts of that returned tuple object.

But I could be wrong, the paper for the feature is linked but I didn't read it (!).

Re:What's new in C++26 (part 1) by quietbritishjim on Saturday September 07, 2024 @07:43AM (#41473333)
> Yes exactly.

Yes exactly, my example would work?

> My hunch is to remember that in `auto [to, ec] = std::to_chars(p, last, 42)` the two names `to` and `ec` are not "real" variables/objects, but ...

Oh so my example wouldn't work after all (because std::string s is a "real" variable/object)?

Re:What's new in C++26 (part 1) by protomolecule on Saturday September 07, 2024 @09:56AM (#41473968)
Your example wouldn't work, yes.

In case of structured binding

  The decision variable of the declaration is the invented variable e introduced by the declaration.
 
but in your case its simply:

  The decision variable of the declaration is the declared variable.