Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Would this be a good idea?

53 views
Skip to first unread message

Mut...@dastardlyhq.com

unread,
Mar 16, 2023, 5:01:25 AM3/16/23
to
I was looking at some Go code last night and it has don't-care placeholders
in range based loops. So I was wondering if something like this might be
a good idea for C++ 23/26:

vector<tuple<string,string,int>> v;
:
:
for(auto [_,s2,_]: v) do something with s2
or
for(auto &[_,s2,_]: v) ....

or perhaps

for(auto [,s2,]: v) .....

It would only be a small gain in efficiency but might be useful.

Bo Persson

unread,
Mar 16, 2023, 6:38:37 AM3/16/23
to
There is already a proposal for this:

https://wg21.link/p2169

Mut...@dastardlyhq.com

unread,
Mar 16, 2023, 11:32:49 AM3/16/23
to
Excellent, lets hope it happens.

Charlie R

unread,
Mar 29, 2023, 6:13:53 AM3/29/23
to
Thu, 16 Mar 2023 11:38:20 +0100, Bo Persson:
std::lock_guard _(mutex1);
...
std::lock_guard _(mutex2);
...
auto [x, y, _] = f();
auto [a, b, _] = g();

I wonder how debugger should show me this 4 placeholders at end when I
look at local variables. Probably some weird internal names like with
lambdas. Would that even be a problem or what to do there...?

Mut...@dastardlyhq.com

unread,
Mar 29, 2023, 6:25:49 AM3/29/23
to
On Wed, 29 Mar 2023 10:13:39 -0000 (UTC)
Charlie R <charl...@wp.pl> wrote:
>Thu, 16 Mar 2023 11:38:20 +0100, Bo Persson:
>
>> On 2023-03-16 at 10:01, Mut...@dastardlyhq.com wrote:
>>> I was looking at some Go code last night and it has don't-care
>>> placeholders in range based loops. So I was wondering if something like
>>> this might be a good idea for C++ 23/26:
>>>
>>> vector<tuple<string,string,int>> v;
>>> :
>>> :
>>> for(auto [_,s2,_]: v) do something with s2 or for(auto &[_,s2,_]: v)
>>> ....
>>>
>>> or perhaps
>>>
>>> for(auto [,s2,]: v) .....
>>>
>>> It would only be a small gain in efficiency but might be useful.
>>>
>>>
>> There is already a proposal for this:
>>
>> https://wg21.link/p2169
>
>std::lock_guard _(mutex1);
>....
>std::lock_guard _(mutex2);
>....
>auto [x, y, _] = f();
>auto [a, b, _] = g();
>
>I wonder how debugger should show me this 4 placeholders at end when I
>look at local variables. Probably some weird internal names like with
>lambdas. Would that even be a problem or what to do there...?

Perhaps the same way it deals with temporaries now? Whatever that is, I don't
actually know how any of the debuggers represent them.

Bo Persson

unread,
Mar 29, 2023, 7:24:13 AM3/29/23
to
If you want them to have nice names, you are free to insert those names.
Using _ as a name means that you don't care about those objects.


So why care about things we don't care about? :-)


Bonita Montero

unread,
Apr 2, 2023, 1:22:14 PM4/2/23
to
There's no gain in efficiency with that since ignoring parts
of the tuple is only declarative.


0 new messages