220 21169 <mum4tp$j5r$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: P0007R0: Constant View: A proposal for a
 std::as_const helper function template
Date: Fri, 02 Oct 2015 10:38:48 -0400
Lines: 43
Approved: news@gmane.org
Message-ID: <mum4tp$j5r$1@ger.gmane.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
X-Trace: ger.gmane.org 1443796764 20020 80.91.229.3 (2 Oct 2015 14:39:24 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 2 Oct 2015 14:39:24 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBC37LBFWUIFBBDNOXKYAKGQEM5HT53Q@isocpp.org Fri Oct 02 16:39:12 2015
Return-path: <std-proposals+bncBC37LBFWUIFBBDNOXKYAKGQEM5HT53Q@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lb0-f197.google.com ([209.85.217.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBC37LBFWUIFBBDNOXKYAKGQEM5HT53Q@isocpp.org>)
	id 1Zi1UM-0002XA-Nt
	for gclcip-std-proposals@m.gmane.org; Fri, 02 Oct 2015 16:39:10 +0200
Original-Received: by lbcao8 with SMTP id ao8sf17250965lbc.1
        for <gclcip-std-proposals@m.gmane.org>; Fri, 02 Oct 2015 07:39:10 -0700 (PDT)
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
         :mime-version:content-type:user-agent: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=ZQ2GoJyv/YpF5myLa2b7l9YFXPscrxKG9+iEnignqts=;
        b=Vde89Uz0hsgCpnHMOZ6ikOYzOftvnH0JFR6buW8uhtS++NI3yT+NH3TsPza4j9Pypp
         mxB6umsf8rlc2VKA0yOB1auvMRqyUEEjgNMyh5J0QWwne8+9YnRcYpzhnf5X7Q0EsVWQ
         cexALvAXotLaT3DdAyNB8xR/oag0ZKf/TxODHcTMTd4ik7pLX/vN7K7XL2ROclVKp3aE
         DTlVEGL7s0FDKvUKD5OxhuA4Tve0Cuyd2Sq1wmp/7Pp79DAgOH6i14GeGJiGEGzqF3yF
         fxxszqzFljQ6maiw8J2zi13/U8Y5JuiptV0fQSslglO74pdgoelEzJRsSedhUMHKIcvO
         xDsQ==
X-Gm-Message-State: ALoCoQkzI5IJGXywAN1aBen2oenLtzF1VQlFXvE/wkUd7eiYNQYTnkr9DveekWprZANWirDUbfd1
X-Received: by 10.180.149.210 with SMTP id uc18mr1032419wib.4.1443796750390;
        Fri, 02 Oct 2015 07:39:10 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.25.156.78 with SMTP id f75ls236655lfe.69.gmail; Fri, 02 Oct
 2015 07:39:09 -0700 (PDT)
X-Received: by 10.112.147.232 with SMTP id tn8mr3844053lbb.84.1443796749120;
        Fri, 02 Oct 2015 07:39:09 -0700 (PDT)
Original-Received: from plane.gmane.org (plane.gmane.org. [80.91.229.3])
        by mx.google.com with ESMTPS id m125si6438442lfm.71.2015.10.02.07.39.09
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=RC4-SHA bits=128/128);
        Fri, 02 Oct 2015 07:39:09 -0700 (PDT)
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 1Zi1UI-0002S9-Fz
	for std-proposals@isocpp.org; Fri, 02 Oct 2015 16:39:06 +0200
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>; Fri, 02 Oct 2015 16:39:06 +0200
Original-Received: from mwoehlke.floss by tripoint.kitware.com with local (Gmexim 0.1 (Debian))
        id 1AlnuQ-0007hv-00
        for <std-proposals@isocpp.org>; Fri, 02 Oct 2015 16:39:06 +0200
X-Injected-Via-Gmane: http://gmane.org/
Original-Lines: 34
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
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: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://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>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:21169
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/21169>

(http://open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0007r0.html)

I like the general idea here, but looking at the Further Discussion
section, I see it appears that the lifetime issues have not been solved.
That being the case, I don't think that the relative advantages and
disadvantages are entirely accurate. In fact, I consider the proposed
implementation to be irresponsibly dangerous, as it accepts an rvalue
but allows the same to be destroyed before it can be used. The assertion
that it can be backported is at any rate dubious.

While it's true that we want lifetime extension anyway, the reality is
that std::as_const *also* doesn't work without core language changes,
i.e. as a library-only solution it is incomplete. Moreover, I don't see
that it cannot be made to work at all for an rvalue of a type that is
not {copy,move}able without introducing mandatory copy elision. (The
suggested alternative implementation cannot be used for such case, and
the original as mentioned yields a destroyed object.)

Conversely, 'const <expr>' (or '(const)<expr>', '<expr> const', etc.) is
completely safe and should be much easier to implement, as it has no
effect on lifetime and doesn't require the compiler to do any optimizing
/ lifetime gymnastics, but merely modify the state of the AST. (The
"looks like a C-style cast" drawback also applies only to one specific
form, and likely not the one that would be preferred.)

Considering that my primary use case for such a feature is the RHS of a
range-based for, which may well be a rvalue, I feel that the rationale
for a library-only solution is problematic and the claim that a proper
language solution has only "marginal gain" is incorrect. The benefit of
a langauge-based solution is that it *would actually work*, which IMHO
makes it far superior.

-- 
Matthew

-- 

--- 
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.
