220 19217 <c952ced3-987e-409d-ae9c-7e7c90df6d1e@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Vlad from Moscow <vlad.moscow@mail.ru>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Overloading std::begin and std::end for std::pair
Date: Thu, 23 Jul 2015 12:56:54 -0700 (PDT)
Lines: 199
Approved: news@gmane.org
Message-ID: <c952ced3-987e-409d-ae9c-7e7c90df6d1e@isocpp.org>
References: <012fd35d-96fd-4775-835e-2105176c4f97@isocpp.org>
 <e61080cb-ca1f-4426-a6be-4618ffe88cfe@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_944_947749181.1437681414495"
X-Trace: ger.gmane.org 1437681419 18525 80.91.229.3 (23 Jul 2015 19:56:59 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 23 Jul 2015 19:56:59 +0000 (UTC)
Cc: sean.middleditch@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCXLLRHD7IDRBB4OYWWQKGQEOFLGC2Y@isocpp.org Thu Jul 23 21:56:58 2015
Return-path: <std-proposals+bncBCXLLRHD7IDRBB4OYWWQKGQEOFLGC2Y@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-oi0-f70.google.com ([209.85.218.70])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCXLLRHD7IDRBB4OYWWQKGQEOFLGC2Y@isocpp.org>)
	id 1ZIMbx-0003v3-9A
	for gclcip-std-proposals@m.gmane.org; Thu, 23 Jul 2015 21:56:57 +0200
Original-Received: by oiho132 with SMTP id o132sf2835427oih.1
        for <gclcip-std-proposals@m.gmane.org>; Thu, 23 Jul 2015 12:56:56 -0700 (PDT)
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:content-type:x-original-sender
         :reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=wlykT0ohmv6WW2EcIGOh4U/yl8WlzZlXTgqpwUVLARM=;
        b=I618T8zJj/85ynQkk8dkWHKblROzubunBMXMihKUMFpsNfy+aEyuN5JTtw+1WJWtmU
         cNStHDaHLR5XkwS+NDJIBau54GBie8CQ8odHCptNxQ++F2lN8LzggxLUxbkHoaqymglO
         r0IDFKd5RstkzuvSi5zqZIW/dFBY/xc+ftKFyHXsyQgQ7vYsOBDn8tYW9GvxVozTL5Zx
         zTadlgW1+1MTm3GLm+B+nFMs+TNDagPxvKmVHZhpp0uIduAYBnZ/Bwes604N7LpFk4gI
         JdsFHT6EAHrMuQmPI9uFbT1jHeUQoRLivCyiTzwPY0RQuuIivpkexOc7m+extUb7yfg3
         eGsg==
X-Gm-Message-State: ALoCoQkDde8H3d1cMWCXpRvrVeIzs7UoC+ksq7MXl/ZDN8u9VpSNRT26TP4hZBSETxZrcEN3Pefy
X-Received: by 10.107.164.40 with SMTP id n40mr9013743ioe.30.1437681416461;
        Thu, 23 Jul 2015 12:56:56 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.100.194 with SMTP id s60ls1149382qge.25.gmail; Thu, 23 Jul
 2015 12:56:55 -0700 (PDT)
X-Received: by 10.140.92.74 with SMTP id a68mr219763qge.14.1437681415310;
        Thu, 23 Jul 2015 12:56:55 -0700 (PDT)
In-Reply-To: <e61080cb-ca1f-4426-a6be-4618ffe88cfe@isocpp.org>
X-Original-Sender: vlad.moscow@mail.ru
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:19217
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/19217>

------=_Part_944_947749181.1437681414495
Content-Type: multipart/alternative; 
	boundary="----=_Part_945_1255803407.1437681414496"

------=_Part_945_1255803407.1437681414496
Content-Type: text/plain; charset=UTF-8

Or a modified previous example

#include <iostream>
#include <utility>
#include <map>
#include <string>
namespace std
{
    
template <class Iterator>
Iterator begin( const std::pair<Iterator, Iterator> &p )
{
    return p.first;
}
template <class Iterator>
Iterator end( const std::pair<Iterator, Iterator> &p )
{
    return p.second;
}
    
}
int main()
{
    std::multimap<char, std::string> m =
    {
        { 'A', "Apple" }, { 'A', "Animal" }, { 'A', "Amigo" },
        { 'B', "Bee" }, { 'B', "Beef" }, {'B', "Brother" }
    };
    
    auto key = m.empty() ? '\0' : m.begin()->first;
    
    while ( key ) 
    {        
        auto it = m.equal_range( key );
        
        for ( auto p : it ) std::cout << p.first << ' ' << p.second << 
std::endl;
        std::cout << std::endl;
        
        key = it.second == m.end() ? '\0' : it.second->first;
    };       
}    

The program output is

A Apple
A Animal
A Amigo

B Bee
B Beef
B Brother

And why do I have to use here some ranges? Is it that to make my life 
harder?
On Thursday, July 23, 2015 at 10:04:27 PM UTC+3, Sean Middleditch wrote:

> This is solved by ranges (there's a proposal in flight derived from 
> https://github.com/ericniebler/range-v3). You're trying to treat 
> std::pair<iterator, iterator> as a range between the two iterators, which 
> is not semantically correct for all possible pairs of iterators. I'd rather 
> just leave pair alone and let the ranges proposal solve this by replacing 
> the handle of STL uses of pair<iterator, iterator> with a range<iterator>.
>
> In your example it's also solved by array_view, which is really just a 
> form of range.
>
> An additional nice thing about the ranges is that begin, end, size, 
> operator[], etc. can all be added to the range type as member functions (as 
> appropriate for the iterator category).
>
> On Thursday, July 23, 2015 at 10:36:46 AM UTC-7, Vlad from Moscow wrote:
>>
>> I'd like to  suggest very simple and at the same time very useful  
>> overloaded functions std::begin and std::end for standard class std::pair.
>>
>> Here is a demonstrative program of the idea
>>
>> #include <iostream>
>> #include <utility>
>>
>> namespace std
>> {    
>> template <class Iterator>
>> Iterator begin( const std::pair<Iterator, Iterator> &p )
>> {
>>     return p.first;
>> }
>> template <class Iterator>
>> Iterator end( const std::pair<Iterator, Iterator> &p )
>> {
>>     return p.second;
>> }
>> }
>>
>

-- 

--- 
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_945_1255803407.1437681414496
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Or a modified previous example</div><div><br></div><d=
iv>#include &lt;iostream&gt;<br>#include &lt;utility&gt;<br>#include &lt;ma=
p&gt;<br>#include &lt;string&gt;</div><div>namespace std<br>{<br>=C2=A0=C2=
=A0=C2=A0 <br>template &lt;class Iterator&gt;<br>Iterator begin( const std:=
:pair&lt;Iterator, Iterator&gt; &amp;p )<br>{<br>=C2=A0=C2=A0=C2=A0 return =
p.first;<br>}</div><div>template &lt;class Iterator&gt;<br>Iterator end( co=
nst std::pair&lt;Iterator, Iterator&gt; &amp;p )<br>{<br>=C2=A0=C2=A0=C2=A0=
 return p.second;<br>}<br>=C2=A0=C2=A0=C2=A0 <br>}</div><div>int main()<br>=
{<br>=C2=A0=C2=A0=C2=A0 std::multimap&lt;char, std::string&gt; m =3D<br>=C2=
=A0=C2=A0=C2=A0 {<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 { &#39;A&#3=
9;, &quot;Apple&quot; }, { &#39;A&#39;, &quot;Animal&quot; }, { &#39;A&#39;=
, &quot;Amigo&quot; },<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 { &#39=
;B&#39;, &quot;Bee&quot; }, { &#39;B&#39;, &quot;Beef&quot; }, {&#39;B&#39;=
, &quot;Brother&quot; }<br>=C2=A0=C2=A0=C2=A0 };<br>=C2=A0=C2=A0=C2=A0 <br>=
=C2=A0=C2=A0=C2=A0 auto key =3D m.empty() ? &#39;\0&#39; : m.begin()-&gt;fi=
rst;<br>=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0 while ( key ) <br>=C2=A0=
=C2=A0=C2=A0 {=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto it =3D m.equal_range( key );<br>=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 for ( auto p : it ) std::cout &lt;&lt; p.first &lt;&lt; &#39; &#3=
9; &lt;&lt; p.second &lt;&lt; std::endl;<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 std::cout &lt;&lt; std::endl;<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 key =3D it.s=
econd =3D=3D m.end() ? &#39;\0&#39; : it.second-&gt;first;<br>=C2=A0=C2=A0=
=C2=A0 };=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <br>}=C2=A0=C2=A0=C2=A0 <br><=
/div><div><br></div><div>The program output is</div><div><br></div><div>A A=
pple<br>A Animal<br>A Amigo<br><br>B Bee<br>B Beef<br>B Brother<br></div><d=
iv><br></div><div>And why do I have to use here some ranges? Is it that to =
make my life harder?<br>On Thursday, July 23, 2015 at 10:04:27 PM UTC+3, Se=
an Middleditch wrote:</div><blockquote class=3D"gmail_quote" style=3D"margi=
n: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 2=
04); border-left-width: 1px; border-left-style: solid;"><div dir=3D"ltr">Th=
is is solved by ranges (there&#39;s a proposal in flight derived from <a on=
mousedown=3D"this.href=3D&#39;https://www.google.com/url?q\75https%3A%2F%2F=
github.com%2Fericniebler%2Frange-v3\46sa\75D\46sntz\0751\46usg\75AFQjCNF6-7=
MwmERsjtO_yikBxBOgeh0fkA&#39;;return true;" onclick=3D"this.href=3D&#39;htt=
ps://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Fericniebler%2Frange-=
v3\46sa\75D\46sntz\0751\46usg\75AFQjCNF6-7MwmERsjtO_yikBxBOgeh0fkA&#39;;ret=
urn true;" href=3D"https://github.com/ericniebler/range-v3" target=3D"_blan=
k" rel=3D"nofollow">https://github.com/ericniebler/range-v3</a>). You&#39;r=
e trying to treat std::pair&lt;iterator, iterator&gt; as a range between th=
e two iterators, which is not semantically correct for all possible pairs o=
f iterators. I&#39;d rather just leave pair alone and let the ranges propos=
al solve this by replacing the handle of STL uses of pair&lt;iterator, iter=
ator&gt; with a range&lt;iterator&gt;.<div><br></div><div>In your example i=
t&#39;s also solved by array_view, which is really just a form of range.<br=
><div><br></div><div>An additional nice thing about the ranges is that begi=
n, end, size, operator[], etc. can all be added to the range type as member=
 functions (as appropriate for the iterator category).<br><br>On Thursday, =
July 23, 2015 at 10:36:46 AM UTC-7, Vlad from Moscow wrote:<blockquote clas=
s=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; bo=
rder-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-st=
yle: solid;"><div dir=3D"ltr"><div>I&#39;d like to =C2=A0suggest very simpl=
e and=C2=A0at the same time very useful=C2=A0 overloaded functions std::beg=
in and std::end for standard class std::pair.</div><div><br></div><div>Here=
 is a demonstrative program of the idea</div><div><br></div><div>#include &=
lt;iostream&gt;</div><div>#include &lt;utility&gt;</div><div><br></div><div=
>namespace std<br>{=C2=A0=C2=A0=C2=A0 <br>template &lt;class Iterator&gt;<b=
r>Iterator begin( const std::pair&lt;Iterator, Iterator&gt; &amp;p )<br>{<b=
r>=C2=A0=C2=A0=C2=A0 return p.first;<br>}</div><div>template &lt;class Iter=
ator&gt;<br>Iterator end( const std::pair&lt;Iterator, Iterator&gt; &amp;p =
)<br>{<br>=C2=A0=C2=A0=C2=A0 return p.second;<br>}<br>}</div></div></blockq=
uote></div></div></div></blockquote></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_945_1255803407.1437681414496--
------=_Part_944_947749181.1437681414495--

.
