220 14524 <CADbh+eTp9VGKm1Ux3fGf5S_gRO2XmDw-PD2uoLzJ8qzne1Be-Q@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Brent Friedman <fourthgeek@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Range-based if
Date: Thu, 13 Nov 2014 11:33:35 -0600
Lines: 177
Approved: news@gmane.org
Message-ID: <CADbh+eTp9VGKm1Ux3fGf5S_gRO2XmDw-PD2uoLzJ8qzne1Be-Q@mail.gmail.com>
References: <CADbh+eQCaTPArs7YBUg9mYwrnJ2Gu3SRAfqUbPiLscpyxV8JqQ@mail.gmail.com>
	<m3tvcu$9ia$1@ger.gmane.org>
	<CADbh+eScmZMj4dcQv73re1dM0VNbw_PeHRc_FPWNONoKNKsiMg@mail.gmail.com>
	<c1a0a498-adca-44c7-a9fc-67a979967e6a@isocpp.org>
	<CADbh+eS+nGHpqRBUCbUFGX3+fXWiiCD0C=nvjpAUZDm_=+N2-g@mail.gmail.com>
	<m42ltp$tdn$1@ger.gmane.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=001a113dd29c7f9ce60507c0e93d
X-Trace: ger.gmane.org 1415900027 17147 80.91.229.3 (13 Nov 2014 17:33:47 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 13 Nov 2014 17:33:47 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCHLPXGUXMJBB4GWSORQKGQE7SKLHBQ@isocpp.org Thu Nov 13 18:33:40 2014
Return-path: <std-proposals+bncBCHLPXGUXMJBB4GWSORQKGQE7SKLHBQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ig0-f200.google.com ([209.85.213.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCHLPXGUXMJBB4GWSORQKGQE7SKLHBQ@isocpp.org>)
	id 1XoyH3-0001tt-N3
	for gclcip-std-proposals@m.gmane.org; Thu, 13 Nov 2014 18:33:37 +0100
Original-Received: by mail-ig0-f200.google.com with SMTP id h15sf417860igd.3
        for <gclcip-std-proposals@m.gmane.org>; Thu, 13 Nov 2014 09:33:37 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:in-reply-to:references:date
         :message-id:subject:from:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type;
        bh=LhgY1/oG4csbhXTabyjUOxsntA/xhIcPh9dAOzLl9FI=;
        b=COToh6h37pDDGfFRmuXETJedgzflZ2S+kCewRf7DioLe/YMR3RCYsP4lbVbHd/OaTL
         K8imzd00Tvb/zv6yM5urGcY+DR61D+VzwCurbCahu67k0Ocndve5ISHZW8YuIeBhxrIN
         ev3Oh99bi4PRlb6oLFDQjoDKNRvAIc1pmelT6pI19RVNyXpgYOgWBcBS3lErTGyDnKIo
         TY7GWf+ccCzCwekq/b+DPndiOubE99loKLsh/V8AUMGlrYnojlx980iSkx8gdW3eHEDX
         E77ZeNN6rItv2gR8fQow3piU/0K+ibVINdXEdaXXeMowQe1cogIGjVeoVPqPFBTiMxbN
         Jpeg==
X-Gm-Message-State: ALoCoQnxGBjdx/fZP3Etd2P+PL3Be/5GgmgTfLWhwwhh5FnU6D0LYfsnRbgZf1FSDLDGI6zxHGSu
X-Received: by 10.50.3.97 with SMTP id b1mr296115igb.4.1415900016962;
        Thu, 13 Nov 2014 09:33:36 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.182.233.198 with SMTP id ty6ls1257636obc.76.gmail; Thu, 13 Nov
 2014 09:33:36 -0800 (PST)
X-Received: by 10.202.98.195 with SMTP id w186mr234653oib.104.1415900016314;
        Thu, 13 Nov 2014 09:33:36 -0800 (PST)
Original-Received: from mail-ob0-x22a.google.com (mail-ob0-x22a.google.com. [2607:f8b0:4003:c01::22a])
        by mx.google.com with ESMTPS id l12si30277568oer.70.2014.11.13.09.33.36
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Thu, 13 Nov 2014 09:33:36 -0800 (PST)
Received-SPF: pass (google.com: domain of fourthgeek@gmail.com designates 2607:f8b0:4003:c01::22a as permitted sender) client-ip=2607:f8b0:4003:c01::22a;
Original-Received: by mail-ob0-f170.google.com with SMTP id nt9so12228908obb.29
        for <std-proposals@isocpp.org>; Thu, 13 Nov 2014 09:33:36 -0800 (PST)
X-Received: by 10.202.67.85 with SMTP id q82mr2926071oia.35.1415900016121;
 Thu, 13 Nov 2014 09:33:36 -0800 (PST)
Original-Received: by 10.202.232.77 with HTTP; Thu, 13 Nov 2014 09:33:35 -0800 (PST)
In-Reply-To: <m42ltp$tdn$1@ger.gmane.org>
X-Original-Sender: fourthgeek@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of fourthgeek@gmail.com designates 2607:f8b0:4003:c01::22a as
 permitted sender) smtp.mail=fourthgeek@gmail.com;       dkim=pass
 header.i=@gmail.com;       dmarc=pass (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-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:14524
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/14524>

--001a113dd29c7f9ce60507c0e93d
Content-Type: text/plain; charset=UTF-8

I believe I was misinterpreting your intent. I had interpreted &begin() as
a *begin() typo, not a &*begin() typo. If the intent is to return
pointer-to-dereferenced-value, then that creates a separate issue. If
*begin() returns say int (rather than int&) then that would return
pointer-to-temporary-on-the-stack.

>Brent, that's basically *what I wrote*, except using T* rather than optional<T&>.
Certainly it's the same general idea.
I agree.

On Thu, Nov 13, 2014 at 10:23 AM, Matthew Woehlke <
mw_triad@users.sourceforge.net> wrote:

> On 2014-11-12 21:31, Brent Friedman wrote:
> >> It doesn't assume that the iterators are pointers, if that's what you
> >> mean.
> >
> > It assumes that it is possible to convert from nullptr_t to
> > decltype(&range.begin()).
>
> Oops, yes, there is a '*' missing: 'decltype(&*range.begin())' (or
> std::addressof as Benjamin suggested). This should be obvious
> considering the RHS of the 'return'.
>
> I am confused; I am not returning the iterator. I am returning the
> address of the iterator's value. While I would believe that might not be
> possible in all cases, I don't see how it relates to the cases you are
> concerned about. (Also, my C++11-fu is not that strong; there may be a
> way to return the iterator value as a form of reference that would
> bypass these issues also.)
>
> On 2014-11-12 21:52, Brent Friedman wrote:
> > A function like first_or_null which returns an optional<T&> could
> probably
> > work alright for our purposes with only a bit of extra syntax over this
> > range-if idea.
>
> Brent, that's basically *what I wrote*, except using T* rather than
> optional<T&>. Certainly it's the same general idea.
>
> > It also assumes that this value constructed from nullptr necessarily
> > represents an invalid value (converts to false) for that iterator type.
>
> Huh? The check is on begin == end. No other assumptions are made about
> the behavior of begin except that operator==(end) will return true if
> the range is not valid. Since AFAIUI this is how range-based for also
> works, if this assumption is being violated I'd think you'd have other
> problems...
>
> --
> 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/.
>

-- 

--- 
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/.

--001a113dd29c7f9ce60507c0e93d
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I believe I was misinterpreting your intent. I had interpr=
eted &amp;begin() as a *begin() typo, not a &amp;*begin() typo. If the inte=
nt is to return pointer-to-dereferenced-value, then that creates a separate=
 issue. If *begin() returns say int (rather than int&amp;) then that would =
return pointer-to-temporary-on-the-stack.=C2=A0<div><br></div><div>&gt;<spa=
n style=3D"font-family:arial,sans-serif;font-size:13px">Brent, that&#39;s b=
asically *what I wrote*, except using T* rather than=C2=A0</span><span styl=
e=3D"font-family:arial,sans-serif;font-size:13px">optional&lt;T&amp;&gt;. C=
ertainly it&#39;s the same general idea.</span></div><div><span style=3D"fo=
nt-family:arial,sans-serif;font-size:13px">I agree.</span></div></div><div =
class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Thu, Nov 13, 2014 a=
t 10:23 AM, Matthew Woehlke <span dir=3D"ltr">&lt;<a href=3D"mailto:mw_tria=
d@users.sourceforge.net" target=3D"_blank">mw_triad@users.sourceforge.net</=
a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0=
 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=3D"">On =
2014-11-12 21:31, Brent Friedman wrote:<br>
&gt;&gt; It doesn&#39;t assume that the iterators are pointers, if that&#39=
;s what you<br>
&gt;&gt; mean.<br>
&gt;<br>
&gt; It assumes that it is possible to convert from nullptr_t to<br>
&gt; decltype(&amp;range.begin()).<br>
<br>
</span>Oops, yes, there is a &#39;*&#39; missing: &#39;decltype(&amp;*range=
..begin())&#39; (or<br>
std::addressof as Benjamin suggested). This should be obvious<br>
considering the RHS of the &#39;return&#39;.<br>
<br>
I am confused; I am not returning the iterator. I am returning the<br>
address of the iterator&#39;s value. While I would believe that might not b=
e<br>
possible in all cases, I don&#39;t see how it relates to the cases you are<=
br>
concerned about. (Also, my C++11-fu is not that strong; there may be a<br>
way to return the iterator value as a form of reference that would<br>
bypass these issues also.)<br>
<span class=3D""><br>
On 2014-11-12 21:52, Brent Friedman wrote:<br>
&gt; A function like first_or_null which returns an optional&lt;T&amp;&gt; =
could probably<br>
&gt; work alright for our purposes with only a bit of extra syntax over thi=
s<br>
&gt; range-if idea.<br>
<br>
</span>Brent, that&#39;s basically *what I wrote*, except using T* rather t=
han<br>
optional&lt;T&amp;&gt;. Certainly it&#39;s the same general idea.<br>
<span class=3D""><br>
&gt; It also assumes that this value constructed from nullptr necessarily<b=
r>
&gt; represents an invalid value (converts to false) for that iterator type=
..<br>
<br>
</span>Huh? The check is on begin =3D=3D end. No other assumptions are made=
 about<br>
the behavior of begin except that operator=3D=3D(end) will return true if<b=
r>
the range is not valid. Since AFAIUI this is how range-based for also<br>
works, if this assumption is being violated I&#39;d think you&#39;d have ot=
her<br>
problems...<br>
<span class=3D"HOEnZb"><font color=3D"#888888"><br>
--<br>
Matthew<br>
</font></span><div class=3D"HOEnZb"><div class=3D"h5"><br>
--<br>
<br>
---<br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org">std-propo=
sals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></blockquote></div><br></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--001a113dd29c7f9ce60507c0e93d--

.
