220 19220 <f8707372-73ad-4e74-bd5a-caf79b6c361f@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: Re: Overloading std::begin and std::end for std::pair
Date: Thu, 23 Jul 2015 13:13:06 -0700 (PDT)
Lines: 665
Approved: news@gmane.org
Message-ID: <f8707372-73ad-4e74-bd5a-caf79b6c361f@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>
 <424cd221-d1c7-4baf-b074-b7f44ee5c82e@isocpp.org>
 <58625b71-98be-4acb-9815-af1ec2113cc6@isocpp.org>
 <ae00798f-2944-44ae-a526-4b8e2aeba2ac@isocpp.org>
 <CALQmNFi4R=od29BMMYyOL=6aHv=PoqjaGi_ykvGQD5SJ4ctonQ@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1101_694178070.1437682386877"
X-Trace: ger.gmane.org 1437682395 1729 80.91.229.3 (23 Jul 2015 20:13:15 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 23 Jul 2015 20:13:15 +0000 (UTC)
Cc: rs2740@gmail.com, sean@middleditch.us
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCXLLRHD7IDRBU4VYWWQKGQE7XE5P6I@isocpp.org Thu Jul 23 22:13:10 2015
Return-path: <std-proposals+bncBCXLLRHD7IDRBU4VYWWQKGQE7XE5P6I@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pd0-f199.google.com ([209.85.192.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCXLLRHD7IDRBU4VYWWQKGQE7XE5P6I@isocpp.org>)
	id 1ZIMrd-00044c-Ml
	for gclcip-std-proposals@m.gmane.org; Thu, 23 Jul 2015 22:13:10 +0200
Original-Received: by pdbpo3 with SMTP id po3sf5602541pdb.1
        for <gclcip-std-proposals@m.gmane.org>; Thu, 23 Jul 2015 13:13: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=JjjF/xdlZ+NjJSx9c57o94RVQoHf5BTxw2faAFQFevk=;
        b=JeSwm+M4kf4zJ2lM/JU+jUQQIvPuVuiDET0JMZ7wvgs0E5TV/S+YzPQJ/cVu7ArceM
         Baftuhx+hdglISF0k+trc3W/9SWqPqRQtwijrgLayAgoWv+PQJioUnOksmMjlgaxUBin
         PZM3Ezt7VqxXpiD+fgr3zvrpaeWKPz3Y4klaE7528vSWSe9GzTgNzOh6W/NQSnwtzt0z
         NzWifsxmjl/BjAqO8aeJVwtI3+uRtBMP3e3+oKaTSobyGHS6dvTUIuAUQnKjJw734gb3
         YykXY//DzXavCdY64XDL+5moVv6GZeWijwhuqY9LoEvH19EWm+fJpq8dF+MNM88rtOV4
         Vq4g==
X-Gm-Message-State: ALoCoQk7UfvnbjN3ZDcxyL3xe5QHWZUp/9BU9iL1AwWFpDDKgX83OQIQ2WzssN2wJj+CfAAXgN7X
X-Received: by 10.66.184.132 with SMTP id eu4mr10030549pac.15.1437682388618;
        Thu, 23 Jul 2015 13:13:08 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.22.198 with SMTP id 64ls1187128qgn.2.gmail; Thu, 23 Jul
 2015 13:13:07 -0700 (PDT)
X-Received: by 10.140.85.232 with SMTP id n95mr230638qgd.21.1437682387511;
        Thu, 23 Jul 2015 13:13:07 -0700 (PDT)
In-Reply-To: <CALQmNFi4R=od29BMMYyOL=6aHv=PoqjaGi_ykvGQD5SJ4ctonQ@mail.gmail.com>
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:19220
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/19220>

------=_Part_1101_694178070.1437682386877
Content-Type: multipart/alternative; 
	boundary="----=_Part_1102_811115058.1437682386877"

------=_Part_1102_811115058.1437682386877
Content-Type: text/plain; charset=UTF-8



On Thursday, July 23, 2015 at 10:57:30 PM UTC+3, Sean Middleditch wrote:
>
> std::pair is not semantically a range. Treating it as such is wrong. 
> Period. It _can_ be used as a range, but it would be more correct to 
> then clearly make a semantic range type for this purpose. 
>
> For member functions like equal_range, those really should return a 
> proper range type. Returning a pair was (in hindsight) a mistake of 
> the design. Doubling down on that mistake would just be another 
> mistake; instead, the mistake should be corrected (whether that means 
> changing the return type or creating new alternatives). 
>
> I am sorry but this has no any great sense. As I said early you can use 
any two iterators by mistake that do not make a range with any algorithm. 
For example what does prevent you to write

int a[] = { /*...*/ };
int b[] = { /*...*/ };

std::for_each( std::begin(a ), std::and( b ), some_function_pointer );

Or 

int m = 5;
int n = 2;
//...
std::for_each( a + m, a + n, some_function_pointer );
 
 

> We can't retroactively change return types without breaking 
> compatibility (probably), but the ranges will facilitate either adding 
> new member functions/algorithms if not an entirely new STL (with 
> concepts + ranges). 
>
> That is where ranges is not neeed you want to litter the STL with ranges.
 

> Also remember that as Eric N. pointed out, iterator pairs aren't even 
> necessarily the best way to model ranges, esp. for some more advanced 
> containers (instead you want iterator and sentinel type), so the 
> existing interfaces that return a pair of iterators have yet other 
> reasons to be replaced with proper ranges anyway. 
>
> If you want your example to work easily and quickly, consider making 
> your own quick wrapper: 
>
> // wrapper 
> template <class T> struct iterator_range : std::pair<T, T> { 
>   // assuming you make an is_iterator trait; would be outmoded by concepts 
>   //static_assert(is_iterator_v<T>); 
>
>   using pair::pair; 
>   T begin() { return first; } 
>   T end() { return second; } 
> }; 
>
> template <class T> iterator_range<T> range(std::pair<T, T> rng) { 
>   return iterator_range<T>(rng); 
> } 
>
> //usage 
> 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 : range(it) ) std::cout << p.first << ' ' << p.second 
> << std::endl; 
>
> It is a good example of how you are going to make the life of programmers 
harder.:) 

>
> Short version: I strongly dislike the idea of begin/end for a pair of 
> iterators as that's semantically incorrect and enables 
> dangerous/broken code to compile with other pairs of iterators that 
> don't form a range. 
>
> I can only understand this provided that it is your idea. 
 

> On Thu, Jul 23, 2015 at 12:35 PM, Vlad from Moscow <vlad....@mail.ru 
> <javascript:>> wrote: 
> > How is it related to std:;pair?! You can with the same success use 
> iterators 
> > in any algorithm that do not make a range and what? Do you suggest not 
> to 
> > use algorithms? 
> > 
> > 
> > On Thursday, July 23, 2015 at 10:29:23 PM UTC+3, T. C. wrote: 
> >> 
> >> They existed in an earlier C++0x draft, and were removed by that LWG 
> issue 
> >> before C++11 was published. 
> >> 
> >> Not all pairs of iterators are ranges. Not even all pairs of iterators 
> >> returned by functions in the standard library are ranges, 
> >> as your own code with minmax_element demonstrates. 
> >> 
> >> Besides, a range class that wraps a pair of iterators is trivial to 
> >> implement. 
> >> 
> >> On Thursday, July 23, 2015 at 3:15:05 PM UTC-4, Vlad from Moscow wrote: 
> >>> 
> >>> 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 a topic in the 
> > Google Groups "ISO C++ Standard - Future Proposals" group. 
> > To unsubscribe from this topic, visit 
> > 
> https://groups.google.com/a/isocpp.org/d/topic/std-proposals/z_BtdcvO1NA/unsubscribe. 
>
> > To unsubscribe from this group and all its topics, send an email to 
> > std-proposal...@isocpp.org <javascript:>. 
> > To post to this group, send email to std-pr...@isocpp.org <javascript:>. 
>
> > Visit this group at 
> > http://groups.google.com/a/isocpp.org/group/std-proposals/. 
>
>
>
> -- 
> Sean Middleditch 
> http://seanmiddleditch.com 
>

-- 

--- 
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_1102_811115058.1437682386877
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Thursday, July 23, 2015 at 10:57:30 PM UTC+3, S=
ean Middleditch wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0p=
x 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); =
border-left-width: 1px; border-left-style: solid;">std::pair is not semanti=
cally a range. Treating it as such is wrong.
<br>Period. It _can_ be used as a range, but it would be more correct to
<br>then clearly make a semantic range type for this purpose.
<br>
<br>For member functions like equal_range, those really should return a
<br>proper range type. Returning a pair was (in hindsight) a mistake of
<br>the design. Doubling down on that mistake would just be another
<br>mistake; instead, the mistake should be corrected (whether that means
<br>changing the return type or creating new alternatives).
<br>
<br></blockquote><div>I am sorry but this has no any great sense. As I said=
 early you can use any two iterators by mistake that do not make a range wi=
th any algorithm. For example what=C2=A0does prevent you to write</div><div=
><br></div><div>int a[] =3D { /*...*/ };</div><div>int b[] =3D {=C2=A0/*...=
*/ };</div><div><br></div><div>std::for_each( std::begin(a ), std::and( b )=
, some_function_pointer );</div><div><br></div><div>Or </div><div><br></div=
><div>int m =3D 5;</div><div>int n =3D 2;</div><div>//...</div><div><div>st=
d::for_each(=C2=A0a + m,=C2=A0a + n, some_function_pointer );</div></div><d=
iv>=C2=A0</div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"=
margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 2=
04, 204); border-left-width: 1px; border-left-style: solid;">We can&#39;t r=
etroactively change return types without breaking
<br>compatibility (probably), but the ranges will facilitate either adding
<br>new member functions/algorithms if not an entirely new STL (with
<br>concepts + ranges).
<br><br></blockquote><div>That is where ranges is not neeed you want to lit=
ter the STL with ranges.</div><div>=C2=A0</div><blockquote class=3D"gmail_q=
uote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-co=
lor: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;"=
>Also remember that as Eric N. pointed out, iterator pairs aren&#39;t even
<br>necessarily the best way to model ranges, esp. for some more advanced
<br>containers (instead you want iterator and sentinel type), so the
<br>existing interfaces that return a pair of iterators have yet other
<br>reasons to be replaced with proper ranges anyway.
<br>
<br>If you want your example to work easily and quickly, consider making
<br>your own quick wrapper:
<br>
<br>// wrapper
<br>template &lt;class T&gt; struct iterator_range : std::pair&lt;T, T&gt; =
{
<br>=C2=A0 // assuming you make an is_iterator trait; would be outmoded by =
concepts
<br>=C2=A0 //static_assert(is_iterator_v&lt;T&gt;);
<br>
<br>=C2=A0 using pair::pair;
<br>=C2=A0 T begin() { return first; }
<br>=C2=A0 T end() { return second; }
<br>};
<br>
<br>template &lt;class T&gt; iterator_range&lt;T&gt; range(std::pair&lt;T, =
T&gt; rng) {
<br>=C2=A0 return iterator_range&lt;T&gt;(rng);
<br>}
<br>
<br>//usage
<br>std::multimap&lt;char, std::string&gt; m =3D
<br>=C2=A0 =C2=A0 {
<br>=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 { &#39;B&#39;, &quot;Bee&quot; }, { &#39;B&=
#39;, &quot;Beef&quot; }, {&#39;B&#39;, &quot;Brother&quot; }
<br>=C2=A0 =C2=A0 };
<br>
<br>=C2=A0 =C2=A0 auto it =3D m.equal_range( &#39;A&#39; );
<br>
<br>=C2=A0 =C2=A0 for ( auto p : range(it) ) std::cout &lt;&lt; p.first &lt=
;&lt; &#39; &#39; &lt;&lt; p.second
<br>&lt;&lt; std::endl;
<br>
<br></blockquote><div>It is a good example of how=C2=A0you are going to mak=
e the life of programmers harder.:)=C2=A0</div><blockquote class=3D"gmail_q=
uote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-co=
lor: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;"=
>
<br>Short version: I strongly dislike the idea of begin/end for a pair of
<br>iterators as that&#39;s semantically incorrect and enables
<br>dangerous/broken code to compile with other pairs of iterators that
<br>don&#39;t form a range.
<br>
<br></blockquote><div>I can only=C2=A0understand this provided that it is y=
our idea. </div><div>=C2=A0</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;">On Thu, Jul 2=
3, 2015 at 12:35 PM, Vlad from Moscow &lt;<a onmousedown=3D"this.href=3D&#3=
9;javascript:&#39;;return true;" onclick=3D"this.href=3D&#39;javascript:&#3=
9;;return true;" href=3D"javascript:" target=3D"_blank" rel=3D"nofollow">vl=
ad....@mail.ru</a>&gt; wrote:
<br>&gt; How is it related to std:;pair?! You can with the same success use=
 iterators
<br>&gt; in any algorithm that do not make a range and what? Do you suggest=
 not to
<br>&gt; use algorithms?
<br>&gt;
<br>&gt;
<br>&gt; On Thursday, July 23, 2015 at 10:29:23 PM UTC+3, T. C. wrote:
<br>&gt;&gt;
<br>&gt;&gt; They existed in an earlier C++0x draft, and were removed by th=
at LWG issue
<br>&gt;&gt; before C++11 was published.
<br>&gt;&gt;
<br>&gt;&gt; Not all pairs of iterators are ranges. Not even all pairs of i=
terators
<br>&gt;&gt; returned by functions in the standard library are ranges,
<br>&gt;&gt; as your own code with minmax_element demonstrates.
<br>&gt;&gt;
<br>&gt;&gt; Besides, a range class that wraps a pair of iterators is trivi=
al to
<br>&gt;&gt; implement.
<br>&gt;&gt;
<br>&gt;&gt; On Thursday, July 23, 2015 at 3:15:05 PM UTC-4, Vlad from Mosc=
ow wrote:
<br>&gt;&gt;&gt;
<br>&gt;&gt;&gt; There is nothing said about introducing functions std::beg=
in and std:;end
<br>&gt;&gt;&gt; for std::pair.
<br>&gt;&gt;&gt;
<br>&gt;&gt;&gt; On Thursday, July 23, 2015 at 9:52:23 PM UTC+3, T. C. wrot=
e:
<br>&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt; <a onmousedown=3D"this.href=3D&#39;http://www.google.c=
om/url?q\75http%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Flwg-=
defects.html%231381\46sa\75D\46sntz\0751\46usg\75AFQjCNGCnw-GAV0E1QTFZv90wI=
Fhv-vtdQ&#39;;return true;" onclick=3D"this.href=3D&#39;http://www.google.c=
om/url?q\75http%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Flwg-=
defects.html%231381\46sa\75D\46sntz\0751\46usg\75AFQjCNGCnw-GAV0E1QTFZv90wI=
Fhv-vtdQ&#39;;return true;" href=3D"http://www.open-std.org/jtc1/sc22/wg21/=
docs/lwg-defects.html#1381" target=3D"_blank" rel=3D"nofollow">http://www.o=
pen-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#1381</a>
<br>&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt; On Thursday, July 23, 2015 at 2:30:02 PM UTC-4, Vlad f=
rom Moscow wrote:
<br>&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt; And one more example :)
<br>&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt; #include &lt;iostream&gt;
<br>&gt;&gt;&gt;&gt;&gt; #include &lt;utility&gt;
<br>&gt;&gt;&gt;&gt;&gt; #include &lt;vector&gt;
<br>&gt;&gt;&gt;&gt;&gt; #include &lt;algorithm&gt;
<br>&gt;&gt;&gt;&gt;&gt; #include &lt;iterator&gt;
<br>&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt; namespace std
<br>&gt;&gt;&gt;&gt;&gt; {
<br>&gt;&gt;&gt;&gt;&gt; template &lt;class Iterator&gt;
<br>&gt;&gt;&gt;&gt;&gt; Iterator begin( const std::pair&lt;Iterator, Itera=
tor&gt; &amp;p )
<br>&gt;&gt;&gt;&gt;&gt; {
<br>&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 return p.first;
<br>&gt;&gt;&gt;&gt;&gt; }
<br>&gt;&gt;&gt;&gt;&gt; template &lt;class Iterator&gt;
<br>&gt;&gt;&gt;&gt;&gt; Iterator end( const std::pair&lt;Iterator, Iterato=
r&gt; &amp;p )
<br>&gt;&gt;&gt;&gt;&gt; {
<br>&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 return p.second;
<br>&gt;&gt;&gt;&gt;&gt; }
<br>&gt;&gt;&gt;&gt;&gt; }
<br>&gt;&gt;&gt;&gt;&gt; int main()
<br>&gt;&gt;&gt;&gt;&gt; {
<br>&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 std::vector&lt;int&gt; v =3D { 3, 4,=
 0, 5, 1, 6, 9, 7, 8 };
<br>&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 for ( auto x : v ) std::cout &lt;&lt=
; x &lt;&lt; &#39; &#39;;
<br>&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 std::cout &lt;&lt; std::endl;
<br>&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 auto p =3D std::minmax_element( v.be=
gin(), v.end() );
<br>&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 if ( std::distance( v.begin(), p.sec=
ond ) &lt; std::distance(
<br>&gt;&gt;&gt;&gt;&gt; v.begin(), p.first ) )
<br>&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 {
<br>&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 std::swap( p.first, p.=
second );
<br>&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 }
<br>&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 for ( auto x : p ) std::cout &lt;&lt=
; x &lt;&lt; &#39; &#39;;
<br>&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 std::cout &lt;&lt; std::endl;
<br>&gt;&gt;&gt;&gt;&gt; }
<br>&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt; The program output is
<br>&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt; 3 4 0 5 1 6 9 7 8
<br>&gt;&gt;&gt;&gt;&gt; 0 5 1 6
<br>&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt; On Thursday, July 23, 2015 at 8:57:38 PM UTC+3, Vl=
ad from Moscow wrote:
<br>&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt; Another example
<br>&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt; #include &lt;iostream&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt; #include &lt;utility&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt; #include &lt;vector&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt; namespace std
<br>&gt;&gt;&gt;&gt;&gt;&gt; {
<br>&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt; template &lt;class Iterator&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt; Iterator begin( const std::pair&lt;Iterator, I=
terator&gt; &amp;p )
<br>&gt;&gt;&gt;&gt;&gt;&gt; {
<br>&gt;&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 return p.first;
<br>&gt;&gt;&gt;&gt;&gt;&gt; }
<br>&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt; template &lt;class Iterator&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt; Iterator end( const std::pair&lt;Iterator, Ite=
rator&gt; &amp;p )
<br>&gt;&gt;&gt;&gt;&gt;&gt; {
<br>&gt;&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 return p.second;
<br>&gt;&gt;&gt;&gt;&gt;&gt; }
<br>&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt; }
<br>&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt; int main()
<br>&gt;&gt;&gt;&gt;&gt;&gt; {
<br>&gt;&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 std::vector&lt;int&gt; v =3D { 0=
, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
<br>&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 for ( auto x : std::make_pair( v=
..begin(), v.end() ) ) std::cout &lt;&lt;
<br>&gt;&gt;&gt;&gt;&gt;&gt; x &lt;&lt; &#39; &#39;;
<br>&gt;&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 std::cout &lt;&lt; std::endl;
<br>&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 for ( auto x : std::make_pair( v=
..rbegin(), v.rend() ) ) std::cout
<br>&gt;&gt;&gt;&gt;&gt;&gt; &lt;&lt; x &lt;&lt; &#39; &#39;;
<br>&gt;&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 std::cout &lt;&lt; std::endl;
<br>&gt;&gt;&gt;&gt;&gt;&gt; }
<br>&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt; The program output is
<br>&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt; 0 1 2 3 4 5 6 7 8 9
<br>&gt;&gt;&gt;&gt;&gt;&gt; 9 8 7 6 5 4 3 2 1 0
<br>&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt; Enjoy!:)
<br>&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt; On Thursday, July 23, 2015 at 8:36:46 PM UTC+3=
, Vlad from Moscow
<br>&gt;&gt;&gt;&gt;&gt;&gt; wrote:
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; I&#39;d like to =C2=A0suggest very simple =
and at the same time very useful
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; overloaded functions std::begin and std::e=
nd for standard class std::pair.
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; Here is a demonstrative program of the ide=
a
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; #include &lt;iostream&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; #include &lt;utility&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; namespace std
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; {
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; template &lt;class Iterator&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; Iterator begin( const std::pair&lt;Iterato=
r, Iterator&gt; &amp;p )
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; {
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 return p.first;
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; }
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; template &lt;class Iterator&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; Iterator end( const std::pair&lt;Iterator,=
 Iterator&gt; &amp;p )
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; {
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 return p.second;
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; }
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; }
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; int main()
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; {
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 int a[] =3D { 0, 1, 2, 3, 4,=
 5, 6, 7, 8, 9 };
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 for ( auto x : std::make_pai=
r( a + 3, a + 7 ) ) std::cout &lt;&lt; x &lt;&lt;
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; &#39; &#39;;
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 std::cout &lt;&lt; std::endl=
;
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 int b[][3] =3D { { 1, 2, 3 }=
, { 4, 5, 6 } };
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 for ( auto x : std::make_pai=
r( b[0] + 1, b[1] + 2 ) ) std::cout
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; &lt;&lt; x &lt;&lt; &#39; &#39;;
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; =C2=A0 =C2=A0 std::cout &lt;&lt; std::endl=
;
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; }
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; The program output is
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt;
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; 3 4 5 6
<br>&gt;&gt;&gt;&gt;&gt;&gt;&gt; 2 3 4 5
<br>&gt;
<br>&gt; --
<br>&gt;
<br>&gt; ---
<br>&gt; You received this message because you are subscribed to a topic in=
 the
<br>&gt; Google Groups &quot;ISO C++ Standard - Future Proposals&quot; grou=
p.
<br>&gt; To unsubscribe from this topic, visit
<br>&gt; <a onmousedown=3D"this.href=3D&#39;https://groups.google.com/a/iso=
cpp.org/d/topic/std-proposals/z_BtdcvO1NA/unsubscribe&#39;;return true;" on=
click=3D"this.href=3D&#39;https://groups.google.com/a/isocpp.org/d/topic/st=
d-proposals/z_BtdcvO1NA/unsubscribe&#39;;return true;" href=3D"https://grou=
ps.google.com/a/isocpp.org/d/topic/std-proposals/z_BtdcvO1NA/unsubscribe" t=
arget=3D"_blank" rel=3D"nofollow">https://groups.google.com/a/isocpp.org/d/=
topic/std-proposals/z_BtdcvO1NA/unsubscribe</a>.
<br>&gt; To unsubscribe from this group and all its topics, send an email t=
o
<br>&gt; <a onmousedown=3D"this.href=3D&#39;javascript:&#39;;return true;" =
onclick=3D"this.href=3D&#39;javascript:&#39;;return true;" href=3D"javascri=
pt:" target=3D"_blank" rel=3D"nofollow">std-proposal...@isocpp.org</a>.
<br>&gt; To post to this group, send email to <a onmousedown=3D"this.href=
=3D&#39;javascript:&#39;;return true;" onclick=3D"this.href=3D&#39;javascri=
pt:&#39;;return true;" href=3D"javascript:" target=3D"_blank" rel=3D"nofoll=
ow">std-pr...@isocpp.org</a>.
<br>&gt; Visit this group at
<br>&gt; <a onmousedown=3D"this.href=3D&#39;http://groups.google.com/a/isoc=
pp.org/group/std-proposals/&#39;;return true;" onclick=3D"this.href=3D&#39;=
http://groups.google.com/a/isocpp.org/group/std-proposals/&#39;;return true=
;" href=3D"http://groups.google.com/a/isocpp.org/group/std-proposals/" targ=
et=3D"_blank" rel=3D"nofollow">http://groups.google.com/a/isocpp.org/group/=
std-proposals/</a>.
<br>
<br>
<br>
<br>--=20
<br>Sean Middleditch
<br><a onmousedown=3D"this.href=3D&#39;http://www.google.com/url?q\75http%3=
A%2F%2Fseanmiddleditch.com\46sa\75D\46sntz\0751\46usg\75AFQjCNHx3WLavT-kbTo=
Ov7IL4uvcN5l-vg&#39;;return true;" onclick=3D"this.href=3D&#39;http://www.g=
oogle.com/url?q\75http%3A%2F%2Fseanmiddleditch.com\46sa\75D\46sntz\0751\46u=
sg\75AFQjCNHx3WLavT-kbToOv7IL4uvcN5l-vg&#39;;return true;" href=3D"http://s=
eanmiddleditch.com" target=3D"_blank" rel=3D"nofollow">http://seanmiddledit=
ch.com</a>
<br></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_1102_811115058.1437682386877--
------=_Part_1101_694178070.1437682386877--

.
