Re:Const all the things?
by PaulDavisThe1st on Monday January 24, 2022 @01:48PM
(#30062062)
For C++17, true. Not so if you're using an earlier compiler and/or language standard. Yes, yes, I know we should all get with the program, but that's alas not how the world operates.
[ Parent
| on HN ]
There is no std::optional in earlier language standards. std::optional is a C++17 library feature.
Re:Const all the things?
by tsimionescu on Monday January 24, 2022 @02:46PM
(#30062922)
Even for C++ 17, this is only guaranteed if you don't name the variable in your function. NRVO is not guaranteed at all. There is even an example downthread where gcc can't do it even at -O3.
Re:Const all the things?
by PaulDavisThe1st on Monday January 24, 2022 @02:04PM
(#30062298)
boost::optional has existed for many, many years and does not require compiler/language support. AFAIK, the behavior is substantially identical to std::optional.