220 14492 <m3tvcu$9ia$1@ger.gmane.org> article
Path: news.gmane.org!not-for-mail
From: Matthew Woehlke <mw_triad@users.sourceforge.net>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Range-based if
Date: Tue, 11 Nov 2014 16:34:21 -0500
Lines: 44
Approved: news@gmane.org
Message-ID: <m3tvcu$9ia$1@ger.gmane.org>
References: <CADbh+eQCaTPArs7YBUg9mYwrnJ2Gu3SRAfqUbPiLscpyxV8JqQ@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
X-Trace: ger.gmane.org 1415741690 10051 80.91.229.3 (11 Nov 2014 21:34:50 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 11 Nov 2014 21:34:50 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCO5FYHBU4ERB3MBRKRQKGQEJRXFILI@isocpp.org Tue Nov 11 22:34:40 2014
Return-path: <std-proposals+bncBCO5FYHBU4ERB3MBRKRQKGQEJRXFILI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ee0-f71.google.com ([74.125.83.71])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCO5FYHBU4ERB3MBRKRQKGQEJRXFILI@isocpp.org>)
	id 1XoJ5D-00035m-3Z
	for gclcip-std-proposals@m.gmane.org; Tue, 11 Nov 2014 22:34:39 +0100
Original-Received: by mail-ee0-f71.google.com with SMTP id e51sf7334759eek.6
        for <gclcip-std-proposals@m.gmane.org>; Tue, 11 Nov 2014 13:34:38 -0800 (PST)
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:user-agent:in-reply-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=v6aUXV9gCxAfX340eK/M6hsEvzLRi1GSuvDU5aaMXNE=;
        b=k4S2CNdQdX/mCdUhblo/JSVLoLGJWFj07WEvhLoOPaPMLi2RDaym75TP2qVHxUbqMY
         mpCW+gploE+0wdpJc5NGu8Qf+f0tMShWVVrGhTUB0uEFcZG4X81nvb8beDgxrmV2O78L
         W3MCmJDPaHFfNYDoUSLQMW5A10RwGh0RHCqpLB3OzGT4XGVOdwt2ad5wiWvOrCsrrU7E
         kvo8VRf2kjKk+RdAYCoUFJioma1h8aIG3XlItjDDUtq1bTf8LrJQpvALpjUupY8RutiN
         mxBPLth/Sv/OaDRxJn61tMnFfhKCbBOdDN4JI2JrGBZohgMcQyLMRWoPysuI5GVvE3kl
         94QA==
X-Gm-Message-State: ALoCoQn6vCwLn8ZyWLJ0sUHp4+Lty9s0xDgqG5dff6Aq0JYdaeejBbgXarKZO14JJKjD6hx283/C
X-Received: by 10.152.27.38 with SMTP id q6mr1043954lag.5.1415741678717;
        Tue, 11 Nov 2014 13:34:38 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.152.29.135 with SMTP id k7ls543767lah.78.gmail; Tue, 11 Nov
 2014 13:34:36 -0800 (PST)
X-Received: by 10.152.115.131 with SMTP id jo3mr38360390lab.20.1415741676845;
        Tue, 11 Nov 2014 13:34:36 -0800 (PST)
Original-Received: from plane.gmane.org (plane.gmane.org. [80.91.229.3])
        by mx.google.com with ESMTPS id o3si32924862lag.29.2014.11.11.13.34.36
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=RC4-SHA bits=128/128);
        Tue, 11 Nov 2014 13:34:36 -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 1XoJ58-00033q-N5
	for std-proposals@isocpp.org; Tue, 11 Nov 2014 22:34:34 +0100
Original-Received: from cpe-67-240-43-113.nycap.res.rr.com ([67.240.43.113])
        by main.gmane.org with esmtp (Gmexim 0.1 (Debian))
        id 1AlnuQ-0007hv-00
        for <std-proposals@isocpp.org>; Tue, 11 Nov 2014 22:34:34 +0100
Original-Received: from mw_triad by cpe-67-240-43-113.nycap.res.rr.com with local (Gmexim 0.1 (Debian))
        id 1AlnuQ-0007hv-00
        for <std-proposals@isocpp.org>; Tue, 11 Nov 2014 22:34:34 +0100
X-Injected-Via-Gmane: http://gmane.org/
Original-Lines: 35
Original-X-Complaints-To: usenet@ger.gmane.org
X-Gmane-NNTP-Posting-Host: cpe-67-240-43-113.nycap.res.rr.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0
In-Reply-To: <CADbh+eQCaTPArs7YBUg9mYwrnJ2Gu3SRAfqUbPiLscpyxV8JqQ@mail.gmail.com>
X-Original-Sender: mw_triad@users.sourceforge.net
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.mail=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: <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:14492
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/14492>

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/.

.
