Hacker News new | past | comments | ask | show | jobs | submit login

I have used it c++ to take a scoped lock without naming it and returning a mutex protected value:

   return scoped_lock{foo_mux_}, return foo_;
Also nobody likes it.



Deosn't such an unnamed variable get's immediately destructed, right at the comma? I am pretty certain I'd hit exactly that problem and had to switch to __LINE__-macro to name such scoped locks.


My understanding of the standard is that the `full-expression` ends at the semicolon and 6.7.7.8 prescribes that the temporary shall be destructed after copying the value to be returned.


I think you mean:

    return scoped_lock{foo_mux_}, foo_;


Indeed! :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: