220 14493 <706b7c7d-2bc2-4281-b534-848763d0657e@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Bengt Gustafsson <bengt.gustafsson@beamways.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Range-based if
Date: Tue, 11 Nov 2014 14:26:05 -0800 (PST)
Lines: 131
Approved: news@gmane.org
Message-ID: <706b7c7d-2bc2-4281-b534-848763d0657e@isocpp.org>
References: <CADbh+eQCaTPArs7YBUg9mYwrnJ2Gu3SRAfqUbPiLscpyxV8JqQ@mail.gmail.com>
 <m3tvcu$9ia$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="----=_Part_1183_390031277.1415744765776"
X-Trace: ger.gmane.org 1415744797 27693 80.91.229.3 (11 Nov 2014 22:26:37 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 11 Nov 2014 22:26:37 +0000 (UTC)
Cc: mw_triad@users.sourceforge.net
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCRIRSPDTQIRB7UZRKRQKGQEH6BNGQQ@isocpp.org Tue Nov 11 23:26:30 2014
Return-path: <std-proposals+bncBCRIRSPDTQIRB7UZRKRQKGQEH6BNGQQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ig0-f199.google.com ([209.85.213.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCRIRSPDTQIRB7UZRKRQKGQEH6BNGQQ@isocpp.org>)
	id 1XoJt1-0003qn-9a
	for gclcip-std-proposals@m.gmane.org; Tue, 11 Nov 2014 23:26:07 +0100
Original-Received: by mail-ig0-f199.google.com with SMTP id hn18sf9268870igb.2
        for <gclcip-std-proposals@m.gmane.org>; Tue, 11 Nov 2014 14:26:06 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to
         :references:subject:mime-version:x-original-sender:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=KALlt3sPJDc/Iu95SsGfdjBWypqCNpTcaIFA8NPnDgc=;
        b=cjPLwSLuXHuPOb7cyo/E5+TM9xuycDj2cg5ijKNp3qre2TrU2m3i7ddL++51vCIdw/
         iRUW1AgKiu2jqx4p4VLRHWs8HxqSjUKopPnAs2xnK6nCT6jUUqYdOm8FByN3yukmKNcZ
         vvEEbxVGa8cgnCvoAAHL17UlAM4sSrusuwOqnElaikWUiTDHN0fgCjgbYjypVlIImb+3
         UZzTrozKD4oSbRqDJW9CGeVSNFuKQcnjPB7u3ql6xW91rNdaWqmmGtqxwpkaaLg14Lf7
         SxnkZk8QohjTHxdcxqDzOMBIojDoYB/894VntWt3TbC2uTEHXeY1mLDQwrSznVIZ7Ecv
         ecRg==
X-Gm-Message-State: ALoCoQmV3lupu0Fhe1EnzaaiTqb2ludzMKaTjHfmgWH5Cp4zslOMcQmfhB/JIobCX+R1QaZn3JFt
X-Received: by 10.50.111.131 with SMTP id ii3mr27270816igb.6.1415744766650;
        Tue, 11 Nov 2014 14:26:06 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.93.225 with SMTP id d88ls2575704qge.91.gmail; Tue, 11 Nov
 2014 14:26:06 -0800 (PST)
X-Received: by 10.140.101.227 with SMTP id u90mr60106qge.18.1415744765962;
        Tue, 11 Nov 2014 14:26:05 -0800 (PST)
In-Reply-To: <m3tvcu$9ia$1@ger.gmane.org>
X-Original-Sender: bengt.gustafsson@beamways.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:14493
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/14493>

------=_Part_1183_390031277.1415744765776
Content-Type: text/plain; charset=UTF-8

Or use the new free function size, count or whatever it is eventually 
called, or maybe there is an empty() too in the works:

if (!std::empty(range))
    DoSomething(*begin(range));



Den tisdagen den 11:e november 2014 kl. 22:34:39 UTC+1 skrev Matthew 
Woehlke:
>
> On 2014-11-11 16:12, Brent Friedman wrote: 
> > I've noted in our codebase that we lean heavily on the convenience of 
> > range-based for even when it's not perhaps the best way to express an 
> idea. 
> > 
> > //do something to the first item 
> > for (auto& Item : range) 
> > { 
> >     DoSomething(Item); 
> >     break; 
> > } 
>
>     auto first_or_null(auto range) -> decltype(&range.begin()) 
>     { 
>         auto begin = range.begin(); 
>         auto end = range.end(); 
>         return (begin == end ? nullptr : &(*begin)); 
>     } 
>
>     if (auto item = first_or_null(range)) 
>
> Basically you want that, right? :-) 
>
> I'm not sure if that actually works, and it requires an additional 
> dereference when you go to use 'item', but OTOH it wouldn't require a 
> language change... 
>
> That said, how often can you not write: 
>
>     if (!range.empty()) 
>         DoSomething(*range.begin()); 
>
> ...? 
>
> -- 
> 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/.

------=_Part_1183_390031277.1415744765776
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Or use the new free function size, count or whatever it is=
 eventually called, or maybe there is an empty() too in the works:<div><br>=
</div><div>if (!std::empty(range))</div><div>&nbsp; &nbsp; DoSomething(*beg=
in(range));</div><div><br></div><div><br><br>Den tisdagen den 11:e november=
 2014 kl. 22:34:39 UTC+1 skrev Matthew Woehlke:<blockquote class=3D"gmail_q=
uote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;pad=
ding-left: 1ex;">On 2014-11-11 16:12, Brent Friedman wrote:
<br>&gt; I've noted in our codebase that we lean heavily on the convenience=
 of
<br>&gt; range-based for even when it's not perhaps the best way to express=
 an idea.
<br>&gt;=20
<br>&gt; //do something to the first item
<br>&gt; for (auto&amp; Item : range)
<br>&gt; {
<br>&gt; &nbsp; &nbsp; DoSomething(Item);
<br>&gt; &nbsp; &nbsp; break;
<br>&gt; }
<br>
<br>&nbsp; &nbsp; auto first_or_null(auto range) -&gt; decltype(&amp;range.=
begin())
<br>&nbsp; &nbsp; {
<br>&nbsp; &nbsp; &nbsp; &nbsp; auto begin =3D range.begin();
<br>&nbsp; &nbsp; &nbsp; &nbsp; auto end =3D range.end();
<br>&nbsp; &nbsp; &nbsp; &nbsp; return (begin =3D=3D end ? nullptr : &amp;(=
*begin));
<br>&nbsp; &nbsp; }
<br>
<br>&nbsp; &nbsp; if (auto item =3D first_or_null(range))
<br>
<br>Basically you want that, right? :-)
<br>
<br>I'm not sure if that actually works, and it requires an additional
<br>dereference when you go to use 'item', but OTOH it wouldn't require a
<br>language change...
<br>
<br>That said, how often can you not write:
<br>
<br>&nbsp; &nbsp; if (!range.empty())
<br>&nbsp; &nbsp; &nbsp; &nbsp; DoSomething(*range.begin());
<br>
<br>...?
<br>
<br>--=20
<br>Matthew
<br>
<br></blockquote></div></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 />

------=_Part_1183_390031277.1415744765776--

.
