Hacker News new | ask | show | jobs
by wrasee 652 days ago
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 (!).

1 comments

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

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.