220 24592 <nafi40$lve$1@ger.gmane.org> article
Path: news.gmane.org!not-for-mail
From: Matthew Woehlke <mwoehlke.floss@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: throwaway variable
Date: Mon, 22 Feb 2016 12:56:16 -0500
Lines: 84
Approved: news@gmane.org
Message-ID: <nafi40$lve$1@ger.gmane.org>
References: <9658e852-6254-4ecf-a6d4-879160d4de7d@isocpp.org>	<CAKiZDp0Q9VFSd9ONVDH8hJdhcFQ8daU12yLCSXB69UcRBcMj3Q@mail.gmail.com>	<CAA7YVg1T2WQM5fzckDE5oczmAycJt-cibZ_iYvWp4SzgkGLpQQ@mail.gmail.com>	<naf9ro$36k$2@ger.gmane.org> <CAA7YVg2QppYXRg-zGEnD4+m5yET4fisd0BhXLyGwMaRZgNe6tQ@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: ger.gmane.org 1456163814 23157 80.91.229.3 (22 Feb 2016 17:56:54 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 22 Feb 2016 17:56:54 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBC37LBFWUIFBBU4XVW3AKGQEGBWFTSY@isocpp.org Mon Feb 22 18:56:42 2016
Return-path: <std-proposals+bncBC37LBFWUIFBBU4XVW3AKGQEGBWFTSY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lf0-f69.google.com ([209.85.215.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBC37LBFWUIFBBU4XVW3AKGQEGBWFTSY@isocpp.org>)
	id 1aXuir-0007gF-CE
	for gclcip-std-proposals@m.gmane.org; Mon, 22 Feb 2016 18:56:37 +0100
Original-Received: by mail-lf0-f69.google.com with SMTP id l83sf39234275lfd.0
        for <gclcip-std-proposals@m.gmane.org>; Mon, 22 Feb 2016 09:56:37 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=to:from:subject:date:lines:message-id:references:mime-version
         :content-type:content-transfer-encoding:user-agent:in-reply-to
         :x-original-sender:x-original-authentication-results:reply-to
         :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=jjMaPMRu8X/KloZdUXNA0STVWDujJ1vn23rw1cOqMGo=;
        b=yJbqITvDbmjIopqRQ8tTyFcLba99+xHG7sPod4KdkrDK2ujnt19qKeZtKSlCEEYpWP
         VeUUv0PX52aVic32eOL68u8B401CFoFqAdznYvEdl9WgfDtMiVPPEKpl2noCg2umoU0l
         fSdqE7hYv9hgjYKF+NmKxqmbgXuqATJuAMqmUWcNuSVSt4Y/HsWfHjZJtVDEQjB0A7Er
         ibLajVGO0jmAv9LJ6LzhP/NLpPCz7a68grhG6iP3FFmhxy+QAmm0WSU3n7QjGx2uk6G+
         EzDRVPJyXvVnOMEwi5Py74m7+n1Pmk18TxQHZcpymnvog7lv0amgItR 
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:to:from:subject:date:lines:message-id:references
         :mime-version:content-type:content-transfer-encoding:user-agent
         :in-reply-to:x-original-sender:x-original-authentication-results
         :reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=jjMaPMRu8X/KloZdUXNA0STVWDujJ1vn23rw1cOqMGo=;
        b=Qpw+GjZ4uqKz+16GA3TUs6pLcfoSTF4np9jpUyyecaaMZQRnp4N2kHI9mWmMd0ltCP
         AmmmgCDa6xnW705qbeyyFdaZzhijNXpxkUkzSMfemV99aLDy8xIaT8FYYYEMVf5xNd56
         GqsDwrWA/iNDQyPF8vReicIBtPBqAGlyQbwZpytNuklHvoJZiGOtfjH4ixGjfmWxEBVO
         i5+D2sdlATdZUNtsRgbILXdWJ9HKUHgpZZN4WZ4ApqFdfwXbho38EkPslAQCcZMVhObU
         X0h+n4qsCh7lptXEDhFlpbwZ//lp7nzPmjer1L94nnUnGHuCPTZ 
X-Gm-Message-State: AG10YOTyvrYNcaam/DSSV/pPGCD05jx6QVdsmpgMPjuEK4tfUX0JSk1/PX6MsHhRVz+8dA==
X-Received: by 10.28.47.211 with SMTP id v202mr1361846wmv.3.1456163796751;
        Mon, 22 Feb 2016 09:56:36 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.25.28.76 with SMTP id c73ls379230lfc.71.gmail; Mon, 22 Feb
 2016 09:56:34 -0800 (PST)
X-Received: by 10.112.10.131 with SMTP id i3mr10719138lbb.100.1456163794914;
        Mon, 22 Feb 2016 09:56:34 -0800 (PST)
Original-Received: from plane.gmane.org (plane.gmane.org. [80.91.229.3])
        by mx.google.com with ESMTPS id o9si13895108lfa.135.2016.02.22.09.56.34
        for <std-proposals@isocpp.org>
        (version=TLS1 cipher=AES128-SHA bits=128/128);
        Mon, 22 Feb 2016 09:56:34 -0800 (PST)
Received-SPF: pass (google.com: domain of gclcip-std-proposals@m.gmane.org designates 80.91.229.3 as permitted sender) client-ip=80.91.229.3;
Original-Received: from list by plane.gmane.org with local (Exim 4.69)
	(envelope-from <gclcip-std-proposals@m.gmane.org>)
	id 1aXuim-0007Xw-Kx
	for std-proposals@isocpp.org; Mon, 22 Feb 2016 18:56:32 +0100
Original-Received: from tripoint.kitware.com ([66.194.253.20])
        by main.gmane.org with esmtp (Gmexim 0.1 (Debian))
        id 1AlnuQ-0007hv-00
        for <std-proposals@isocpp.org>; Mon, 22 Feb 2016 18:56:27 +0100
Original-Received: from mwoehlke.floss by tripoint.kitware.com with local (Gmexim 0.1 (Debian))
        id 1AlnuQ-0007hv-00
        for <std-proposals@isocpp.org>; Mon, 22 Feb 2016 18:56:27 +0100
X-Injected-Via-Gmane: http://gmane.org/
Original-Lines: 71
Original-X-Complaints-To: usenet@ger.gmane.org
X-Gmane-NNTP-Posting-Host: tripoint.kitware.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
In-Reply-To: <CAA7YVg2QppYXRg-zGEnD4+m5yET4fisd0BhXLyGwMaRZgNe6tQ@mail.gmail.com>
X-Original-Sender: mwoehlke.floss@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of gclcip-std-proposals@m.gmane.org designates 80.91.229.3 as
 permitted sender) smtp.mailfrom=gclcip-std-proposals@m.gmane.org;
       dmarc=fail (p=NONE dis=NONE) header.from=gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:24592
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/24592>

On 2016-02-22 12:00, Viacheslav Usov wrote:
> On Mon, Feb 22, 2016 at 4:35 PM, Matthew Woehlke wrote:
>> On 2016-02-21 08:55, Viacheslav Usov wrote:
>>> On Fri, Feb 19, 2016 at 9:06 PM, Patrice Roy wrote:
>>>> I often use _ as =C2=ABuninteresting but needed=C2=BB variables such a=
s
>>>> lock_guards. Please don't break my code :)
>>>
>>> I would even say that this case, "uninteresting but needed" is=20
>>> more interesting. It would be nice to have a language construct=20
>>> that creates an "anonymous" variable in the current scope.=20
>>> Alternatively, this could be conceptualized as a temporary whose
>>> lifetime is extended till the end of the current scope.
>>=20
>> Is that not what we're proposing?
>=20
> I am not sure. The discussion definitely started with a very different
> idea, and I do not think I saw a clear statement similar to what I wrote
> above.

I'm not sure I'd call it "different" or not. The OP (who curiously seems
to have dropped out of the conversation) originally only mentioned being
implicitly `[[maybe_unused]]`. Ville immediately brought up
http://cplusplus.github.io/EWG/ewg-active.html#35, which dealt with
"nameless" variables, which seems consistent with the OP's intent as
well as much more useful (though Dmitry brings up the interesting point
that these should be `[[maybe_unused]]`, now that that seems likely to
be in C++17). I've generally read the rest of the thread as referring to
such 'anonymous variables'.

> For the record, I dislike the special names that have been proposed. I
> believe the lifetime-extended temporary approach is more appropriate, so
> this should probably be phrased in a language involving temporaries; say =
if
> <expression> produces a temporary, then &<expression> makes it an anonymo=
us
> variable (and an l-value) in the current scope. The use of & is just an
> example and not essential.

I see at least one issue with that, namely that it doesn't solve the
OP's problem (anonymous variables as loop iterators). Otherwise, I fail
to see a semantic difference between:

  &lock_guard{...}; // life extended until end of scope
  auto&& . =3D lock_guard{...}; // anonymous variable

In both cases, a temporary that would otherwise be immediately destroyed
is lifetime-extended to the end of the scope in which the statement
appears. Said temporary is anonymous and cannot be named (i.e. used
again). The only difference I see=C2=B9 is syntactic.

Do I miss something?

(=C2=B9 Again, ignoring that reuse of declaration syntax means I can do
things with 'auto .' that I can't do with pure lifetime extension.)

Note also I'm not a big fan of changing the meaning of an existing
identifier, even `__`, to be something other than an identifier. That's
why I suggested using `.` instead; the proposed syntax is not (AFAIK)
currently legal, and `.` is definitely not an identifier.



Just for fun... here's how a potential 'do something X times' loop might
look in the future:

  for (.: [0..X))
    do_something();

(And no, this isn't completely theoretical code; it might well appear in
timing tests.)

--=20
Matthew

--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/nafi40%24lve%241%40ger.gmane.org.

.
