Vicente J. Botet Escriba
unread,Nov 13, 2012, 4:46:58 PM11/13/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to std-pr...@isocpp.org
Hi,
Quite often we need to name a guard variable which is not used other
than in the declaration to do some action on the destruction (raii), e.g.
{
std::lock_guard<std::mutex> guard(mtx);
// ...
}
Giving a name to these guard variables doesn't adds value to the
expression, and some of us use to name them '_'
{
std::lock_guard<std::mutex> _(mtx);
// ...
}
Of course we can not include two of them on the same scope without using
a more specific name as the name conflict.
{
std::lock_guard<std::mutex> g1(mtx1);
std::lock_guard<std::mutex> g2(mtx2);
// ...
}
Do you think it could be worth adding some kind of anonymous variable
that avoid having to name these kind of variables? E.g.we could use the
token '...'
{
std::lock_guard<std::mutex> ...(mtx1);
std::lock_guard<std::mutex> ...(mtx2);
// ...
}
One of the features of these unnamed variables could be that we can not
do anything with, so maybe the compiler could take advantage in order to
optimize the code.
I recognize that the added value is minor, but I'm sure that you have
already desired to not name these variables.
Best,
Vicente