220 19209 <70492682-c1ac-4d67-9c00-fe8d841aae63@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 11:30:02 -0700 (PDT)
Lines: 237
Approved: news@gmane.org
Message-ID: <70492682-c1ac-4d67-9c00-fe8d841aae63@isocpp.org>
References: <012fd35d-96fd-4775-835e-2105176c4f97@isocpp.org>
 <dc79f59b-77d2-45f6-96ad-50c704cb873d@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_456_1822935554.1437676202900"
X-Trace: ger.gmane.org 1437676210 30395 80.91.229.3 (23 Jul 2015 18:30:10 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 23 Jul 2015 18:30:10 +0000 (UTC)
Cc: vlad.moscow@mail.ru
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCXLLRHD7IDRBK7FYSWQKGQEO6A6OKQ@isocpp.org Thu Jul 23 20:30:09 2015
Return-path: <std-proposals+bncBCXLLRHD7IDRBK7FYSWQKGQEO6A6OKQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qk0-f197.google.com ([209.85.220.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCXLLRHD7IDRBK7FYSWQKGQEO6A6OKQ@isocpp.org>)
	id 1ZILFt-0000jG-KF
	for gclcip-std-proposals@m.gmane.org; Thu, 23 Jul 2015 20:30:05 +0200
Original-Received: by qkbs7 with SMTP id s7sf731907qkb.0
        for <gclcip-std-proposals@m.gmane.org>; Thu, 23 Jul 2015 11:30:04 -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=myXafSBK1xkwg5F+wIklpz/UVWkhB8bMSUZow+yT8a4=;
        b=bPUjtwKsJpgJnzQoZ0e5aJJ2GuheXb/m/EiCkYPK7M5U5UlPix7rocqoEFKyS8B5m1
         joGa65pZh0bUJ97NduQ0cX4Wp4brFbsSHf2SRTkEdT29z6r572vfFonUSarTONufo7wg
         EVkB705BZR9m9ytbqGTBwoVDlr+4Ma4qNPJqUaokArc9f71GWOiG1tygR3hTQCJTjF51
         kbOVixuIbP7rx+11/FCk6onIE/jYF4iBydQ8MpsdYS0SyMvlLsdMIrkGWTIGdFJ12zLz
         zyci4i5iWlhx5YjLtt2Mc6aWbDScBbLl25srx1cOQlfiwFK3qJT8KSv4ey46Yi5i51t3
         FR8w==
X-Gm-Message-State: ALoCoQlTtGz+RSk6nouVVWu2VCLrqKsWOll8Q0dgFFTuG6GKoTgMAYI5OxVj8GtEjl1Q+JTbl3ID
X-Received: by 10.13.248.133 with SMTP id i127mr9544799ywf.38.1437676204799;
        Thu, 23 Jul 2015 11:30:04 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.42.104 with SMTP id b95ls1094970qga.64.gmail; Thu, 23 Jul
 2015 11:30:03 -0700 (PDT)
X-Received: by 10.140.39.165 with SMTP id v34mr216057qgv.25.1437676203435;
        Thu, 23 Jul 2015 11:30:03 -0700 (PDT)
In-Reply-To: <dc79f59b-77d2-45f6-96ad-50c704cb873d@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:19209
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/19209>

------=_Part_456_1822935554.1437676202900
Content-Type: multipart/alternative; 
	boundary="----=_Part_457_782634225.1437676202900"

------=_Part_457_782634225.1437676202900
Content-Type: text/plain; charset=UTF-8

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_457_782634225.1437676202900
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>And one more example :)</div><div><br></div><div>#inc=
lude &lt;iostream&gt;<br>#include &lt;utility&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 Iter=
ator&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( const std::pair&lt;Iterator, Iterator&g=
t; &amp;p )<br>{<br>=C2=A0=C2=A0=C2=A0 return 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 s=
td::minmax_element( v.begin(), v.end() );<br>=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.second );<br>=C2=A0=C2=A0=C2=A0 }=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 </div><div>=C2=A0=C2=A0=C2=A0 fo=
r ( 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, July 23, 2015 at 8:57:38 PM UTC=
+3, Vlad from Moscow wrote:</div><blockquote 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"l=
tr"><div>Another example</div><div><br></div><div>#include &lt;iostream&gt;=
<br>#include &lt;utility&gt;<br>#include &lt;vector&gt;</div><div><br></div=
><div>namespace std<br>{=C2=A0=C2=A0=C2=A0 <br></div><div><br></div><div>te=
mplate &lt;class Iterator&gt;<br>Iterator begin( const std::pair&lt;Iterato=
r, Iterator&gt; &amp;p )<br>{<br>=C2=A0=C2=A0=C2=A0 return p.first;<br>}</d=
iv><div><br></div><div>template &lt;class Iterator&gt;<br>Iterator end( con=
st 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><d=
iv>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 f=
or ( auto x : std::make_pair( v.begin(), v.end() ) ) std::cout &lt;&lt; x &=
lt;&lt; &#39; &#39;;<br>=C2=A0=C2=A0=C2=A0 std::cout &lt;&lt; std::endl;<br=
>=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0 for ( 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 output is</div><div><br></div><d=
iv>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>Enj=
oy!:)<br><br>On Thursday, July 23, 2015 at 8:36:46 PM UTC+3, Vlad from Mosc=
ow wrote:</div><blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0=
px 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 l=
ike to =C2=A0suggest very simple and=C2=A0at the same time very useful=C2=
=A0 overloaded functions std::begin and std::end for standard class std::pa=
ir.</div><div><br></div><div>Here is a demonstrative program of the idea</d=
iv><div><br></div><div>#include &lt;iostream&gt;</div><div>#include &lt;uti=
lity&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;Itera=
tor, 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( const std::pair&=
lt;Iterator, Iterator&gt; &amp;p )<br>{<br>=C2=A0=C2=A0=C2=A0 return p.seco=
nd;<br>}<br>}</div><div><br></div><div>int main()<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_pair( a + 3, a + 7 ) ) std::co=
ut &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><div>=C2=A0=C2=A0=C2=A0=C2=A0<=
br>=C2=A0=C2=A0=C2=A0 for ( auto x : std::make_pair( 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</d=
iv><div><br></div><div>3 4 5 6 <br>2 3 4 5=C2=A0=C2=A0=C2=A0 <br></div></di=
v></blockquote></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_457_782634225.1437676202900--
------=_Part_456_1822935554.1437676202900--

.
