220 41412 <q2pnql$1mvo$1@blaine.gmane.org> article
Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail
From: David Brown <david@westcontrol.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Overloading `using` for temporary scopes
Date: Tue, 29 Jan 2019 15:26:29 +0100
Approved: news@gmane.org
Message-ID: <q2pnql$1mvo$1@blaine.gmane.org>
References: <41a2bed6-6738-cd11-0037-9a471f8a75d5@gmail.com>
Reply-To: std-proposals@isocpp.org
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226";
	logging-data="57655"; mail-complaints-to="usenet@blaine.gmane.org"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101
 Thunderbird/60.2.1
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDP6R2XHXIARBHOFYHRAKGQES5CRYRQ@isocpp.org Tue Jan 29 15:26:39 2019
Return-path: <std-proposals+bncBDP6R2XHXIARBHOFYHRAKGQES5CRYRQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lj1-f198.google.com ([209.85.208.198])
	by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
	(Exim 4.89)
	(envelope-from <std-proposals+bncBDP6R2XHXIARBHOFYHRAKGQES5CRYRQ@isocpp.org>)
	id 1goULX-000EoF-3T
	for gclcip-std-proposals@m.gmane.org; Tue, 29 Jan 2019 15:26:39 +0100
Original-Received: by mail-lj1-f198.google.com with SMTP id t7-v6sf5928506ljg.9
        for <gclcip-std-proposals@m.gmane.org>; Tue, 29 Jan 2019 06:26:39 -0800 (PST)
ARC-Seal: i=2; a=rsa-sha256; t=1548771998; cv=pass;
        d=google.com; s=arc-20160816;
        b=mvnGJlHn7JRng8/ogSTLho9oIzovKRaX14Ryz+4QDQT2DjM1tqRCEOBuoo3qo4w8j7
         FElJBwH4y2ovLB8ZS2rUKiVRcSIxPHTm+RvufiWtlxx2IUdMDyI8fRF5SjqNi38DA/+j
         p+BnLCYSGAa41UTtVQHoLIVdcrg/XdRznHIxMPDM+KhuQg/zOflTxVm/acfGu7exvnFw
         UA5jZbEy8TaHhwySGdHTr7xXvmfmb6IwSHg5S/m/IOsLOT/Jer8RFxUNTDvb4D8dyW7e
         7pf4UwJnNcbDE9cnfKG15feb16kfPcgcfpzkwuYoEmXqMVzP4fnvM1WyP7/V8tE2H4st
         05Qw==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to:content-language
         :in-reply-to:user-agent:mime-version:references:message-id:date
         :subject:from:to:dkim-signature;
        bh=GRuT9tbjJXtz1ID7X49sdAOP566ID1U8Un25he7PbBc=;
        b=Zd86JrNMhOr3uBCLPuPc2c7CHWJPGsj+5V3NJOa9RgQEbuq+7/3J3ElaTfnpl0ejbr
         ZUb/eqUroC4xyFMJspJXL0aU5ZQ6GUIBrG7TvCdFZQSqEZ9BUYklHIl9MygFat7titEc
         6FJCWjds5ctgi+ym/GCtfXZqqdg4ZsEwMBLRGSUd0LbpK8f8QYLTOiqSl/kymerMiBgA
         BQwPhTeOcIew1krbzN9myXcm4zi7PT8oSIxCyOKI+ngEvvVV8wYSC3iOdxJTEqtXsrgE
         l/hZ/aggO03lHahhNB+iLDQAgOs7A0u89yqwoVjbeQcdUgp642u1Zo8NDI5dE4U0c4Mb
         4e3Q==
ARC-Authentication-Results: i=2; mx.google.com;
       spf=neutral (google.com: 195.159.176.226 is neither permitted nor denied by best guess record for domain of gclcip-std-proposals@m.gmane.org) smtp.mailfrom=gclcip-std-proposals@m.gmane.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=to:from:subject:date:message-id:references:mime-version:user-agent
         :in-reply-to:content-language:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=GRuT9tbjJXtz1ID7X49sdAOP566ID1U8Un25he7PbBc=;
        b=eucU6YSxFKe4dUOAjr2PgIL4hwxbKTx0awCcfI0CAdxTOh+ElTcP3qoyENu/xHnNOk
         5X/BCPSJo77TkN6EkGq7qHsGZVAC9PbztX4de/+zO0XbRu48M2uXOfqmIeyzL7dB71yj
         LQKcmvKAUtqhOAjTIzqB2VMi/M3FMefxngSbq1rmL9hRUN3juhsyp9sG9l3S89nG0nxo
         K/Sat4ezeXDpU6KmAhB8QQUEoEQTXZrw+JJSbqZW2yAO3O3Uu6Nbijfc99QYodZiOSIG
         20ViGeoF0HX3yBa1w4Et4RJWry4HDHMmbe9we/PK5jZJ9aK0iCVozrSNeOJk1i70ihM4
         k3Vw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:to:from:subject:date:message-id:references
         :mime-version:user-agent:in-reply-to:content-language
         :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=GRuT9tbjJXtz1ID7X49sdAOP566ID1U8Un25he7PbBc=;
        b=EFOxuhKVKC/j7+Szihf0KIaKS7+yxKkiF6cRwUWAForm2H0Q++HgIMtUVo5+djbjvM
         iz0W/zmNl+AEfPBx6hBqd4Zn9kDTYolTjF/ht2Yqg22G+ysi9hRyXFsAIgJJAxwvWlJU
         52Co9V2T5fqXLohRL+BCNVX8kEKwlh4c2Od9lly8dftuD6pVGOWglLrNlMzZUxca/bE1
         Au8AiW3uhYeXLbldDLIseyKy2MzM31dSbs0fiuJAi9zDaWZ5WJ7EFSPvXR9hmfNlwIkp
         7SdcXPmI6Hc8687ZYlMNWUsAOWQJ9cic0IuoZ3jNW8YnoS5DcCwyrA8QhVOW0R4dhAb1
         y 
X-Gm-Message-State: AHQUAuYuSnJ96Fl8YNWdKHTFmHPQoFi3SS1OXi0/qLv/805qv/zXRiQ8
	mC7Ula95ArlHWZHFdiKVoKaEyQ==
X-Google-Smtp-Source: AHgI3IbXWXqUBnfBqGHTlOF29cmCxSVrzixAT2xeIqqNE14n2pgY6fYFq90OgdJgnXsiAuMLH3SNLg==
X-Received: by 2002:a19:f60d:: with SMTP id x13mr364445lfe.12.1548771998618;
        Tue, 29 Jan 2019 06:26:38 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:a19:f65:: with SMTP id e98ls1953683lfi.4.gmail; Tue, 29 Jan
 2019 06:26:36 -0800 (PST)
X-Received: by 2002:a19:5510:: with SMTP id n16mr13780068lfe.68.1548771996256;
        Tue, 29 Jan 2019 06:26:36 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1548771996; cv=none;
        d=google.com; s=arc-20160816;
        b=yrFYGnA46sxSIVOO/O9oiY/Ra1B0hsQGEka+YLxNRvzFOBcPmqgnLG3QB+K0lyN4zW
         bPb2GeLXc0lTUIr3q9z2ycHT9CLYiXFYXfjPnCYcQScplW3eZg1v53MZ2IiEi7BBE8TO
         HNzE1M4rtrSZtlxxb7K1oz29xCKxBCHS+FtS66vtGf6HrlhQO+gYOsCn4/CdUwuiaAOf
         F2IEcTp00mcltqvyr74K4ij97GWHFmIiu4D10UvGtYyWWlBRyl+BczpuCyt4rXq49JqY
         vC+J+i/8WYfMNNLMf8q5XUHetVmhvjCjgxigsKsNVoYvDO05XA4jbjwMtU/L9ZVvmas9
         OdNQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=content-language:in-reply-to:user-agent:content-transfer-encoding
         :mime-version:references:message-id:date:subject:from:to;
        bh=u3yvPCoLnYhHVHw0XRNzSh3DnEkgQGFKkUe3y0xivb4=;
        b=R0E2rQHQXXsMKHWj/gR193yYF4uUF4ZXHVFhDOVP9rPFoQHm6KPQgMkcOS5r1noiqg
         trcKena3mPChofrdaMcjHklUjHBGs6t4jKXrDXwtgVAJ6M8OqvmFNldnHkPAYuKmA798
         FqUI/CjFiEclKQKTZ5n67uixoPojnTK22JSf2DtrN8VKUsw3oRS4dk+YaQmFwdSOiZ5Y
         JSobA4yR3yk35pEXquT9yOPduCRR8HONCd8QqaMp0RSCeL/+uIwyRSN0MmYmlfmWrkIB
         tJOJgGpfMCglUjral+lW7qR5G+TY/8axCI9yLGi/ds1U3L2iu0y1bla0Wb6WwgWhfRj4
         id5g==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=neutral (google.com: 195.159.176.226 is neither permitted nor denied by best guess record for domain of gclcip-std-proposals@m.gmane.org) smtp.mailfrom=gclcip-std-proposals@m.gmane.org
Original-Received: from blaine.gmane.org ([195.159.176.226])
        by mx.google.com with ESMTPS id h84si21040858lfl.72.2019.01.29.06.26.36
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
        Tue, 29 Jan 2019 06:26:36 -0800 (PST)
Received-SPF: neutral (google.com: 195.159.176.226 is neither permitted nor denied by best guess record for domain of gclcip-std-proposals@m.gmane.org) client-ip=195.159.176.226;
Original-Received: from list by blaine.gmane.org with local (Exim 4.89)
	(envelope-from <gclcip-std-proposals@m.gmane.org>)
	id 1goULS-000EkF-IW
	for std-proposals@isocpp.org; Tue, 29 Jan 2019 15:26:34 +0100
X-Injected-Via-Gmane: http://gmane.org/
In-Reply-To: <41a2bed6-6738-cd11-0037-9a471f8a75d5@gmail.com>
Content-Language: en-GB
X-Original-Sender: david@westcontrol.com
X-Original-Authentication-Results: mx.google.com;       spf=neutral
 (google.com: 195.159.176.226 is neither permitted nor denied by best guess
 record for domain of gclcip-std-proposals@m.gmane.org) smtp.mailfrom=gclcip-std-proposals@m.gmane.org
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <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:41412
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/41412>

On 28/01/2019 17:20, Matthew Woehlke wrote:
> I often wish C++ had the equivalent of Python's `with`:
> 
>   with (auto x = expr())
>   {
>     // use 'x' here
>   }
>   // 'x' is out of scope
> 
> With C++17 I can more or less achieve this:
> 
>   if (auto x = expr(); true)
>   {
>     // use 'x' here
>   }
>   // 'x' is out of scope
> 
> ...and even:
> 
>   #define with(...) if (__VA_AGS__; true)
> 
> ...but I still have to declare and name the variable, even if I don't
> actually care (e.g. lock guards). While we will hopefully, eventually
> solve the 'anonymous variable' problem, I wonder if there would be any
> perceived value in having a dedicated syntax for this? I'm thinking either:
> 
>   with (auto x = expr())
>   with (expr())
> 
> ...where in the latter case, the result of `expr()` is "live" until the
> end of the `with` scope, e.g. like `if (auto&& ? = expr(); true)`. Or even:
> 
>   using (auto x = expr())
>   using (expr())
> 
> The benefit of the latter, of course, is that it does not need a new
> keyword. The benefit of *either* is that, as a language feature, it
> could be made to work with either an expression or a declaration, which,
> AFAICT, is not possible with any macro-based implementation.
> 
> Does anyone think this would be useful? Or is it not worthwhile given
> the work-arounds that exist?
> 

Basically, what you want is to be able to give "expr()" a name so that
it stays in scope, but you don't want to give it a name because it isn't
something you are going to use.  I don't know of any neat way to do this.

#define anon anon##__counter__

{
	auto anon = expr();
	auto anon = expr2();
	T1 anon;

	// These are all still in scope
}


-- 
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 email 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/q2pnql%241mvo%241%40blaine.gmane.org.

.
