220 19212 <424cd221-d1c7-4baf-b074-b7f44ee5c82e@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:15:04 -0700 (PDT)
Lines: 266
Approved: news@gmane.org
Message-ID: <424cd221-d1c7-4baf-b074-b7f44ee5c82e@isocpp.org>
References: <012fd35d-96fd-4775-835e-2105176c4f97@isocpp.org>
 <dc79f59b-77d2-45f6-96ad-50c704cb873d@isocpp.org>
 <70492682-c1ac-4d67-9c00-fe8d841aae63@isocpp.org>
 <f4f76dbb-96d2-432f-82ed-0df45658f72c@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_804_255530540.1437678905025"
X-Trace: ger.gmane.org 1437678910 9881 80.91.229.3 (23 Jul 2015 19:15:10 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 23 Jul 2015 19:15:10 +0000 (UTC)
Cc: rs2740@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCXLLRHD7IDRBO72YSWQKGQEAIMRY6I@isocpp.org Thu Jul 23 21:15:10 2015
Return-path: <std-proposals+bncBCXLLRHD7IDRBO72YSWQKGQEAIMRY6I@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-oi0-f72.google.com ([209.85.218.72])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCXLLRHD7IDRBO72YSWQKGQEAIMRY6I@isocpp.org>)
	id 1ZILxV-0007PI-Fc
	for gclcip-std-proposals@m.gmane.org; Thu, 23 Jul 2015 21:15:09 +0200
Original-Received: by oige126 with SMTP id e126sf1677729oig.0
        for <gclcip-std-proposals@m.gmane.org>; Thu, 23 Jul 2015 12:15:08 -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=2cRkrECOmoJcKY5jQ3Gsi/Cu3JK2BZ0jcFWPFhNr5M8=;
        b=ltIkZxr5u+LFQrtbl05vCfOXecQ1hZM/PXQHu0H8RUdm/KXKyQVwlDkuR/5zl5twk9
         uyc0uguBkiLIm0+gfh6UrvhYDbDCA8O3HdE6jQBC8s2itqL6ukioGQv6UljQEYbus8zY
         ZFkliMx5L+4FaWz82UODMv9zsln4MBZ7UEOF5Vt8bFOvcLtQN7IxtLiko1G0DooxMvOZ
         DiCp+ged7S0fMB8AAgljeLFGdBs1Ivpuhi48pOhWI/AulXLsUC0tQNSpwHFnaIEUeW+g
         /5JQgHsr09oC7FSw72rQjac8s0qmgkBCkj+hWDvrwdozDgH+E+Lu7QYxwecSnAo04YvJ
         jy9w==
X-Gm-Message-State: ALoCoQnFyOTGqEo5dLKZQBjD3TKHTUMBTQCuzJvezwM5/rUuGF6yQRAjrqaLM80erMuGwYtFmmhv
X-Received: by 10.182.142.72 with SMTP id ru8mr10056690obb.47.1437678908504;
        Thu, 23 Jul 2015 12:15:08 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.31.194 with SMTP id f60ls1151878qgf.7.gmail; Thu, 23 Jul
 2015 12:15:07 -0700 (PDT)
X-Received: by 10.140.92.74 with SMTP id a68mr215385qge.14.1437678907374;
        Thu, 23 Jul 2015 12:15:07 -0700 (PDT)
In-Reply-To: <f4f76dbb-96d2-432f-82ed-0df45658f72c@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:19212
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/19212>

------=_Part_804_255530540.1437678905025
Content-Type: multipart/alternative; 
	boundary="----=_Part_805_1077728928.1437678905026"

------=_Part_805_1077728928.1437678905026
Content-Type: text/plain; charset=UTF-8

There is nothing said about introducing functions std::begin and std:;end 
for std::pair.

On Thursday, July 23, 2015 at 9:52:23 PM UTC+3, T. C. wrote:
>
> http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#1381
>
>
> On Thursday, July 23, 2015 at 2:30:02 PM UTC-4, Vlad from Moscow wrote:
>>
>> And one more example :)
>>
>> #include <iostream>
>> #include <utility>
>> #include <vector>
>> #include <algorithm>
>> #include <iterator>
>>
>> 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::vector<int> v = { 3, 4, 0, 5, 1, 6, 9, 7, 8 };
>>     
>>     for ( auto x : v ) std::cout << x << ' ';
>>     std::cout << std::endl;
>>     auto p = std::minmax_element( v.begin(), v.end() );
>>     
>>     if ( std::distance( v.begin(), p.second ) < std::distance( v.begin(), 
>> p.first ) )
>>     {
>>         std::swap( p.first, p.second );
>>     }        
>>     for ( auto x : p ) std::cout << x << ' ';
>>     std::cout << std::endl;
>> }    
>>
>> The program output is
>>
>> 3 4 0 5 1 6 9 7 8 
>> 0 5 1 6
>>
>> On Thursday, July 23, 2015 at 8:57:38 PM UTC+3, Vlad from Moscow wrote:
>>
>>> Another example
>>>
>>> #include <iostream>
>>> #include <utility>
>>> #include <vector>
>>>
>>> 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::vector<int> v = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
>>>     
>>>     for ( auto x : std::make_pair( v.begin(), v.end() ) ) std::cout << x 
>>> << ' ';
>>>     std::cout << std::endl;
>>>     
>>>     for ( auto x : std::make_pair( v.rbegin(), v.rend() ) ) std::cout << 
>>> x << ' ';
>>>     std::cout << std::endl;
>>> }    
>>>
>>> The program output is
>>>
>>> 0 1 2 3 4 5 6 7 8 9 
>>> 9 8 7 6 5 4 3 2 1 0
>>>
>>> Enjoy!:)
>>>
>>> On Thursday, July 23, 2015 at 8:36:46 PM UTC+3, 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;
>>>> }
>>>> }
>>>>
>>>> int main()
>>>> {
>>>>     int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
>>>>     
>>>>     for ( auto x : std::make_pair( a + 3, a + 7 ) ) std::cout << x << ' 
>>>> ';
>>>>     std::cout << std::endl;
>>>>     
>>>>     int b[][3] = { { 1, 2, 3 }, { 4, 5, 6 } };
>>>>     
>>>>     for ( auto x : std::make_pair( b[0] + 1, b[1] + 2 ) ) std::cout << 
>>>> x << ' ';
>>>>     std::cout << std::endl;
>>>> }
>>>>
>>>> The program output is
>>>>
>>>> 3 4 5 6 
>>>> 2 3 4 5    
>>>>
>>>

-- 

--- 
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_805_1077728928.1437678905026
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">There is nothing said about introducing functions std::beg=
in and std:;end for std::pair.<br><br>On Thursday, July 23, 2015 at 9:52:23=
 PM UTC+3, T. C. wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0=
px 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><=
a onmousedown=3D"this.href=3D&#39;http://www.google.com/url?q\75http%3A%2F%=
2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Flwg-defects.html%231381\46=
sa\75D\46sntz\0751\46usg\75AFQjCNGCnw-GAV0E1QTFZv90wIFhv-vtdQ&#39;;return t=
rue;" onclick=3D"this.href=3D&#39;http://www.google.com/url?q\75http%3A%2F%=
2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Flwg-defects.html%231381\46=
sa\75D\46sntz\0751\46usg\75AFQjCNGCnw-GAV0E1QTFZv90wIFhv-vtdQ&#39;;return t=
rue;" href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#=
1381" target=3D"_blank" rel=3D"nofollow">http://www.open-std.org/jtc1/sc22/=
wg21/docs/lwg-defects.html#1381</a></div><div><br></div><div><div><br></div=
><div>On Thursday, July 23, 2015 at 2:30:02 PM UTC-4, Vlad from Moscow wrot=
e:<blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; pad=
ding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1=
px; border-left-style: solid;"><div dir=3D"ltr"><div>And one more example :=
)</div><div><br></div><div>#include &lt;iostream&gt;<br>#include &lt;utilit=
y&gt;<br>#include &lt;vector&gt;<br>#include &lt;algorithm&gt;<br>#include =
&lt;iterator&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.firs=
t;<br>}</div><div>template &lt;class Iterator&gt;<br>Iterator end( const st=
d::pair&lt;Iterator, Iterator&gt; &amp;p )<br>{<br>=C2=A0=C2=A0=C2=A0 retur=
n p.second;<br>}<br>}</div><div>int main()<br>{<br>=C2=A0=C2=A0=C2=A0 std::=
vector&lt;int&gt; v =3D { 3, 4, 0, 5, 1, 6, 9, 7, 8 };<br>=C2=A0=C2=A0=C2=
=A0 <br>=C2=A0=C2=A0=C2=A0 for ( auto x : v ) std::cout &lt;&lt; x &lt;&lt;=
 &#39; &#39;;<br>=C2=A0=C2=A0=C2=A0 std::cout &lt;&lt; std::endl;</div><div=
>=C2=A0=C2=A0=C2=A0 auto p =3D std::minmax_element( v.begin(), v.end() );<b=
r>=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0 if ( std::distance( v.begin(), =
p.second ) &lt; std::distance( v.begin(), p.first ) )<br>=C2=A0=C2=A0=C2=A0=
 {<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::swap( p.first, p.seco=
nd );<br>=C2=A0=C2=A0=C2=A0 }=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 </d=
iv><div>=C2=A0=C2=A0=C2=A0 for ( auto x : p ) std::cout &lt;&lt; x &lt;&lt;=
 &#39; &#39;;<br>=C2=A0=C2=A0=C2=A0 std::cout &lt;&lt; std::endl;<br></div>=
<div>}=C2=A0=C2=A0=C2=A0 <br><br></div><div>The program output is</div><div=
><br></div><div>3 4 0 5 1 6 9 7 8 <br>0 5 1 6</div><div><br>On Thursday, Ju=
ly 23, 2015 at 8:57:38 PM UTC+3, Vlad from Moscow wrote:</div><blockquote c=
lass=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"><div>Another example</div><div><br></div><=
div>#include &lt;iostream&gt;<br>#include &lt;utility&gt;<br>#include &lt;v=
ector&gt;</div><div><br></div><div>namespace std<br>{=C2=A0=C2=A0=C2=A0 <br=
></div><div><br></div><div>template &lt;class Iterator&gt;<br>Iterator begi=
n( 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 Ite=
rator&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><br></div=
><div>}</div><div><br></div><div>int main()<br>{<br>=C2=A0=C2=A0=C2=A0 std:=
:vector&lt;int&gt; v =3D { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };<br>=C2=A0=C2=A0=
=C2=A0 <br>=C2=A0=C2=A0=C2=A0 for ( auto x : std::make_pair( v.begin(), v.e=
nd() ) ) std::cout &lt;&lt; x &lt;&lt; &#39; &#39;;<br>=C2=A0=C2=A0=C2=A0 s=
td::cout &lt;&lt; std::endl;<br>=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0 f=
or ( auto x : std::make_pair( v.rbegin(), v.rend() ) ) std::cout &lt;&lt; x=
 &lt;&lt; &#39; &#39;;<br>=C2=A0=C2=A0=C2=A0 std::cout &lt;&lt; std::endl;<=
/div><div>}=C2=A0=C2=A0=C2=A0 <br></div><div><br></div><div>The program out=
put is</div><div><br></div><div>0 1 2 3 4 5 6 7 8 9 <br>9 8 7 6 5 4 3 2 1 0=
</div><div><br></div><div>Enjoy!:)<br><br>On Thursday, July 23, 2015 at 8:3=
6:46 PM UTC+3, Vlad from Moscow wrote:</div><blockquote class=3D"gmail_quot=
e" 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;"><d=
iv dir=3D"ltr"><div>I&#39;d like to =C2=A0suggest very simple and=C2=A0at t=
he same time very useful=C2=A0 overloaded functions std::begin and std::end=
 for standard class std::pair.</div><div><br></div><div>Here is a demonstra=
tive 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;<br>Iterator begi=
n( 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>It=
erator 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><br></div><div>int mai=
n()<br>{<br>=C2=A0=C2=A0=C2=A0 int a[] =3D { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }=
;<br>=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0 for ( auto x : std::make_pai=
r( a + 3, a + 7 ) ) std::cout &lt;&lt; x &lt;&lt; &#39; &#39;;<br>=C2=A0=C2=
=A0=C2=A0 std::cout &lt;&lt; std::endl;</div><div>=C2=A0=C2=A0=C2=A0=C2=A0<=
br>=C2=A0=C2=A0=C2=A0 int b[][3] =3D { { 1, 2, 3 }, { 4, 5, 6 } };</div><di=
v>=C2=A0=C2=A0=C2=A0=C2=A0<br>=C2=A0=C2=A0=C2=A0 for ( auto x : std::make_p=
air( b[0] + 1, b[1] + 2 ) ) std::cout &lt;&lt; x &lt;&lt; &#39; &#39;;<br>=
=C2=A0=C2=A0=C2=A0 std::cout &lt;&lt; std::endl;<br>}</div><div><br></div><=
div>The program output is</div><div><br></div><div>3 4 5 6 <br>2 3 4 5=C2=
=A0=C2=A0=C2=A0 <br></div></div></blockquote></div></blockquote></div></blo=
ckquote></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_805_1077728928.1437678905026--
------=_Part_804_255530540.1437678905025--

.
