220 19208 <dc79f59b-77d2-45f6-96ad-50c704cb873d@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 10:57:37 -0700 (PDT)
Lines: 167
Approved: news@gmane.org
Message-ID: <dc79f59b-77d2-45f6-96ad-50c704cb873d@isocpp.org>
References: <012fd35d-96fd-4775-835e-2105176c4f97@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_666_974218136.1437674258041"
X-Trace: ger.gmane.org 1437674262 30013 80.91.229.3 (23 Jul 2015 17:57:42 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 23 Jul 2015 17:57:42 +0000 (UTC)
Cc: vlad.moscow@mail.ru
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCXLLRHD7IDRBEWWYSWQKGQEQK3HXSI@isocpp.org Thu Jul 23 19:57:42 2015
Return-path: <std-proposals+bncBCXLLRHD7IDRBEWWYSWQKGQEQK3HXSI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-vn0-f72.google.com ([209.85.216.72])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCXLLRHD7IDRBEWWYSWQKGQEQK3HXSI@isocpp.org>)
	id 1ZIKkW-0000TR-AM
	for gclcip-std-proposals@m.gmane.org; Thu, 23 Jul 2015 19:57:40 +0200
Original-Received: by vnav141 with SMTP id v141sf134231722vna.1
        for <gclcip-std-proposals@m.gmane.org>; Thu, 23 Jul 2015 10:57:39 -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=Zig8KYjxYdfvhIjLEm3bx65uRgDJg/H87MyA0iD4bWQ=;
        b=btwKw/Ga4M3vFg7EEqg4PMw6YIkkUTNJ1EFJocZs0MPcCjhPCNgnPmNq72JX7UVuC9
         udJM2hBibgWaSGZAYlFGGpgEPSFHWNvYNli1WFC/utpBb205PVYT8aqR1kMlWcjoS+ZV
         unKB+TZH/LbMV8Q6DZc0k/Di4mD8yj9NajXDmH9JlZ2/vjv1cHxL+jfp15SBjyS1+57O
         m+aU+8kOK9PJew/Tt31d6PAN8qgGH+djpfbXqKShnYbDK/nYT7SgquRS2kg8zP42jGSM
         E2k8Y4mrBeVIBQVM2tkwJXu+z08E3DvrH+Gc3lyOrPCTXSvjeOMMT42xKUsGjx70ep07
         aLdA==
X-Gm-Message-State: ALoCoQn2uI+I1gIqAKMqtBMBUcWWKBTbJ8yO6xwo3Lcse59NRaA3APPb5cdCAW9IcBEbqYwSPNy9
X-Received: by 10.129.90.134 with SMTP id o128mr6473737ywb.14.1437674259475;
        Thu, 23 Jul 2015 10:57:39 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.19.105 with SMTP id 96ls1089665qgg.68.gmail; Thu, 23 Jul
 2015 10:57:38 -0700 (PDT)
X-Received: by 10.140.106.247 with SMTP id e110mr207385qgf.7.1437674258667;
        Thu, 23 Jul 2015 10:57:38 -0700 (PDT)
In-Reply-To: <012fd35d-96fd-4775-835e-2105176c4f97@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:19208
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/19208>

------=_Part_666_974218136.1437674258041
Content-Type: multipart/alternative; 
	boundary="----=_Part_667_1843617176.1437674258041"

------=_Part_667_1843617176.1437674258041
Content-Type: text/plain; charset=UTF-8

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_667_1843617176.1437674258041
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><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>template &lt;class Iterator&gt;<br>Iterator begin( const std::pa=
ir&lt;Iterator, Iterator&gt; &amp;p )<br>{<br>=C2=A0=C2=A0=C2=A0 return p.f=
irst;<br>}</div><div><br></div><div>template &lt;class Iterator&gt;<br>Iter=
ator 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.end() ) ) std::cou=
t &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><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:36:46 PM UTC+3, Vl=
ad from Moscow 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"><d=
iv>I&#39;d like to =C2=A0suggest very simple and=C2=A0at the same time very=
 useful=C2=A0 overloaded functions std::begin and std::end for standard cla=
ss std::pair.</div><div><br></div><div>Here is a demonstrative program of t=
he idea</div><div><br></div><div>#include &lt;iostream&gt;</div><div>#inclu=
de &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::pa=
ir&lt;Iterator, Iterator&gt; &amp;p )<br>{<br>=C2=A0=C2=A0=C2=A0 return p.f=
irst;<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 re=
turn p.second;<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::cout &lt;&lt; x &lt;&lt; &#39; &#39;;<br>=C2=A0=C2=A0=C2=A0 std::co=
ut &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</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>

<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_667_1843617176.1437674258041--
------=_Part_666_974218136.1437674258041--

.
