220 19215 <792fab39-5af7-4d95-b9ba-a5cc4aed8544@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:31:59 -0700 (PDT)
Lines: 185
Approved: news@gmane.org
Message-ID: <792fab39-5af7-4d95-b9ba-a5cc4aed8544@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_1075_1516249200.1437679919783"
X-Trace: ger.gmane.org 1437679929 26502 80.91.229.3 (23 Jul 2015 19:32:09 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 23 Jul 2015 19:32:09 +0000 (UTC)
Cc: sean.middleditch@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCXLLRHD7IDRBMECYWWQKGQEE64OQ7Y@isocpp.org Thu Jul 23 21:32:04 2015
Return-path: <std-proposals+bncBCXLLRHD7IDRBMECYWWQKGQEE64OQ7Y@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yk0-f198.google.com ([209.85.160.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCXLLRHD7IDRBMECYWWQKGQEE64OQ7Y@isocpp.org>)
	id 1ZIMDq-0007hy-Rn
	for gclcip-std-proposals@m.gmane.org; Thu, 23 Jul 2015 21:32:03 +0200
Original-Received: by ykek23 with SMTP id k23sf2846749yke.2
        for <gclcip-std-proposals@m.gmane.org>; Thu, 23 Jul 2015 12:32:01 -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=TOic4dS+/Lb4VR/oQoGi9hctPE0qTRp7ocsDf9sedmU=;
        b=HPwUTqpMRVi8zLvkczCidzCUrvc2xlfIQwyoZ0g3vXsaDSvPhfCzVMb/nX+Rb5XQlW
         zqcwircniVjJkcvvRqRzSHo2JRHGS70P0pTshVJxr44UYe2yVoCY85gxwrm6up45tgWn
         tISCy1fcjhVYy1HN2d+lXuMMUGadVdcN0TuKc/0M3VuDZ7ww23byuFtrXFEljoyG5S/t
         ZshLUIrAWSSKB6DHpGzFjBqgRlWa2mIPsjK2b18Gd2HI8IMrlov5HDgl9k9uoYprU8S1
         x1CxETRPShXaK5R+uzKjCtzalKevX4dAvFmFoZLiElV0fSIot5o6+4n8t/AKBtkkl+w5
         78yA==
X-Gm-Message-State: ALoCoQniHRIK+ixvPJrAEO7I5vxskkiYYm6ayei5wDj6cLCMAXUWTb4pkzUT9pzYLJmkZnCF1fXb
X-Received: by 10.13.244.2 with SMTP id d2mr10138066ywf.34.1437679921471;
        Thu, 23 Jul 2015 12:32:01 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.35.199 with SMTP id n65ls1144147qgn.21.gmail; Thu, 23 Jul
 2015 12:32:00 -0700 (PDT)
X-Received: by 10.140.19.46 with SMTP id 43mr224056qgg.13.1437679920545;
        Thu, 23 Jul 2015 12:32:00 -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:19215
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/19215>

------=_Part_1075_1516249200.1437679919783
Content-Type: multipart/alternative; 
	boundary="----=_Part_1076_1409815911.1437679919784"

------=_Part_1076_1409815911.1437679919784
Content-Type: text/plain; charset=UTF-8

Could you explain why do I need some ranges when this program looks clear 
and nice without any ranges?

#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 it = m.equal_range( 'A' );
    
    
    for ( auto p : it ) std::cout << p.first << ' ' << p.second << 
std::endl;
}    

The program output is

A Apple
A Animal
A Amigo



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_1076_1409815911.1437679919784
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Could you explain why do I need some ranges when this=
 program looks clear and nice without any ranges?</div><div><br></div><div>=
#include &lt;iostream&gt;<br>#include &lt;utility&gt;<br>#include &lt;map&g=
t;<br>#include &lt;string&gt;</div><div><br></div><div>namespace std<br>{<b=
r>=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><br></div><div>template &lt;class Iterat=
or&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>=C2=A0=C2=A0=C2=A0 <br>=
}</div><div><br></div><div>int main()<br>{<br>=C2=A0=C2=A0=C2=A0 std::multi=
map&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&#39;, &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 it =3D=
 m.equal_range( &#39;A&#39; );<br>=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0=
 <br>=C2=A0=C2=A0=C2=A0 for ( auto p : it ) std::cout &lt;&lt; p.first &lt;=
&lt; &#39; &#39; &lt;&lt; p.second &lt;&lt; std::endl;<br>}=C2=A0=C2=A0=C2=
=A0 </div><div><br></div><div>The program output is</div><div><br></div><di=
v>A Apple<br>A Animal<br>A Amigo<br></div><div><br></div><div><br><br>On Th=
ursday, July 23, 2015 at 10:04:27 PM UTC+3, Sean Middleditch wrote:</div><b=
lockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding=
-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; =
border-left-style: solid;"><div dir=3D"ltr">This is solved by ranges (there=
&#39;s a proposal in flight derived from <a onmousedown=3D"this.href=3D&#39=
;https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Fericniebler%2Fra=
nge-v3\46sa\75D\46sntz\0751\46usg\75AFQjCNF6-7MwmERsjtO_yikBxBOgeh0fkA&#39;=
;return true;" onclick=3D"this.href=3D&#39;https://www.google.com/url?q\75h=
ttps%3A%2F%2Fgithub.com%2Fericniebler%2Frange-v3\46sa\75D\46sntz\0751\46usg=
\75AFQjCNF6-7MwmERsjtO_yikBxBOgeh0fkA&#39;;return true;" href=3D"https://gi=
thub.com/ericniebler/range-v3" target=3D"_blank" rel=3D"nofollow">https://g=
ithub.com/ericniebler/range-v3</a>). You&#39;re trying to treat std::pair&l=
t;iterator, iterator&gt; as a range between the two iterators, which is not=
 semantically correct for all possible pairs of iterators. I&#39;d rather j=
ust leave pair alone and let the ranges proposal solve this by replacing th=
e handle of STL uses of pair&lt;iterator, iterator&gt; with a range&lt;iter=
ator&gt;.<div><br></div><div>In your example it&#39;s also solved by array_=
view, which is really just a form of range.<br><div><br></div><div>An addit=
ional 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 fo=
r the iterator category).<br><br>On Thursday, July 23, 2015 at 10:36:46 AM =
UTC-7, Vlad from Moscow wrote:<blockquote class=3D"gmail_quote" style=3D"ma=
rgin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204=
, 204); border-left-width: 1px; border-left-style: solid;"><div dir=3D"ltr"=
><div>I&#39;d like to =C2=A0suggest very simple and=C2=A0at the same time v=
ery useful=C2=A0 overloaded functions std::begin and std::end for standard =
class std::pair.</div><div><br></div><div>Here is a demonstrative program o=
f the idea</div><div><br></div><div>#include &lt;iostream&gt;</div><div>#in=
clude &lt;utility&gt;</div><div><br></div><div>namespace std<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>}</div></div></blockquote></div></div></div></blo=
ckquote></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_1076_1409815911.1437679919784--
------=_Part_1075_1516249200.1437679919783--

.
