Is the discussion about `auto _ = f()` actually done?
Just asking since I still think it's a bad idea to allow that as
a short form to ignore return values for functions marked as
[[nodiscard]]
P2169 has been actively discussed (yesterday & today, literally minutes ago) and bouncing back & forth between EWG(evolution) & CWG(core) adjusting the usage under special cases. Things are looking good. It is potentially likely (no guarantees) that _ (an underscore) will be an unnamed placeholder in C++26 usable in many/most places you would normally have an identifier including structured bindings.
Chiris++;
On Sat, Jun 10, 2023 at 5:34 PM Sebastian Wittmeier via Std-Proposals <std-proposals@lists.isocpp.org> wrote:
--See P2169 A Nice Placeholder With No Name
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2169r3.pdf
https://github.com/cplusplus/papers/issues/878
-----Ursprüngliche Nachricht-----
Von: Frederick Virchanza Gotham via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Sa 10.06.2023 16:27
Betreff: [std-proposals] Dummy names for dummy objects
An: std-proposals <std-proposals@lists.isocpp.org>;
CC: Frederick Virchanza Gotham <cauldwell.thomas@gmail.com>;
Sometimes I have code like this:
void Func(void)
{
OnScopeExit dummy( [](){ ::close(global_fd); } );
// Do more stuff here
}
If I later amend this function so that further down there's another
'OnScopeExit', then I have to name the second one "dummy1", and the
third one "dummy2" and so on.
For the sake of making it easier to patch source files, I propose that
we can give an object a dummy name as follows:
void Func(void)
{
OnScopeExit __dummy( [](){ /* Do Something */ } );
// Do more stuff here
OnScopeExit __dummy( [](){ /* Do Something */ } );
// Do more stuff here
OnScopeExit __dummy( [](){ /* Do Something */ } );
}
These objects don't have a name clash. If you try to access an object
by the name '__dummy', it accesses the most recently defined dummy
object:
void Func(void)
{
OnScopeExit __dummy( [](){ /* Do Something */ } );
// Do more stuff here
_dummy.SomeMethod(); // refers to the object defined 3 lines above
OnScopeExit __dummy( [](){ /* Do Something */ } );
// Do more stuff here
_dummy.SomeMethod(); // refers to the object defined 3 lines above
OnScopeExit __dummy( [](){ /* Do Something */ } );
}
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals