Topic: Overloading std::begin and std::end for std::pair


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Thu, 23 Jul 2015 10:36:46 -0700 (PDT)
Raw View
------=_Part_737_309793220.1437673006283
Content-Type: multipart/alternative;
 boundary="----=_Part_738_963777742.1437673006283"

------=_Part_738_963777742.1437673006283
Content-Type: text/plain; charset=UTF-8

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_738_963777742.1437673006283
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>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::e=
nd for standard class std::pair.</div><div><br></div><div>Here is a demonst=
rative program of the idea</div><div><br></div><div>#include &lt;iostream&g=
t;</div><div>#include &lt;utility&gt;</div><div><br></div><div>namespace st=
d<br>{=C2=A0=C2=A0=C2=A0 <br>template &lt;class Iterator&gt;<br>Iterator be=
gin( 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&gt; &amp;p )<br>{<br>=
=C2=A0=C2=A0=C2=A0 return 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::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::ma=
ke_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></di=
v><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>

<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_738_963777742.1437673006283--
------=_Part_737_309793220.1437673006283--

.


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Thu, 23 Jul 2015 10:57:37 -0700 (PDT)
Raw View
------=_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--

.


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Thu, 23 Jul 2015 11:30:02 -0700 (PDT)
Raw View
------=_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--

.


Author: "T. C." <rs2740@gmail.com>
Date: Thu, 23 Jul 2015 11:52:23 -0700 (PDT)
Raw View
------=_Part_756_1165770198.1437677543648
Content-Type: multipart/alternative;
 boundary="----=_Part_757_2023590488.1437677543648"

------=_Part_757_2023590488.1437677543648
Content-Type: text/plain; charset=UTF-8

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_757_2023590488.1437677543648
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defec=
ts.html#1381</div><div><br></div><div><div><br></div><div>On Thursday, July=
 23, 2015 at 2:30:02 PM UTC-4, Vlad from Moscow wrote:<blockquote class=3D"=
gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc so=
lid;padding-left: 1ex;"><div dir=3D"ltr"><div>And one more example :)</div>=
<div><br></div><div>#include &lt;iostream&gt;<br>#include &lt;utility&gt;<b=
r>#include &lt;vector&gt;<br>#include &lt;algorithm&gt;<br>#include &lt;ite=
rator&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;Iter=
ator, 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.sec=
ond;<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() );<br>=C2=
=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0 if ( std::distance( v.begin(), p.sec=
ond ) &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><d=
iv>=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, 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"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,204);bor=
der-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></blockquote></div></div></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_757_2023590488.1437677543648--
------=_Part_756_1165770198.1437677543648--

.


Author: Sean Middleditch <sean.middleditch@gmail.com>
Date: Thu, 23 Jul 2015 12:04:26 -0700 (PDT)
Raw View
------=_Part_1220_396501332.1437678266187
Content-Type: multipart/alternative;
 boundary="----=_Part_1221_222889290.1437678266187"

------=_Part_1221_222889290.1437678266187
Content-Type: text/plain; charset=UTF-8

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_1221_222889290.1437678266187
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">This is solved by ranges (there&#39;s a proposal in flight=
 derived from https://github.com/ericniebler/range-v3). You&#39;re trying t=
o treat std::pair&lt;iterator, iterator&gt; as a range between the two iter=
ators, which is not semantically correct for all possible pairs of iterator=
s. I&#39;d rather just leave pair alone and let the ranges proposal solve t=
his by replacing the handle of STL uses of pair&lt;iterator, iterator&gt; w=
ith a range&lt;iterator&gt;.<div><br></div><div>In your example it&#39;s al=
so solved by array_view, which is really just a form of range.<br><div><br>=
</div><div>An additional nice thing about the ranges is that begin, end, si=
ze, operator[], etc. can all be added to the range type as member functions=
 (as appropriate for the iterator category).<br><br>On Thursday, July 23, 2=
015 at 10:36:46 AM UTC-7, Vlad from Moscow wrote:<blockquote class=3D"gmail=
_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;p=
adding-left: 1ex;"><div dir=3D"ltr"><div>I&#39;d like to =C2=A0suggest very=
 simple and=C2=A0at the same time very useful=C2=A0 overloaded functions st=
d::begin and std::end for standard class std::pair.</div><div><br></div><di=
v>Here is a demonstrative program of the idea</div><div><br></div><div>#inc=
lude &lt;iostream&gt;</div><div>#include &lt;utility&gt;</div><div><br></di=
v><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;clas=
s Iterator&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></=
blockquote></div></div></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_1221_222889290.1437678266187--
------=_Part_1220_396501332.1437678266187--

.


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Thu, 23 Jul 2015 12:15:04 -0700 (PDT)
Raw View
------=_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--

.


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Thu, 23 Jul 2015 12:18:04 -0700 (PDT)
Raw View
------=_Part_759_905092172.1437679084352
Content-Type: multipart/alternative;
 boundary="----=_Part_760_1532103494.1437679084353"

------=_Part_760_1532103494.1437679084353
Content-Type: text/plain; charset=UTF-8

There is nothing solved by ranges. I would prefer to use what I already
have that  is std::pair. I do not need for such tasks new compound classes
as ranges.

And as far as I know array_view does not work with for examples std::map.

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_760_1532103494.1437679084353
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>There is nothing solved by ranges. I would prefer to =
use what I already have that=C2=A0 is std::pair. I do not need for such tas=
ks new compound classes as ranges. <br></div><div><br></div><div>And as far=
 as I know array_view does not work with for examples std::map.</div><div><=
br>On Thursday, July 23, 2015 at 10:04:27 PM UTC+3, Sean Middleditch 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-widt=
h: 1px; border-left-style: solid;"><div dir=3D"ltr">This is solved by range=
s (there&#39;s a proposal in flight derived from <a onmousedown=3D"this.hre=
f=3D&#39;https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Fericnieb=
ler%2Frange-v3\46sa\75D\46sntz\0751\46usg\75AFQjCNF6-7MwmERsjtO_yikBxBOgeh0=
fkA&#39;;return true;" onclick=3D"this.href=3D&#39;https://www.google.com/u=
rl?q\75https%3A%2F%2Fgithub.com%2Fericniebler%2Frange-v3\46sa\75D\46sntz\07=
51\46usg\75AFQjCNF6-7MwmERsjtO_yikBxBOgeh0fkA&#39;;return true;" href=3D"ht=
tps://github.com/ericniebler/range-v3" target=3D"_blank" rel=3D"nofollow">h=
ttps://github.com/ericniebler/range-v3</a>). You&#39;re trying to treat std=
::pair&lt;iterator, iterator&gt; as a range between the two iterators, whic=
h is not semantically correct for all possible pairs of iterators. I&#39;d =
rather just leave pair alone and let the ranges proposal solve this by repl=
acing the handle of STL uses of pair&lt;iterator, iterator&gt; with a range=
&lt;iterator&gt;.<div><br></div><div>In your example it&#39;s also solved b=
y array_view, which is really just a form of range.<br><div><br></div><div>=
An additional nice thing about the ranges is that begin, end, size, operato=
r[], etc. can all be added to the range type as member functions (as approp=
riate for the iterator category).<br><br>On Thursday, July 23, 2015 at 10:3=
6:46 AM UTC-7, Vlad from Moscow wrote:<blockquote class=3D"gmail_quote" sty=
le=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>I&#39;d like to =C2=A0suggest very simple and=C2=A0at the sam=
e time very useful=C2=A0 overloaded functions std::begin and std::end for s=
tandard class std::pair.</div><div><br></div><div>Here is a demonstrative p=
rogram 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 begin( c=
onst 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>Itera=
tor 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></blockquote></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_760_1532103494.1437679084353--
------=_Part_759_905092172.1437679084352--

.


Author: "T. C." <rs2740@gmail.com>
Date: Thu, 23 Jul 2015 12:29:23 -0700 (PDT)
Raw View
------=_Part_1057_1728071093.1437679763642
Content-Type: multipart/alternative;
 boundary="----=_Part_1058_888928744.1437679763643"

------=_Part_1058_888928744.1437679763643
Content-Type: text/plain; charset=UTF-8

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 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_1058_888928744.1437679763643
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">They existed in an earlier C++0x draft, and were removed b=
y that LWG issue before C++11 was published.<div><br></div><div>Not all pai=
rs of iterators are ranges. Not even all pairs of iterators returned by fun=
ctions in the standard library are ranges,</div><div>as your own code with =
minmax_element demonstrates.</div><div><br></div><div>Besides, a range clas=
s that wraps a pair of iterators is trivial to implement.</div><div><br>On =
Thursday, July 23, 2015 at 3:15:05 PM UTC-4, Vlad from Moscow wrote:<blockq=
uote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-lef=
t: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">There is nothing sai=
d about introducing functions std::begin and std:;end for std::pair.<br><br=
>On Thursday, July 23, 2015 at 9:52:23 PM UTC+3, T. C. wrote:<blockquote cl=
ass=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;padding-left:1ex;bord=
er-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:soli=
d"><div dir=3D"ltr"><div><a href=3D"http://www.open-std.org/jtc1/sc22/wg21/=
docs/lwg-defects.html#1381" rel=3D"nofollow" target=3D"_blank" onmousedown=
=3D"this.href=3D&#39;http://www.google.com/url?q\75http%3A%2F%2Fwww.open-st=
d.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Flwg-defects.html%231381\46sa\75D\46sntz=
\0751\46usg\75AFQjCNGCnw-GAV0E1QTFZv90wIFhv-vtdQ&#39;;return true;" onclick=
=3D"this.href=3D&#39;http://www.google.com/url?q\75http%3A%2F%2Fwww.open-st=
d.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Flwg-defects.html%231381\46sa\75D\46sntz=
\0751\46usg\75AFQjCNGCnw-GAV0E1QTFZv90wIFhv-vtdQ&#39;;return true;">http://=
www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#1381</a></div><div><b=
r></div><div><div><br></div><div>On Thursday, July 23, 2015 at 2:30:02 PM U=
TC-4, Vlad from Moscow wrote:<blockquote class=3D"gmail_quote" style=3D"mar=
gin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);b=
order-left-width:1px;border-left-style:solid"><div dir=3D"ltr"><div>And one=
 more example :)</div><div><br></div><div>#include &lt;iostream&gt;<br>#inc=
lude &lt;utility&gt;<br>#include &lt;vector&gt;<br>#include &lt;algorithm&g=
t;<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( c=
onst 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>Itera=
tor 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>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() );<br>=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0 if ( std::dista=
nce( 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::swa=
p( 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 for ( auto x : p ) std::cout =
&lt;&lt; x &lt;&lt; &#39; &#39;;<br>=C2=A0=C2=A0=C2=A0 std::cout &lt;&lt; s=
td::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;p=
adding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;bo=
rder-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>#includ=
e &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>Iterat=
or 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;cla=
ss Iterator&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.beg=
in(), 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><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, Vlad from Moscow wrote:</div><blockquote class=3D=
"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;padding-left:1ex;border-lef=
t-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><di=
v dir=3D"ltr"><div>I&#39;d like to =C2=A0suggest very simple and=C2=A0at th=
e 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 demonstrat=
ive 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<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>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></blockquote></div></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_1058_888928744.1437679763643--
------=_Part_1057_1728071093.1437679763642--

.


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Thu, 23 Jul 2015 12:31:59 -0700 (PDT)
Raw View
------=_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--

.


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Thu, 23 Jul 2015 12:35:12 -0700 (PDT)
Raw View
------=_Part_830_236881370.1437680112775
Content-Type: multipart/alternative;
 boundary="----=_Part_831_1970079006.1437680112775"

------=_Part_831_1970079006.1437680112775
Content-Type: text/plain; charset=UTF-8

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 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_831_1970079006.1437680112775
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">How is it related to std:;pair?! You can with the same suc=
cess use iterators in any algorithm that do not make a range and what? Do y=
ou suggest not to use algorithms?<br><br>On Thursday, July 23, 2015 at 10:2=
9:23 PM UTC+3, T. C. wrote:<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">Th=
ey existed in an earlier C++0x draft, and were removed by that LWG issue be=
fore C++11 was published.<div><br></div><div>Not all pairs of iterators are=
 ranges. Not even all pairs of iterators returned by functions in the stand=
ard library are ranges,</div><div>as your own code with minmax_element demo=
nstrates.</div><div><br></div><div>Besides, a range class that wraps a pair=
 of iterators is trivial to implement.</div><div><br>On Thursday, July 23, =
2015 at 3:15:05 PM UTC-4, Vlad from Moscow wrote:<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"ltr">There is nothing said about introducing functions std::=
begin 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=
: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 20=
4); border-left-width: 1px; border-left-style: solid;"><div dir=3D"ltr"><di=
v><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=
\46sa\75D\46sntz\0751\46usg\75AFQjCNGCnw-GAV0E1QTFZv90wIFhv-vtdQ&#39;;retur=
n true;" 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=
\46sa\75D\46sntz\0751\46usg\75AFQjCNGCnw-GAV0E1QTFZv90wIFhv-vtdQ&#39;;retur=
n true;" href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.ht=
ml#1381" target=3D"_blank" rel=3D"nofollow">http://www.open-std.org/jtc1/sc=
22/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 w=
rote:<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"ltr"><div>And one more exampl=
e :)</div><div><br></div><div>#include &lt;iostream&gt;<br>#include &lt;uti=
lity&gt;<br>#include &lt;vector&gt;<br>#include &lt;algorithm&gt;<br>#inclu=
de &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::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>int main()<br>{<br>=C2=A0=C2=A0=C2=A0 st=
d::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() )=
;<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.s=
econd );<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 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></d=
iv><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><blockquot=
e class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1=
ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-l=
eft-style: solid;"><div dir=3D"ltr"><div>Another example</div><div><br></di=
v><div>#include &lt;iostream&gt;<br>#include &lt;utility&gt;<br>#include &l=
t;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 b=
egin( 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 =
Iterator&gt;<br>Iterator end( const std::pair&lt;Iterator, Iterator&gt; &am=
p;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 s=
td::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::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::e=
ndl;</div><div>}=C2=A0=C2=A0=C2=A0 <br></div><div><br></div><div>The progra=
m 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 a=
t 8:36:46 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"ltr"><div>I&#39;d like to =C2=A0suggest very simple and=C2=
=A0at the same time very useful=C2=A0 overloaded functions std::begin and s=
td::end for standard class std::pair.</div><div><br></div><div>Here is a de=
monstrative program of the idea</div><div><br></div><div>#include &lt;iostr=
eam&gt;</div><div>#include &lt;utility&gt;</div><div><br></div><div>namespa=
ce std<br>{=C2=A0=C2=A0=C2=A0 <br>template &lt;class Iterator&gt;<br>Iterat=
or 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&gt; &amp;p )<br>{<b=
r>=C2=A0=C2=A0=C2=A0 return p.second;<br>}<br>}</div><div><br></div><div>in=
t 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::mak=
e_pair( 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><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></blockquote></div><=
/blockquote></div></div></div></blockquote></div></blockquote></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_831_1970079006.1437680112775--
------=_Part_830_236881370.1437680112775--

.


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Thu, 23 Jul 2015 12:56:54 -0700 (PDT)
Raw View
------=_Part_944_947749181.1437681414495
Content-Type: multipart/alternative;
 boundary="----=_Part_945_1255803407.1437681414496"

------=_Part_945_1255803407.1437681414496
Content-Type: text/plain; charset=UTF-8

Or a modified previous example

#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 key = m.empty() ? '\0' : m.begin()->first;

    while ( key )
    {
        auto it = m.equal_range( key );

        for ( auto p : it ) std::cout << p.first << ' ' << p.second <<
std::endl;
        std::cout << std::endl;

        key = it.second == m.end() ? '\0' : it.second->first;
    };
}

The program output is

A Apple
A Animal
A Amigo

B Bee
B Beef
B Brother

And why do I have to use here some ranges? Is it that to make my life
harder?
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_945_1255803407.1437681414496
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Or a modified previous example</div><div><br></div><d=
iv>#include &lt;iostream&gt;<br>#include &lt;utility&gt;<br>#include &lt;ma=
p&gt;<br>#include &lt;string&gt;</div><div>namespace std<br>{<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>=C2=A0=C2=A0=C2=A0 <br>}</div><div>int main()<br>=
{<br>=C2=A0=C2=A0=C2=A0 std::multimap&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&#3=
9;, &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 key =3D m.empty() ? &#39;\0&#39; : m.begin()-&gt;fi=
rst;<br>=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0 while ( key ) <br>=C2=A0=
=C2=A0=C2=A0 {=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto it =3D m.equal_range( key );<br>=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 for ( auto p : it ) std::cout &lt;&lt; p.first &lt;&lt; &#39; &#3=
9; &lt;&lt; p.second &lt;&lt; std::endl;<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 std::cout &lt;&lt; std::endl;<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 key =3D it.s=
econd =3D=3D m.end() ? &#39;\0&#39; : it.second-&gt;first;<br>=C2=A0=C2=A0=
=C2=A0 };=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <br>}=C2=A0=C2=A0=C2=A0 <br><=
/div><div><br></div><div>The program output is</div><div><br></div><div>A A=
pple<br>A Animal<br>A Amigo<br><br>B Bee<br>B Beef<br>B Brother<br></div><d=
iv><br></div><div>And why do I have to use here some ranges? Is it that to =
make my life harder?<br>On Thursday, July 23, 2015 at 10:04:27 PM UTC+3, Se=
an Middleditch 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">Th=
is is solved by ranges (there&#39;s a proposal in flight derived from <a on=
mousedown=3D"this.href=3D&#39;https://www.google.com/url?q\75https%3A%2F%2F=
github.com%2Fericniebler%2Frange-v3\46sa\75D\46sntz\0751\46usg\75AFQjCNF6-7=
MwmERsjtO_yikBxBOgeh0fkA&#39;;return true;" onclick=3D"this.href=3D&#39;htt=
ps://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Fericniebler%2Frange-=
v3\46sa\75D\46sntz\0751\46usg\75AFQjCNF6-7MwmERsjtO_yikBxBOgeh0fkA&#39;;ret=
urn true;" href=3D"https://github.com/ericniebler/range-v3" target=3D"_blan=
k" rel=3D"nofollow">https://github.com/ericniebler/range-v3</a>). You&#39;r=
e trying to treat std::pair&lt;iterator, iterator&gt; as a range between th=
e two iterators, which is not semantically correct for all possible pairs o=
f iterators. I&#39;d rather just leave pair alone and let the ranges propos=
al solve this by replacing the handle of STL uses of pair&lt;iterator, iter=
ator&gt; with a range&lt;iterator&gt;.<div><br></div><div>In your example i=
t&#39;s also solved by array_view, which is really just a form of range.<br=
><div><br></div><div>An additional nice thing about the ranges is that begi=
n, end, size, operator[], etc. can all be added to the range type as member=
 functions (as appropriate for the iterator category).<br><br>On Thursday, =
July 23, 2015 at 10:36:46 AM UTC-7, Vlad from Moscow wrote:<blockquote clas=
s=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; bo=
rder-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-st=
yle: solid;"><div dir=3D"ltr"><div>I&#39;d like to =C2=A0suggest very simpl=
e and=C2=A0at the same time very useful=C2=A0 overloaded functions std::beg=
in and std::end for standard class std::pair.</div><div><br></div><div>Here=
 is a demonstrative 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;<b=
r>Iterator begin( const std::pair&lt;Iterator, Iterator&gt; &amp;p )<br>{<b=
r>=C2=A0=C2=A0=C2=A0 return p.first;<br>}</div><div>template &lt;class Iter=
ator&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></blockq=
uote></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_945_1255803407.1437681414496--
------=_Part_944_947749181.1437681414495--

.


Author: Sean Middleditch <sean@middleditch.us>
Date: Thu, 23 Jul 2015 12:57:27 -0700
Raw View
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).

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).

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;


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.

On Thu, Jul 23, 2015 at 12:35 PM, Vlad from Moscow <vlad.moscow@mail.ru> 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-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/.



--
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/.

.


Author: "T. C." <rs2740@gmail.com>
Date: Thu, 23 Jul 2015 13:10:56 -0700 (PDT)
Raw View
------=_Part_878_567141446.1437682257087
Content-Type: multipart/alternative;
 boundary="----=_Part_879_1570981853.1437682257087"

------=_Part_879_1570981853.1437682257087
Content-Type: text/plain; charset=UTF-8

There *were* std::begin/end overloads for std::pair. They were removed
before C++11 was published, because the committee decided that they
shouldn't exist, for all the reasons Sean pointed out (also,
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2995.pdf).

Allowing code like `for(auto p : std::minmax_element(b, e)) { /* stuff */
}` to silently compile and cause UB at run time half the time isn't a great
idea, IMO.

Of course, you don't need to convince me, but given the previous rejection
of this idea, the Ranges TS on the horizon, and the trivially implemented
workaround, I'm doubtful that it would find much support in the committee.

On Thursday, July 23, 2015 at 3:35:12 PM UTC-4, Vlad from Moscow 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 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_879_1570981853.1437682257087
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">There *were* std::begin/end overloads for std::pair. They =
were removed before C++11 was published, because the committee decided that=
 they shouldn&#39;t exist, for all the reasons Sean pointed out (also, http=
://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2995.pdf).<div><br></d=
iv><div>Allowing code like `for(auto p : std::minmax_element(b, e)) { /* st=
uff */ }` to silently compile and cause UB at run time half the time isn&#3=
9;t a great idea, IMO.</div><div><br></div><div>Of course, you don&#39;t ne=
ed to convince me, but given the previous rejection of this idea, the Range=
s TS on the horizon, and the trivially implemented workaround, I&#39;m doub=
tful that it would find much support in the committee.<br><div><div><br>On =
Thursday, July 23, 2015 at 3:35:12 PM UTC-4, Vlad from Moscow wrote:<blockq=
uote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-lef=
t: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">How is it related to=
 std:;pair?! You can with the same success use iterators in any algorithm t=
hat do not make a range and what? Do you suggest not to use algorithms?<br>=
<br>On Thursday, July 23, 2015 at 10:29:23 PM UTC+3, T. C. wrote:<blockquot=
e 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">They existed in an earlier C++0x draft, and were re=
moved by that LWG issue before C++11 was published.<div><br></div><div>Not =
all pairs of iterators are ranges. Not even all pairs of iterators returned=
 by functions in the standard library are ranges,</div><div>as your own cod=
e with minmax_element demonstrates.</div><div><br></div><div>Besides, a ran=
ge class that wraps a pair of iterators is trivial to implement.</div><div>=
<br>On Thursday, July 23, 2015 at 3:15:05 PM UTC-4, Vlad from Moscow wrote:=
<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-l=
eft-style:solid"><div dir=3D"ltr">There is nothing said about introducing f=
unctions std::begin 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" s=
tyle=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><a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html=
#1381" rel=3D"nofollow" target=3D"_blank" onmousedown=3D"this.href=3D&#39;h=
ttp://www.google.com/url?q\75http%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2F=
wg21%2Fdocs%2Flwg-defects.html%231381\46sa\75D\46sntz\0751\46usg\75AFQjCNGC=
nw-GAV0E1QTFZv90wIFhv-vtdQ&#39;;return true;" onclick=3D"this.href=3D&#39;h=
ttp://www.google.com/url?q\75http%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2F=
wg21%2Fdocs%2Flwg-defects.html%231381\46sa\75D\46sntz\0751\46usg\75AFQjCNGC=
nw-GAV0E1QTFZv90wIFhv-vtdQ&#39;;return true;">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=
 wrote:<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;b=
order-left-style:solid"><div dir=3D"ltr"><div>And one more example :)</div>=
<div><br></div><div>#include &lt;iostream&gt;<br>#include &lt;utility&gt;<b=
r>#include &lt;vector&gt;<br>#include &lt;algorithm&gt;<br>#include &lt;ite=
rator&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;Iter=
ator, 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.sec=
ond;<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() );<br>=C2=
=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0 if ( std::distance( v.begin(), p.sec=
ond ) &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><d=
iv>=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, 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"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,204);bor=
der-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></blockquote></div></div></div></bl=
ockquote></div></blockquote></div></div></blockquote></div></blockquote></d=
iv></div></div></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_879_1570981853.1437682257087--
------=_Part_878_567141446.1437682257087--

.


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Thu, 23 Jul 2015 13:13:06 -0700 (PDT)
Raw View
------=_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--

.


Author: Sean Middleditch <sean@middleditch.us>
Date: Thu, 23 Jul 2015 15:26:59 -0700
Raw View
--089e010d8358c3d37d051b92628f
Content-Type: text/plain; charset=UTF-8

On Jul 23, 2015 1:13 PM, "Vlad from Moscow" <vlad.moscow@mail.ru> wrote:
>
>
>
> On Thursday, July 23, 2015 at 10:57:30 PM UTC+3, Sean Middleditch wrote:
> 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

Which requires explicitly trying to contort iterators into undefined
behavior, rather than having the library itself legitimize the UB by
providing out of the box bogus operators that pretend all pairs of
iterators are iterable ranges, which they aren't, even in the existing
standard usage.

Good interface design means avoiding handing the user a loaded shotgun
pointed at their feet, even if the user is able to load and clumsily aim
one themselves. Make it easier to do the right thing than it is to do the
wrong thing.

>>
>> 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.

It is most certainly not just me who wants that. I'm just informing you of
directions things are already moving towards. :)

You even want it, according to this thread. You just want "range" to be
spelled "pair of iterators" which is where the contention arises. :p

--

---
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/.

--089e010d8358c3d37d051b92628f
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<p dir=3D"ltr"><br>
On Jul 23, 2015 1:13 PM, &quot;Vlad from Moscow&quot; &lt;<a href=3D"mailto=
:vlad.moscow@mail.ru">vlad.moscow@mail.ru</a>&gt; wrote:<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Thursday, July 23, 2015 at 10:57:30 PM UTC+3, Sean Middleditch wrot=
e:<br>
&gt; I am sorry but this has no any great sense. As I said early you can us=
e any two iterators by mistake that do not make a range with any algorithm.=
 For example what=C2=A0does prevent you to write</p>
<p dir=3D"ltr">Which requires explicitly trying to contort iterators into u=
ndefined behavior, rather than having the library itself legitimize the UB =
by providing out of the box bogus operators that pretend all pairs of itera=
tors are iterable ranges, which they aren&#39;t, even in the existing stand=
ard usage.</p>
<p dir=3D"ltr">Good interface design means avoiding handing the user a load=
ed shotgun pointed at their feet, even if the user is able to load and clum=
sily aim one themselves. Make it easier to do the right thing than it is to=
 do the wrong thing.</p>
<p dir=3D"ltr">&gt;&gt;<br>
&gt;&gt; We can&#39;t retroactively change return types without breaking <b=
r>
&gt;&gt; compatibility (probably), but the ranges will facilitate either ad=
ding <br>
&gt;&gt; new member functions/algorithms if not an entirely new STL (with <=
br>
&gt;&gt; concepts + ranges). <br>
&gt;&gt;<br>
&gt; That is where ranges is not neeed you want to litter the STL with rang=
es.</p>
<p dir=3D"ltr">It is most certainly not just me who wants that. I&#39;m jus=
t informing you of directions things are already moving towards. :)</p>
<p dir=3D"ltr">You even want it, according to this thread. You just want &q=
uot;range&quot; to be spelled &quot;pair of iterators&quot; which is where =
the contention arises. :p<br>
</p>

<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 />

--089e010d8358c3d37d051b92628f--

.


Author: Thiago Macieira <thiago@macieira.org>
Date: Thu, 23 Jul 2015 15:58:18 -0700
Raw View
On Thursday 23 July 2015 12:31:59 Vlad from Moscow wrote:
> Could you explain why do I need some ranges when this program looks clear
> and nice without any ranges?

Because you made it so that std::pair<T, T> is always a range, but that isn't
the case. In fact, I'd argue that most people who think of "iterating" over a
pair expect it to behave as an array of two elements: the first and the second.

I'd expect:

template<typename T> const T* begin(const pair<T, T> &p)
{ return &p.first; }

template<typename T> const T *end(const pair<T, T> &p)
{ return &p.second + 1; }

Which allows me to run:

int main()
{
 for (auto i : std::make_pair(1, 2))
  cout << i << ' ';
 cout << endl;
}

output: 1 2
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

--

---
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/.

.


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Fri, 24 Jul 2015 00:36:04 -0700 (PDT)
Raw View
------=_Part_318_1054327731.1437723364615
Content-Type: multipart/alternative;
 boundary="----=_Part_319_849222971.1437723364615"

------=_Part_319_849222971.1437723364615
Content-Type: text/plain; charset=UTF-8



On Friday, July 24, 2015 at 1:58:22 AM UTC+3, Thiago Macieira wrote:
>
> On Thursday 23 July 2015 12:31:59 Vlad from Moscow wrote:
> > Could you explain why do I need some ranges when this program looks
> clear
> > and nice without any ranges?
>
> Because you made it so that std::pair<T, T> is always a range, but that
> isn't
> the case. In fact, I'd argue that most people who think of "iterating"
> over a
> pair expect it to behave as an array of two elements: the first and the
> second.
>
>
There is a serious logical mistake. If for example two pointers can make up
a range this does not mean that any two pointers is a range or that any
range is two pointers. Even two iterators of the same container or two
pointers of the same array might not make a range.

std::pair is simply a media that can store iterators. It is used in
algorithm std::mismatch where iterators does not make up a range or in the
algorithm or class methods  equal_range where pointers make up a range.

It is a responsibility of the programmer to use appropriate iterators that
are stored in the media.

So you and Sean Middleditch attempts to substitute the meaning of
std::pair for the role like just ranges are false and confuse programmers.
It is responsibility of the programmer to correctly use std::pair in
different situations.

With the same success you can use any valid C++ construction incorrectly.
For example you can return a reference to a local variable of a function.
Does it mean that something wrong with references and the programmers shall
not declare function return types as references?

According to your false logic it follows that the programmers indeed shall
not declare function return types as references

The ptoblem is why should the programmer pay for the means that he totally
need not?

I showed already an example with std::multimap where the code looks clear
and nice. But you are saying: "Stop! Programs must not be so clear and
nice. You have to declare a class hierarchy and use these additional
classes to do a simple and entirely correct thing."

Why do the programmer have to use a suoerstructure when he already has a
range that he stored on such a media like std::pair?

And moreover now Sean Middleditch is even going to deform standard
algorithms with the only purpose that all programmers used his useless
superstructures where all can be done simply and clear without them.


I'd expect:
>
> template<typename T> const T* begin(const pair<T, T> &p)
> { return &p.first; }
>
> template<typename T> const T *end(const pair<T, T> &p)
> { return &p.second + 1; }
>
> Which allows me to run:
>
> int main()
> {
>         for (auto i : std::make_pair(1, 2))
>                 cout << i << ' ';
>         cout << endl;
> }
>
> output: 1 2
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>    Software Architect - Intel Open Source Technology Center
>       PGP/GPG: 0x6EF45358; fingerprint:
>       E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
>
>

--

---
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_319_849222971.1437723364615
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Friday, July 24, 2015 at 1:58:22 AM UTC+3, Thia=
go Macieira wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0px 0p=
x 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); bord=
er-left-width: 1px; border-left-style: solid;">On Thursday 23 July 2015 12:=
31:59 Vlad from Moscow wrote:
<br>&gt; Could you explain why do I need some ranges when this program look=
s clear=20
<br>&gt; and nice without any ranges?
<br>
<br>Because you made it so that std::pair&lt;T, T&gt; is always a range, bu=
t that isn&#39;t=20
<br>the case. In fact, I&#39;d argue that most people who think of &quot;it=
erating&quot; over a=20
<br>pair expect it to behave as an array of two elements: the first and the=
 second.
<br>
<br></blockquote><div><br>There is a serious logical mistake. If for exampl=
e two pointers can make up a range this does not mean that any two pointers=
 is a range or that any range is two pointers. Even two iterators of the sa=
me container or two pointers of the same array might not make a range.</div=
><div><br></div><div>std::pair is simply a media that can store iterators. =
It is used in algorithm std::mismatch where iterators does not make up a ra=
nge or in the algorithm or class methods=C2=A0 equal_range where pointers m=
ake up a range.</div><div><br></div><div>It is a responsibility of the prog=
rammer to use appropriate iterators that are stored in the media.</div><div=
><br></div><div>So you and Sean Middleditch attempts to substitute the mean=
ing of=C2=A0 std::pair for the role like just ranges are false and confuse =
programmers.</div><div>It is responsibility of the programmer to correctly =
use std::pair in different situations.</div><div>=C2=A0</div><div>With the =
same success you can use any valid C++ construction incorrectly. For exampl=
e you can return a reference to a local variable of a function. Does it mea=
n that something wrong with references and the programmers shall not declar=
e function return types as references? </div><div><br></div><div>According =
to your false logic it follows that the programmers indeed shall not declar=
e function return types as references</div><div><br></div><div>The ptoblem =
is why should the programmer pay for the means that he totally need not?</d=
iv><div><br></div><div>I showed already an example with std::multimap where=
 the code looks clear and nice. But you are saying: &quot;Stop! Programs mu=
st not be so clear and nice. You have to declare a class hierarchy and use =
these additional classes to do a simple and entirely correct thing.&quot;</=
div><div><br></div><div>Why do the programmer have to use a suoerstructure =
when he already has a range that he stored on such a media like std::pair?<=
/div><div><br></div><div>And moreover now Sean Middleditch is even going to=
 deform standard algorithms with the only purpose that all programmers used=
 his useless superstructures where all can be done simply and clear without=
 them. </div><div><br></div><div><br></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;">I&#=
39;d expect:
<br>
<br>template&lt;typename T&gt; const T* begin(const pair&lt;T, T&gt; &amp;p=
)
<br>{ return &amp;p.first; }
<br>
<br>template&lt;typename T&gt; const T *end(const pair&lt;T, T&gt; &amp;p)
<br>{ return &amp;p.second + 1; }
<br>
<br>Which allows me to run:
<br>
<br>int main()
<br>{
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0for (auto i : std::make=
_pair(1, 2))
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0cout &lt;&lt; i &lt;&lt; &#39; &#39;;
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0cout &lt;&lt; endl;
<br>}
<br>
<br>output: 1 2
<br>--=20
<br>Thiago Macieira - thiago (AT) <a onmousedown=3D"this.href=3D&#39;http:/=
/www.google.com/url?q\75http%3A%2F%2Fmacieira.info\46sa\75D\46sntz\0751\46u=
sg\75AFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;return true;" onclick=3D"this.=
href=3D&#39;http://www.google.com/url?q\75http%3A%2F%2Fmacieira.info\46sa\7=
5D\46sntz\0751\46usg\75AFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;return true;=
" href=3D"http://macieira.info" target=3D"_blank" rel=3D"nofollow">macieira=
..info</a> - thiago (AT) <a onmousedown=3D"this.href=3D&#39;http://www.googl=
e.com/url?q\75http%3A%2F%2Fkde.org\46sa\75D\46sntz\0751\46usg\75AFQjCNHGRJd=
o5_JYG1DowztwAHAKs80XSA&#39;;return true;" onclick=3D"this.href=3D&#39;http=
://www.google.com/url?q\75http%3A%2F%2Fkde.org\46sa\75D\46sntz\0751\46usg\7=
5AFQjCNHGRJdo5_JYG1DowztwAHAKs80XSA&#39;;return true;" href=3D"http://kde.o=
rg" target=3D"_blank" rel=3D"nofollow">kde.org</a>
<br>=C2=A0 =C2=A0Software Architect - Intel Open Source Technology Center
<br>=C2=A0 =C2=A0 =C2=A0 PGP/GPG: 0x6EF45358; fingerprint:
<br>=C2=A0 =C2=A0 =C2=A0 E067 918B B660 DBD1 105C =C2=A0966C 33F5 F005 6EF4=
 5358
<br>
<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_319_849222971.1437723364615--
------=_Part_318_1054327731.1437723364615--

.


Author: Sasha Unknown <sasha2048@gmail.com>
Date: Fri, 24 Jul 2015 15:50:54 +0300
Raw View
To T. C. and Sean Middleditch: Thank you for you patience. While I
don't like the this proposal of Vlad from Moscow for many reasons, I
appreciate patience and level of detail in your responses. At some
point in future these patience and detail-level may save some good but
ugly-looking proposal.

To Vlad from Moscow:
1. Just to satisfy my interest: Aren't you coming to C++ from some
dynamically-typed language?
2. If n2995 and/or D4128 would be accepted, they will satisfy all your requests:
    for ( auto x : std::make_range( a + 3, a + 7 ) ) ...;
    for ( auto p : m.equal_range( 'A' ) ) ...;

On Fri, Jul 24, 2015 at 10:36 AM, Vlad from Moscow <vlad.moscow@mail.ru> wrote:
>
>
> On Friday, July 24, 2015 at 1:58:22 AM UTC+3, Thiago Macieira wrote:
>>
>> On Thursday 23 July 2015 12:31:59 Vlad from Moscow wrote:
>> > Could you explain why do I need some ranges when this program looks
>> > clear
>> > and nice without any ranges?
>>
>> Because you made it so that std::pair<T, T> is always a range, but that
>> isn't
>> the case. In fact, I'd argue that most people who think of "iterating"
>> over a
>> pair expect it to behave as an array of two elements: the first and the
>> second.
>>
>
> There is a serious logical mistake. If for example two pointers can make up
> a range this does not mean that any two pointers is a range or that any
> range is two pointers. Even two iterators of the same container or two
> pointers of the same array might not make a range.
>
> std::pair is simply a media that can store iterators. It is used in
> algorithm std::mismatch where iterators does not make up a range or in the
> algorithm or class methods  equal_range where pointers make up a range.
>
> It is a responsibility of the programmer to use appropriate iterators that
> are stored in the media.
>
> So you and Sean Middleditch attempts to substitute the meaning of  std::pair
> for the role like just ranges are false and confuse programmers.
> It is responsibility of the programmer to correctly use std::pair in
> different situations.
>
> With the same success you can use any valid C++ construction incorrectly.
> For example you can return a reference to a local variable of a function.
> Does it mean that something wrong with references and the programmers shall
> not declare function return types as references?
>
> According to your false logic it follows that the programmers indeed shall
> not declare function return types as references
>
> The ptoblem is why should the programmer pay for the means that he totally
> need not?
>
> I showed already an example with std::multimap where the code looks clear
> and nice. But you are saying: "Stop! Programs must not be so clear and nice.
> You have to declare a class hierarchy and use these additional classes to do
> a simple and entirely correct thing."
>
> Why do the programmer have to use a suoerstructure when he already has a
> range that he stored on such a media like std::pair?
>
> And moreover now Sean Middleditch is even going to deform standard
> algorithms with the only purpose that all programmers used his useless
> superstructures where all can be done simply and clear without them.
>
>
>> I'd expect:
>>
>> template<typename T> const T* begin(const pair<T, T> &p)
>> { return &p.first; }
>>
>> template<typename T> const T *end(const pair<T, T> &p)
>> { return &p.second + 1; }
>>
>> Which allows me to run:
>>
>> int main()
>> {
>>         for (auto i : std::make_pair(1, 2))
>>                 cout << i << ' ';
>>         cout << endl;
>> }
>>
>> output: 1 2
>> --
>> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>>    Software Architect - Intel Open Source Technology Center
>>       PGP/GPG: 0x6EF45358; fingerprint:
>>       E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
>>
> --
>
> ---
> 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/.

--

---
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/.

.


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Fri, 24 Jul 2015 06:10:03 -0700 (PDT)
Raw View
------=_Part_686_1349645481.1437743403415
Content-Type: multipart/alternative;
 boundary="----=_Part_687_1594186586.1437743403416"

------=_Part_687_1594186586.1437743403416
Content-Type: text/plain; charset=UTF-8



On Friday, July 24, 2015 at 3:50:58 PM UTC+3, Sasha Unknown wrote:
>
> To T. C. and Sean Middleditch: Thank you for you patience. While I
> don't like the this proposal of Vlad from Moscow for many reasons, I
> appreciate patience and level of detail in your responses. At some
> point in future these patience and detail-level may save some good but
> ugly-looking proposal.
>
> To Vlad from Moscow:
> 1. Just to satisfy my interest: Aren't you coming to C++ from some
> dynamically-typed language?
> 2. If n2995 and/or D4128 would be accepted, they will satisfy all your
> requests:
>     for ( auto x : std::make_range( a + 3, a + 7 ) ) ...;
>     for ( auto p : m.equal_range( 'A' ) ) ...;
>
>
It seems you do not understand. There is no any need to build a
superconstruction or to deform algorithms that to do this in clear and
natural way.

The C++ Standard already has all needed to do the task.  And if you have a
pair of iterators that make up a range then why do you need to build a
range from already existent valid range?! Simply write

    for ( auto x : p ) ...;

There is such principle KISS in programming that means Keep It Simple
Stupid.

The programmer should not pay for what he totally need not.

What you are suggesting looks the following way. I have a notebook. You
come to my home take away my notebook and say: "Pay me and i will give you
a notebook". And after I paid you return me my notebook.

Excelent idea!




On Fri, Jul 24, 2015 at 10:36 AM, Vlad from Moscow <vlad....@mail.ru
> <javascript:>> wrote:
> >
> >
> > On Friday, July 24, 2015 at 1:58:22 AM UTC+3, Thiago Macieira wrote:
> >>
> >> On Thursday 23 July 2015 12:31:59 Vlad from Moscow wrote:
> >> > Could you explain why do I need some ranges when this program looks
> >> > clear
> >> > and nice without any ranges?
> >>
> >> Because you made it so that std::pair<T, T> is always a range, but that
> >> isn't
> >> the case. In fact, I'd argue that most people who think of "iterating"
> >> over a
> >> pair expect it to behave as an array of two elements: the first and the
> >> second.
> >>
> >
> > There is a serious logical mistake. If for example two pointers can make
> up
> > a range this does not mean that any two pointers is a range or that any
> > range is two pointers. Even two iterators of the same container or two
> > pointers of the same array might not make a range.
> >
> > std::pair is simply a media that can store iterators. It is used in
> > algorithm std::mismatch where iterators does not make up a range or in
> the
> > algorithm or class methods  equal_range where pointers make up a range.
> >
> > It is a responsibility of the programmer to use appropriate iterators
> that
> > are stored in the media.
> >
> > So you and Sean Middleditch attempts to substitute the meaning of
>  std::pair
> > for the role like just ranges are false and confuse programmers.
> > It is responsibility of the programmer to correctly use std::pair in
> > different situations.
> >
> > With the same success you can use any valid C++ construction
> incorrectly.
> > For example you can return a reference to a local variable of a
> function.
> > Does it mean that something wrong with references and the programmers
> shall
> > not declare function return types as references?
> >
> > According to your false logic it follows that the programmers indeed
> shall
> > not declare function return types as references
> >
> > The ptoblem is why should the programmer pay for the means that he
> totally
> > need not?
> >
> > I showed already an example with std::multimap where the code looks
> clear
> > and nice. But you are saying: "Stop! Programs must not be so clear and
> nice.
> > You have to declare a class hierarchy and use these additional classes
> to do
> > a simple and entirely correct thing."
> >
> > Why do the programmer have to use a suoerstructure when he already has a
> > range that he stored on such a media like std::pair?
> >
> > And moreover now Sean Middleditch is even going to deform standard
> > algorithms with the only purpose that all programmers used his useless
> > superstructures where all can be done simply and clear without them.
> >
> >
> >> I'd expect:
> >>
> >> template<typename T> const T* begin(const pair<T, T> &p)
> >> { return &p.first; }
> >>
> >> template<typename T> const T *end(const pair<T, T> &p)
> >> { return &p.second + 1; }
> >>
> >> Which allows me to run:
> >>
> >> int main()
> >> {
> >>         for (auto i : std::make_pair(1, 2))
> >>                 cout << i << ' ';
> >>         cout << endl;
> >> }
> >>
> >> output: 1 2
> >> --
> >> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> >>    Software Architect - Intel Open Source Technology Center
> >>       PGP/GPG: 0x6EF45358; fingerprint:
> >>       E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
> >>
> > --
> >
> > ---
> > 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-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/.
>

--

---
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_687_1594186586.1437743403416
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Friday, July 24, 2015 at 3:50:58 PM UTC+3, Sash=
a Unknown wrote:<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;">To T. C. and Sean Middleditch:=
 Thank you for you patience. While I
<br>don&#39;t like the this proposal of Vlad from Moscow for many reasons, =
I
<br>appreciate patience and level of detail in your responses. At some
<br>point in future these patience and detail-level may save some good but
<br>ugly-looking proposal.
<br>
<br>To Vlad from Moscow:
<br>1. Just to satisfy my interest: Aren&#39;t you coming to C++ from some
<br>dynamically-typed language?
<br>2. If n2995 and/or D4128 would be accepted, they will satisfy all your =
requests:
<br>=C2=A0 =C2=A0 for ( auto x : std::make_range( a + 3, a + 7 ) ) ...;
<br>=C2=A0 =C2=A0 for ( auto p : m.equal_range( &#39;A&#39; ) ) ...;
<br>
<br></blockquote><div><br></div><div>It seems you do not understand. There =
is no any need to=C2=A0build a superconstruction or to deform algorithms th=
at to do this in clear and natural way.</div><div><br></div><div>The C++ St=
andard already has all=C2=A0needed to do the task.=C2=A0 And if you have a =
pair of iterators that make up a range then why do you need to build a rang=
e from already existent valid range?! Simply write</div><div><br></div><div=
>=C2=A0=C2=A0=C2=A0 for ( auto=C2=A0x :=C2=A0p ) ...; </div><div><br></div>=
<div>There is such principle KISS in programming that means Keep It Simple =
Stupid.</div><div><br></div><div>The=C2=A0programmer should not pay for wha=
t he totally need not.</div><div><br></div><div>What you are suggesting loo=
ks the following way. I have a notebook. You come to my home take away my n=
otebook and say: &quot;Pay me and i will give you a notebook&quot;. And aft=
er I paid you=C2=A0return me my notebook.</div><div><br></div><div>Excelent=
 idea!</div><div><br></div><div><br></div><div><br></div><div><br></div><bl=
ockquote 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; b=
order-left-style: solid;">On Fri, Jul 24, 2015 at 10:36 AM, Vlad from Mosco=
w &lt;<a onmousedown=3D"this.href=3D&#39;javascript:&#39;;return true;" onc=
lick=3D"this.href=3D&#39;javascript:&#39;;return true;" href=3D"javascript:=
" target=3D"_blank" rel=3D"nofollow">vlad....@mail.ru</a>&gt; wrote:
<br>&gt;
<br>&gt;
<br>&gt; On Friday, July 24, 2015 at 1:58:22 AM UTC+3, Thiago Macieira wrot=
e:
<br>&gt;&gt;
<br>&gt;&gt; On Thursday 23 July 2015 12:31:59 Vlad from Moscow wrote:
<br>&gt;&gt; &gt; Could you explain why do I need some ranges when this pro=
gram looks
<br>&gt;&gt; &gt; clear
<br>&gt;&gt; &gt; and nice without any ranges?
<br>&gt;&gt;
<br>&gt;&gt; Because you made it so that std::pair&lt;T, T&gt; is always a =
range, but that
<br>&gt;&gt; isn&#39;t
<br>&gt;&gt; the case. In fact, I&#39;d argue that most people who think of=
 &quot;iterating&quot;
<br>&gt;&gt; over a
<br>&gt;&gt; pair expect it to behave as an array of two elements: the firs=
t and the
<br>&gt;&gt; second.
<br>&gt;&gt;
<br>&gt;
<br>&gt; There is a serious logical mistake. If for example two pointers ca=
n make up
<br>&gt; a range this does not mean that any two pointers is a range or tha=
t any
<br>&gt; range is two pointers. Even two iterators of the same container or=
 two
<br>&gt; pointers of the same array might not make a range.
<br>&gt;
<br>&gt; std::pair is simply a media that can store iterators. It is used i=
n
<br>&gt; algorithm std::mismatch where iterators does not make up a range o=
r in the
<br>&gt; algorithm or class methods =C2=A0equal_range where pointers make u=
p a range.
<br>&gt;
<br>&gt; It is a responsibility of the programmer to use appropriate iterat=
ors that
<br>&gt; are stored in the media.
<br>&gt;
<br>&gt; So you and Sean Middleditch attempts to substitute the meaning of =
=C2=A0std::pair
<br>&gt; for the role like just ranges are false and confuse programmers.
<br>&gt; It is responsibility of the programmer to correctly use std::pair =
in
<br>&gt; different situations.
<br>&gt;
<br>&gt; With the same success you can use any valid C++ construction incor=
rectly.
<br>&gt; For example you can return a reference to a local variable of a fu=
nction.
<br>&gt; Does it mean that something wrong with references and the programm=
ers shall
<br>&gt; not declare function return types as references?
<br>&gt;
<br>&gt; According to your false logic it follows that the programmers inde=
ed shall
<br>&gt; not declare function return types as references
<br>&gt;
<br>&gt; The ptoblem is why should the programmer pay for the means that he=
 totally
<br>&gt; need not?
<br>&gt;
<br>&gt; I showed already an example with std::multimap where the code look=
s clear
<br>&gt; and nice. But you are saying: &quot;Stop! Programs must not be so =
clear and nice.
<br>&gt; You have to declare a class hierarchy and use these additional cla=
sses to do
<br>&gt; a simple and entirely correct thing.&quot;
<br>&gt;
<br>&gt; Why do the programmer have to use a suoerstructure when he already=
 has a
<br>&gt; range that he stored on such a media like std::pair?
<br>&gt;
<br>&gt; And moreover now Sean Middleditch is even going to deform standard
<br>&gt; algorithms with the only purpose that all programmers used his use=
less
<br>&gt; superstructures where all can be done simply and clear without the=
m.
<br>&gt;
<br>&gt;
<br>&gt;&gt; I&#39;d expect:
<br>&gt;&gt;
<br>&gt;&gt; template&lt;typename T&gt; const T* begin(const pair&lt;T, T&g=
t; &amp;p)
<br>&gt;&gt; { return &amp;p.first; }
<br>&gt;&gt;
<br>&gt;&gt; template&lt;typename T&gt; const T *end(const pair&lt;T, T&gt;=
 &amp;p)
<br>&gt;&gt; { return &amp;p.second + 1; }
<br>&gt;&gt;
<br>&gt;&gt; Which allows me to run:
<br>&gt;&gt;
<br>&gt;&gt; int main()
<br>&gt;&gt; {
<br>&gt;&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 for (auto i : std::make_pair(1, 2)=
)
<br>&gt;&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 cout &=
lt;&lt; i &lt;&lt; &#39; &#39;;
<br>&gt;&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 cout &lt;&lt; endl;
<br>&gt;&gt; }
<br>&gt;&gt;
<br>&gt;&gt; output: 1 2
<br>&gt;&gt; --
<br>&gt;&gt; Thiago Macieira - thiago (AT) <a onmousedown=3D"this.href=3D&#=
39;http://www.google.com/url?q\75http%3A%2F%2Fmacieira.info\46sa\75D\46sntz=
\0751\46usg\75AFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;return true;" onclick=
=3D"this.href=3D&#39;http://www.google.com/url?q\75http%3A%2F%2Fmacieira.in=
fo\46sa\75D\46sntz\0751\46usg\75AFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;ret=
urn true;" href=3D"http://macieira.info" target=3D"_blank" rel=3D"nofollow"=
>macieira.info</a> - thiago (AT) <a onmousedown=3D"this.href=3D&#39;http://=
www.google.com/url?q\75http%3A%2F%2Fkde.org\46sa\75D\46sntz\0751\46usg\75AF=
QjCNHGRJdo5_JYG1DowztwAHAKs80XSA&#39;;return true;" onclick=3D"this.href=3D=
&#39;http://www.google.com/url?q\75http%3A%2F%2Fkde.org\46sa\75D\46sntz\075=
1\46usg\75AFQjCNHGRJdo5_JYG1DowztwAHAKs80XSA&#39;;return true;" href=3D"htt=
p://kde.org" target=3D"_blank" rel=3D"nofollow">kde.org</a>
<br>&gt;&gt; =C2=A0 =C2=A0Software Architect - Intel Open Source Technology=
 Center
<br>&gt;&gt; =C2=A0 =C2=A0 =C2=A0 PGP/GPG: 0x6EF45358; fingerprint:
<br>&gt;&gt; =C2=A0 =C2=A0 =C2=A0 E067 918B B660 DBD1 105C =C2=A0966C 33F5 =
F005 6EF4 5358
<br>&gt;&gt;
<br>&gt; --
<br>&gt;
<br>&gt; ---
<br>&gt; You received this message because you are subscribed to the Google=
 Groups
<br>&gt; &quot;ISO C++ Standard - Future Proposals&quot; group.
<br>&gt; To unsubscribe from this group and stop receiving emails from it, =
send an
<br>&gt; email to <a onmousedown=3D"this.href=3D&#39;javascript:&#39;;retur=
n true;" onclick=3D"this.href=3D&#39;javascript:&#39;;return true;" href=3D=
"javascript:" 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></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_687_1594186586.1437743403416--
------=_Part_686_1349645481.1437743403415--

.


Author: inkwizytoryankes@gmail.com
Date: Fri, 24 Jul 2015 11:59:16 -0700 (PDT)
Raw View
------=_Part_439_767270575.1437764356352
Content-Type: multipart/alternative;
 boundary="----=_Part_440_2084545534.1437764356354"

------=_Part_440_2084545534.1437764356354
Content-Type: text/plain; charset=UTF-8

If some object have `begin` and `end` then its range. Most pair aren't
ranges then they should not have this functions.
If some objects don't give you guarantees about something but you know in
some cases it true then proper way of use is EXPLICITLY show that it hold
true.
In our case `std::make_range` fulfill this requirements.

Probably solution for this problem are tagged pairs and tuples (IIRC they
are form range proposition).
It look something like that:

extern int tab[10];

std::pair<std::begin_tag<int*>, std::end_tag<int*>> a;
std::pair<std::ptr_tag<int*>, std::success_tag<bool>> b;

a.begin() = tab; //equal a.first = tab;
a.end() = tab + 10; //equal a.second = tab + 10;
for (auto& x : a)
{
    if (x == 5)
    {
        b.ptr() = &x;
        b.success() = true;
    }
}
return b;




On Friday, July 24, 2015 at 3:10:03 PM UTC+2, Vlad from Moscow wrote:
>
>
>
> On Friday, July 24, 2015 at 3:50:58 PM UTC+3, Sasha Unknown wrote:
>>
>> To T. C. and Sean Middleditch: Thank you for you patience. While I
>> don't like the this proposal of Vlad from Moscow for many reasons, I
>> appreciate patience and level of detail in your responses. At some
>> point in future these patience and detail-level may save some good but
>> ugly-looking proposal.
>>
>> To Vlad from Moscow:
>> 1. Just to satisfy my interest: Aren't you coming to C++ from some
>> dynamically-typed language?
>> 2. If n2995 and/or D4128 would be accepted, they will satisfy all your
>> requests:
>>     for ( auto x : std::make_range( a + 3, a + 7 ) ) ...;
>>     for ( auto p : m.equal_range( 'A' ) ) ...;
>>
>>
> It seems you do not understand. There is no any need to build a
> superconstruction or to deform algorithms that to do this in clear and
> natural way.
>
> The C++ Standard already has all needed to do the task.  And if you have a
> pair of iterators that make up a range then why do you need to build a
> range from already existent valid range?! Simply write
>
>     for ( auto x : p ) ...;
>
> There is such principle KISS in programming that means Keep It Simple
> Stupid.
>
> The programmer should not pay for what he totally need not.
>
> What you are suggesting looks the following way. I have a notebook. You
> come to my home take away my notebook and say: "Pay me and i will give you
> a notebook". And after I paid you return me my notebook.
>
> Excelent idea!
>
>
>
>
> On Fri, Jul 24, 2015 at 10:36 AM, Vlad from Moscow <vlad....@mail.ru>
>> wrote:
>> >
>> >
>> > On Friday, July 24, 2015 at 1:58:22 AM UTC+3, Thiago Macieira wrote:
>> >>
>> >> On Thursday 23 July 2015 12:31:59 Vlad from Moscow wrote:
>> >> > Could you explain why do I need some ranges when this program looks
>> >> > clear
>> >> > and nice without any ranges?
>> >>
>> >> Because you made it so that std::pair<T, T> is always a range, but
>> that
>> >> isn't
>> >> the case. In fact, I'd argue that most people who think of "iterating"
>> >> over a
>> >> pair expect it to behave as an array of two elements: the first and
>> the
>> >> second.
>> >>
>> >
>> > There is a serious logical mistake. If for example two pointers can
>> make up
>> > a range this does not mean that any two pointers is a range or that any
>> > range is two pointers. Even two iterators of the same container or two
>> > pointers of the same array might not make a range.
>> >
>> > std::pair is simply a media that can store iterators. It is used in
>> > algorithm std::mismatch where iterators does not make up a range or in
>> the
>> > algorithm or class methods  equal_range where pointers make up a range.
>> >
>> > It is a responsibility of the programmer to use appropriate iterators
>> that
>> > are stored in the media.
>> >
>> > So you and Sean Middleditch attempts to substitute the meaning of
>>  std::pair
>> > for the role like just ranges are false and confuse programmers.
>> > It is responsibility of the programmer to correctly use std::pair in
>> > different situations.
>> >
>> > With the same success you can use any valid C++ construction
>> incorrectly.
>> > For example you can return a reference to a local variable of a
>> function.
>> > Does it mean that something wrong with references and the programmers
>> shall
>> > not declare function return types as references?
>> >
>> > According to your false logic it follows that the programmers indeed
>> shall
>> > not declare function return types as references
>> >
>> > The ptoblem is why should the programmer pay for the means that he
>> totally
>> > need not?
>> >
>> > I showed already an example with std::multimap where the code looks
>> clear
>> > and nice. But you are saying: "Stop! Programs must not be so clear and
>> nice.
>> > You have to declare a class hierarchy and use these additional classes
>> to do
>> > a simple and entirely correct thing."
>> >
>> > Why do the programmer have to use a suoerstructure when he already has
>> a
>> > range that he stored on such a media like std::pair?
>> >
>> > And moreover now Sean Middleditch is even going to deform standard
>> > algorithms with the only purpose that all programmers used his useless
>> > superstructures where all can be done simply and clear without them.
>> >
>> >
>> >> I'd expect:
>> >>
>> >> template<typename T> const T* begin(const pair<T, T> &p)
>> >> { return &p.first; }
>> >>
>> >> template<typename T> const T *end(const pair<T, T> &p)
>> >> { return &p.second + 1; }
>> >>
>> >> Which allows me to run:
>> >>
>> >> int main()
>> >> {
>> >>         for (auto i : std::make_pair(1, 2))
>> >>                 cout << i << ' ';
>> >>         cout << endl;
>> >> }
>> >>
>> >> output: 1 2
>> >> --
>> >> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>> >>    Software Architect - Intel Open Source Technology Center
>> >>       PGP/GPG: 0x6EF45358; fingerprint:
>> >>       E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
>> >>
>> > --
>> >
>> > ---
>> > 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-proposal...@isocpp.org.
>> > To post to this group, send email to std-pr...@isocpp.org.
>> > Visit this group at
>> > http://groups.google.com/a/isocpp.org/group/std-proposals/.
>>
>

--

---
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_440_2084545534.1437764356354
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">If some object have `begin` and `end` then its range. Most=
 pair aren&#39;t ranges then they should not have this functions.<br>If som=
e objects don&#39;t give you guarantees about something but you know in som=
e cases it true then proper way of use is EXPLICITLY show that it hold true=
..<br>In our case `std::make_range` fulfill this requirements.<br><br>Probab=
ly solution for this problem are tagged pairs and tuples (IIRC they are for=
m range proposition).<br>It look something like that:<br><div class=3D"pret=
typrint" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(1=
87, 187, 187); border-style: solid; border-width: 1px; word-wrap: break-wor=
d;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">extern</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> tab</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">[</span><span style=3D"color: #066;" class=3D"styled-by-pret=
tify">10</span><span style=3D"color: #660;" class=3D"styled-by-prettify">];=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>st=
d</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">pair</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">std</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">begin_tag</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">int</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">*&gt;,</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
end_tag</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt=
;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">*&gt;&gt;</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> a</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>std</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify">pair</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">std</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">ptr_tag</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
&lt;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">int</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">*&gt;,</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">success_tag</span><span style=
=3D"color: #080;" class=3D"styled-by-prettify">&lt;bool&gt;</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> b</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br><br>a</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">.</span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">begin</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> tab</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #800;" class=3D"styled-by-prettify">//equal a.first =3D tab;</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>a</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">end</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> tab </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">+</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #066;" class=3D"styled-by-prettify">10</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #8=
00;" class=3D"styled-by-prettify">//equal a.second =3D tab + 10;</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">for</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">auto</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">&amp;</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> x </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> a<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">if</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">x </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">=3D=3D</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettif=
y">5</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=
=A0 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 b</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
ptr</span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify">x</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 b</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">success</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">true</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">return</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> b</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">;</span></div></code></div><br><br><br><br>On Friday, July=
 24, 2015 at 3:10:03 PM UTC+2, Vlad from Moscow wrote:<blockquote class=3D"=
gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc so=
lid;padding-left: 1ex;"><div dir=3D"ltr"><br><br>On Friday, July 24, 2015 a=
t 3:50:58 PM UTC+3, Sasha Unknown wrote:<blockquote class=3D"gmail_quote" s=
tyle=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">To T. C. and Sean =
Middleditch: Thank you for you patience. While I
<br>don&#39;t like the this proposal of Vlad from Moscow for many reasons, =
I
<br>appreciate patience and level of detail in your responses. At some
<br>point in future these patience and detail-level may save some good but
<br>ugly-looking proposal.
<br>
<br>To Vlad from Moscow:
<br>1. Just to satisfy my interest: Aren&#39;t you coming to C++ from some
<br>dynamically-typed language?
<br>2. If n2995 and/or D4128 would be accepted, they will satisfy all your =
requests:
<br>=C2=A0 =C2=A0 for ( auto x : std::make_range( a + 3, a + 7 ) ) ...;
<br>=C2=A0 =C2=A0 for ( auto p : m.equal_range( &#39;A&#39; ) ) ...;
<br>
<br></blockquote><div><br></div><div>It seems you do not understand. There =
is no any need to=C2=A0build a superconstruction or to deform algorithms th=
at to do this in clear and natural way.</div><div><br></div><div>The C++ St=
andard already has all=C2=A0needed to do the task.=C2=A0 And if you have a =
pair of iterators that make up a range then why do you need to build a rang=
e from already existent valid range?! Simply write</div><div><br></div><div=
>=C2=A0=C2=A0=C2=A0 for ( auto=C2=A0x :=C2=A0p ) ...; </div><div><br></div>=
<div>There is such principle KISS in programming that means Keep It Simple =
Stupid.</div><div><br></div><div>The=C2=A0programmer should not pay for wha=
t he totally need not.</div><div><br></div><div>What you are suggesting loo=
ks the following way. I have a notebook. You come to my home take away my n=
otebook and say: &quot;Pay me and i will give you a notebook&quot;. And aft=
er I paid you=C2=A0return me my notebook.</div><div><br></div><div>Excelent=
 idea!</div><div><br></div><div><br></div><div><br></div><div><br></div><bl=
ockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;padding-le=
ft:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left=
-style:solid">On Fri, Jul 24, 2015 at 10:36 AM, Vlad from Moscow &lt;<a rel=
=3D"nofollow">vlad....@mail.ru</a>&gt; wrote:
<br>&gt;
<br>&gt;
<br>&gt; On Friday, July 24, 2015 at 1:58:22 AM UTC+3, Thiago Macieira wrot=
e:
<br>&gt;&gt;
<br>&gt;&gt; On Thursday 23 July 2015 12:31:59 Vlad from Moscow wrote:
<br>&gt;&gt; &gt; Could you explain why do I need some ranges when this pro=
gram looks
<br>&gt;&gt; &gt; clear
<br>&gt;&gt; &gt; and nice without any ranges?
<br>&gt;&gt;
<br>&gt;&gt; Because you made it so that std::pair&lt;T, T&gt; is always a =
range, but that
<br>&gt;&gt; isn&#39;t
<br>&gt;&gt; the case. In fact, I&#39;d argue that most people who think of=
 &quot;iterating&quot;
<br>&gt;&gt; over a
<br>&gt;&gt; pair expect it to behave as an array of two elements: the firs=
t and the
<br>&gt;&gt; second.
<br>&gt;&gt;
<br>&gt;
<br>&gt; There is a serious logical mistake. If for example two pointers ca=
n make up
<br>&gt; a range this does not mean that any two pointers is a range or tha=
t any
<br>&gt; range is two pointers. Even two iterators of the same container or=
 two
<br>&gt; pointers of the same array might not make a range.
<br>&gt;
<br>&gt; std::pair is simply a media that can store iterators. It is used i=
n
<br>&gt; algorithm std::mismatch where iterators does not make up a range o=
r in the
<br>&gt; algorithm or class methods =C2=A0equal_range where pointers make u=
p a range.
<br>&gt;
<br>&gt; It is a responsibility of the programmer to use appropriate iterat=
ors that
<br>&gt; are stored in the media.
<br>&gt;
<br>&gt; So you and Sean Middleditch attempts to substitute the meaning of =
=C2=A0std::pair
<br>&gt; for the role like just ranges are false and confuse programmers.
<br>&gt; It is responsibility of the programmer to correctly use std::pair =
in
<br>&gt; different situations.
<br>&gt;
<br>&gt; With the same success you can use any valid C++ construction incor=
rectly.
<br>&gt; For example you can return a reference to a local variable of a fu=
nction.
<br>&gt; Does it mean that something wrong with references and the programm=
ers shall
<br>&gt; not declare function return types as references?
<br>&gt;
<br>&gt; According to your false logic it follows that the programmers inde=
ed shall
<br>&gt; not declare function return types as references
<br>&gt;
<br>&gt; The ptoblem is why should the programmer pay for the means that he=
 totally
<br>&gt; need not?
<br>&gt;
<br>&gt; I showed already an example with std::multimap where the code look=
s clear
<br>&gt; and nice. But you are saying: &quot;Stop! Programs must not be so =
clear and nice.
<br>&gt; You have to declare a class hierarchy and use these additional cla=
sses to do
<br>&gt; a simple and entirely correct thing.&quot;
<br>&gt;
<br>&gt; Why do the programmer have to use a suoerstructure when he already=
 has a
<br>&gt; range that he stored on such a media like std::pair?
<br>&gt;
<br>&gt; And moreover now Sean Middleditch is even going to deform standard
<br>&gt; algorithms with the only purpose that all programmers used his use=
less
<br>&gt; superstructures where all can be done simply and clear without the=
m.
<br>&gt;
<br>&gt;
<br>&gt;&gt; I&#39;d expect:
<br>&gt;&gt;
<br>&gt;&gt; template&lt;typename T&gt; const T* begin(const pair&lt;T, T&g=
t; &amp;p)
<br>&gt;&gt; { return &amp;p.first; }
<br>&gt;&gt;
<br>&gt;&gt; template&lt;typename T&gt; const T *end(const pair&lt;T, T&gt;=
 &amp;p)
<br>&gt;&gt; { return &amp;p.second + 1; }
<br>&gt;&gt;
<br>&gt;&gt; Which allows me to run:
<br>&gt;&gt;
<br>&gt;&gt; int main()
<br>&gt;&gt; {
<br>&gt;&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 for (auto i : std::make_pair(1, 2)=
)
<br>&gt;&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 cout &=
lt;&lt; i &lt;&lt; &#39; &#39;;
<br>&gt;&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 cout &lt;&lt; endl;
<br>&gt;&gt; }
<br>&gt;&gt;
<br>&gt;&gt; output: 1 2
<br>&gt;&gt; --
<br>&gt;&gt; Thiago Macieira - thiago (AT) <a href=3D"http://macieira.info"=
 rel=3D"nofollow" target=3D"_blank" onmousedown=3D"this.href=3D&#39;http://=
www.google.com/url?q\75http%3A%2F%2Fmacieira.info\46sa\75D\46sntz\0751\46us=
g\75AFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;return true;" onclick=3D"this.h=
ref=3D&#39;http://www.google.com/url?q\75http%3A%2F%2Fmacieira.info\46sa\75=
D\46sntz\0751\46usg\75AFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;return true;"=
>macieira.info</a> - thiago (AT) <a href=3D"http://kde.org" rel=3D"nofollow=
" target=3D"_blank" onmousedown=3D"this.href=3D&#39;http://www.google.com/u=
rl?q\75http%3A%2F%2Fkde.org\46sa\75D\46sntz\0751\46usg\75AFQjCNHGRJdo5_JYG1=
DowztwAHAKs80XSA&#39;;return true;" onclick=3D"this.href=3D&#39;http://www.=
google.com/url?q\75http%3A%2F%2Fkde.org\46sa\75D\46sntz\0751\46usg\75AFQjCN=
HGRJdo5_JYG1DowztwAHAKs80XSA&#39;;return true;">kde.org</a>
<br>&gt;&gt; =C2=A0 =C2=A0Software Architect - Intel Open Source Technology=
 Center
<br>&gt;&gt; =C2=A0 =C2=A0 =C2=A0 PGP/GPG: 0x6EF45358; fingerprint:
<br>&gt;&gt; =C2=A0 =C2=A0 =C2=A0 E067 918B B660 DBD1 105C =C2=A0966C 33F5 =
F005 6EF4 5358
<br>&gt;&gt;
<br>&gt; --
<br>&gt;
<br>&gt; ---
<br>&gt; You received this message because you are subscribed to the Google=
 Groups
<br>&gt; &quot;ISO C++ Standard - Future Proposals&quot; group.
<br>&gt; To unsubscribe from this group and stop receiving emails from it, =
send an
<br>&gt; email to <a rel=3D"nofollow">std-proposal...@isocpp.org</a>.
<br>&gt; To post to this group, send email to <a rel=3D"nofollow">std-pr...=
@isocpp.org</a>.
<br>&gt; Visit this group at
<br>&gt; <a href=3D"http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/" rel=3D"nofollow" target=3D"_blank" onmousedown=3D"this.href=3D&#39;htt=
p://groups.google.com/a/isocpp.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;">http://groups.google.com/a/isocpp.org/group/=
std-proposals/</a>.
<br></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_440_2084545534.1437764356354--
------=_Part_439_767270575.1437764356352--

.


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Fri, 24 Jul 2015 13:06:21 -0700 (PDT)
Raw View
------=_Part_1082_1582433338.1437768381872
Content-Type: multipart/alternative;
 boundary="----=_Part_1083_1495154463.1437768381873"

------=_Part_1083_1495154463.1437768381873
Content-Type: text/plain; charset=UTF-8



On Friday, July 24, 2015 at 9:59:16 PM UTC+3, inkwizyt...@gmail.com wrote:
>
> If some object have `begin` and `end` then its range. Most pair aren't
> ranges then they should not have this functions.
>

Most pointers are not ranges. Does it mean that pointers can not make up a
range?

Consider for example a dynamically allocated array. Does it has a range?

How will you specify its range? I think you will specify it as a pair of
pointers will not you? So for example if you allocated an integer array of
size n and the address of the allocated area was stored in pointer a then
pair a and a + n set a valid range. How do you specify pairs in C++? I
suspect that you use std::pair.

std::pair<int *, int *> range( a, a + n );

or

auto range = std::make_pair( a, a + n );


So if you have a pair that specifiers a valid range then you expect this
range can be used in for example the for range statement

So it is natural and locgically consistent for example to write

for ( int x : range ) std::cout << x << ' ';

It is a valid record. Why? Because object range defines a valid range. It
already exists. There is no need to invent some superconstructions that to
convert this valid range in the same valid range, You already have it.

Another example that I showed early is using either algorithm or class
methods equal_range. They all return a valid range do not they?

Thus std::pair is an integral part of algorithms and ranges. It is already
used to specify a valid range. There is nothing to invent. All you need is
to have an access to elements of the ranges they make up. To have an access
means that you need to get accfess to the beginning of the range and to the
end of the range.

You have such an access simply writing

for ( auto begin = p.first, end = p.second; begin != end; ++begin ) {
/*...*/ }

There is no any need to deform algorithms. All you need you already have in
your disposal.

Only instead of

for ( auto begin = p.first, end = p.second; begin != end; ++begin ) {
/*...*/ }

it is better to write

for ( x : p ) { /(...*/ }

However according to your logic you prefer to use only this record of the
loop

for ( auto begin = p.first, end = p.second; begin != end; ++begin ) {
/*...*/ }

Why? Because your argument is that std::pair does not set a range.:) It is
funny.:)

I am sorry I do not see any logic in your words.

Of course you can create a class that will be named something like ranges.
You can even to build a hierarchy of such classes and numerous
specializations of the classes. :)

But to use the range that is held in an object of type std::pair your
classes are useless.

All examples of code that I showed in this thread I wrote literally in 5-10
minutes without inventing any classes. Because it is natural way of using
std::pair having a range.

On the other hand your hierarchy of classes of ranges has been created if I
am not mistaken already several years. And in the examples I showed their
usage is no more than the usage of soap bubbles.



> If some objects don't give you guarantees about something but you know in
> some cases it true then proper way of use is EXPLICITLY show that it hold
> true.
> In our case `std::make_range` fulfill this requirements.
>
> Probably solution for this problem are tagged pairs and tuples (IIRC they
> are form range proposition).
> It look something like that:
>
> extern int tab[10];
>
> std::pair<std::begin_tag<int*>, std::end_tag<int*>> a;
> std::pair<std::ptr_tag<int*>, std::success_tag<bool>> b;
>
> a.begin() = tab; //equal a.first = tab;
> a.end() = tab + 10; //equal a.second = tab + 10;
> for (auto& x : a)
> {
>     if (x == 5)
>     {
>         b.ptr() = &x;
>         b.success() = true;
>     }
> }
> return b;
>
>
>
>
> On Friday, July 24, 2015 at 3:10:03 PM UTC+2, Vlad from Moscow wrote:
>>
>>
>>
>> On Friday, July 24, 2015 at 3:50:58 PM UTC+3, Sasha Unknown wrote:
>>>
>>> To T. C. and Sean Middleditch: Thank you for you patience. While I
>>> don't like the this proposal of Vlad from Moscow for many reasons, I
>>> appreciate patience and level of detail in your responses. At some
>>> point in future these patience and detail-level may save some good but
>>> ugly-looking proposal.
>>>
>>> To Vlad from Moscow:
>>> 1. Just to satisfy my interest: Aren't you coming to C++ from some
>>> dynamically-typed language?
>>> 2. If n2995 and/or D4128 would be accepted, they will satisfy all your
>>> requests:
>>>     for ( auto x : std::make_range( a + 3, a + 7 ) ) ...;
>>>     for ( auto p : m.equal_range( 'A' ) ) ...;
>>>
>>>
>> It seems you do not understand. There is no any need to build a
>> superconstruction or to deform algorithms that to do this in clear and
>> natural way.
>>
>> The C++ Standard already has all needed to do the task.  And if you have
>> a pair of iterators that make up a range then why do you need to build a
>> range from already existent valid range?! Simply write
>>
>>     for ( auto x : p ) ...;
>>
>> There is such principle KISS in programming that means Keep It Simple
>> Stupid.
>>
>> The programmer should not pay for what he totally need not.
>>
>> What you are suggesting looks the following way. I have a notebook. You
>> come to my home take away my notebook and say: "Pay me and i will give you
>> a notebook". And after I paid you return me my notebook.
>>
>> Excelent idea!
>>
>>
>>
>>
>> On Fri, Jul 24, 2015 at 10:36 AM, Vlad from Moscow <vlad....@mail.ru>
>>> wrote:
>>> >
>>> >
>>> > On Friday, July 24, 2015 at 1:58:22 AM UTC+3, Thiago Macieira wrote:
>>> >>
>>> >> On Thursday 23 July 2015 12:31:59 Vlad from Moscow wrote:
>>> >> > Could you explain why do I need some ranges when this program looks
>>> >> > clear
>>> >> > and nice without any ranges?
>>> >>
>>> >> Because you made it so that std::pair<T, T> is always a range, but
>>> that
>>> >> isn't
>>> >> the case. In fact, I'd argue that most people who think of
>>> "iterating"
>>> >> over a
>>> >> pair expect it to behave as an array of two elements: the first and
>>> the
>>> >> second.
>>> >>
>>> >
>>> > There is a serious logical mistake. If for example two pointers can
>>> make up
>>> > a range this does not mean that any two pointers is a range or that
>>> any
>>> > range is two pointers. Even two iterators of the same container or two
>>> > pointers of the same array might not make a range.
>>> >
>>> > std::pair is simply a media that can store iterators. It is used in
>>> > algorithm std::mismatch where iterators does not make up a range or in
>>> the
>>> > algorithm or class methods  equal_range where pointers make up a
>>> range.
>>> >
>>> > It is a responsibility of the programmer to use appropriate iterators
>>> that
>>> > are stored in the media.
>>> >
>>> > So you and Sean Middleditch attempts to substitute the meaning of
>>>  std::pair
>>> > for the role like just ranges are false and confuse programmers.
>>> > It is responsibility of the programmer to correctly use std::pair in
>>> > different situations.
>>> >
>>> > With the same success you can use any valid C++ construction
>>> incorrectly.
>>> > For example you can return a reference to a local variable of a
>>> function.
>>> > Does it mean that something wrong with references and the programmers
>>> shall
>>> > not declare function return types as references?
>>> >
>>> > According to your false logic it follows that the programmers indeed
>>> shall
>>> > not declare function return types as references
>>> >
>>> > The ptoblem is why should the programmer pay for the means that he
>>> totally
>>> > need not?
>>> >
>>> > I showed already an example with std::multimap where the code looks
>>> clear
>>> > and nice. But you are saying: "Stop! Programs must not be so clear and
>>> nice.
>>> > You have to declare a class hierarchy and use these additional classes
>>> to do
>>> > a simple and entirely correct thing."
>>> >
>>> > Why do the programmer have to use a suoerstructure when he already has
>>> a
>>> > range that he stored on such a media like std::pair?
>>> >
>>> > And moreover now Sean Middleditch is even going to deform standard
>>> > algorithms with the only purpose that all programmers used his useless
>>> > superstructures where all can be done simply and clear without them.
>>> >
>>> >
>>> >> I'd expect:
>>> >>
>>> >> template<typename T> const T* begin(const pair<T, T> &p)
>>> >> { return &p.first; }
>>> >>
>>> >> template<typename T> const T *end(const pair<T, T> &p)
>>> >> { return &p.second + 1; }
>>> >>
>>> >> Which allows me to run:
>>> >>
>>> >> int main()
>>> >> {
>>> >>         for (auto i : std::make_pair(1, 2))
>>> >>                 cout << i << ' ';
>>> >>         cout << endl;
>>> >> }
>>> >>
>>> >> output: 1 2
>>> >> --
>>> >> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>>> >>    Software Architect - Intel Open Source Technology Center
>>> >>       PGP/GPG: 0x6EF45358; fingerprint:
>>> >>       E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
>>> >>
>>> > --
>>> >
>>> > ---
>>> > 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-proposal...@isocpp.org.
>>> > To post to this group, send email to std-pr...@isocpp.org.
>>> > Visit this group at
>>> > http://groups.google.com/a/isocpp.org/group/std-proposals/.
>>>
>>

--

---
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_1083_1495154463.1437768381873
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Friday, July 24, 2015 at 9:59:16 PM UTC+3, inkw=
izyt...@gmail.com wrote:<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"ltr">If so=
me object have `begin` and `end` then its range. Most pair aren&#39;t range=
s then they should not have this functions.<br></div></blockquote><div><br>=
</div><div>Most pointers are not ranges. Does it mean that pointers can not=
 make up a range? </div><div><br></div><div>Consider for example a dynamica=
lly allocated array. Does it has a range?</div><div><br></div><div>How will=
 you specify its range? I think you will specify it as a pair of pointers w=
ill not you? So for example if you allocated an integer array of size n and=
 the address of the allocated area was stored in pointer=C2=A0a then pair=
=C2=A0a and=C2=A0a + n set a valid range. How do you specify pairs in C++? =
I suspect that you use std::pair.</div><div><br></div><div>std::pair&lt;int=
 *, int *&gt; range( a, a + n );</div><div><br></div><div>or</div><div><br>=
</div><div>auto range =3D std::make_pair( a, a + n );</div><div><br></div><=
div><br></div><div>So if you have a pair that specifiers a valid range then=
 you expect this range can be used in for example the for range statement</=
div><div><br></div><div>So it is natural and locgically consistent for exam=
ple to write</div><div><br></div><div>for ( int x :=C2=A0range ) std::cout =
&lt;&lt; x &lt;&lt; &#39; &#39;;</div><div><br></div><div>It is a valid rec=
ord. Why? Because=C2=A0object range defines a valid range. It already exist=
s. There is no need to invent some superconstructions that to convert this =
valid range in the same valid range, You already have it.</div><div><br></d=
iv><div>Another example that I showed early is using either algorithm or cl=
ass methods equal_range. They all return a valid range do not they?</div><d=
iv><br></div><div>Thus std::pair is an integral part of algorithms and rang=
es. It is already used to specify a valid range. There is nothing to invent=
.. All you need is to have an access to elements of the ranges they make up.=
 To have an access means that you need to get accfess to the beginning of t=
he range and to the end of the range.</div><div><br></div><div>You have suc=
h an access simply writing</div><div><br></div><div>for ( auto begin =3D p.=
first, end =3D p.second; begin !=3D end; ++begin ) { /*...*/ }</div><div><b=
r></div><div>There is no any need to deform algorithms.=C2=A0All you need y=
ou already have in your disposal.=C2=A0</div><div><br></div><div>Only inste=
ad of </div><div><br></div><div><div>for ( auto begin =3D p.first, end =3D =
p.second; begin !=3D end; ++begin ) { /*...*/ }</div><div><br></div><div>it=
 is better to write</div><div><br></div><div>for ( x : p ) { /(...*/ }</div=
><div><br></div><div>However according to your logic you prefer to use only=
=C2=A0this=C2=A0record of the loop</div><div><br></div><div><div>for ( auto=
 begin =3D p.first, end =3D p.second; begin !=3D end; ++begin ) { /*...*/ }=
</div><div><br></div><div>Why? Because your argument is that std::pair does=
 not set a range.:) It is funny.:)=C2=A0</div><div><br></div><div>I am sorr=
y I do not see any logic in your words. </div><div><br></div><div>Of course=
 you can create a class that will be named something=C2=A0like ranges.=C2=
=A0 You can even to build a hierarchy of such classes and numerous speciali=
zations of the classes. :)</div><div><br></div><div>But to use the range th=
at is held in an object of type std::pair your classes are useless.</div><d=
iv><br></div><div>All examples of code that I showed in this thread I wrote=
 literally in 5-10 minutes without inventing any classes. Because it is nat=
ural way of using std::pair having a range.</div><div><br></div><div>On the=
 other hand your hierarchy of classes of ranges has been created if I am no=
t mistaken already several years. And in the examples I showed their usage =
is no more than the usage of soap bubbles. </div><div><br></div><div>=C2=A0=
</div></div></div><blockquote class=3D"gmail_quote" style=3D"margin: 0px 0p=
x 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); bord=
er-left-width: 1px; border-left-style: solid;"><div dir=3D"ltr">If some obj=
ects don&#39;t give you guarantees about something but you know in some cas=
es it true then proper way of use is EXPLICITLY show that it hold true.<br>=
In our case `std::make_range` fulfill this requirements.<br><br>Probably so=
lution for this problem are tagged pairs and tuples (IIRC they are form ran=
ge proposition).<br>It look something like that:<br><div style=3D"border: 1=
px solid rgb(187, 187, 187); border-image: none; -ms-word-wrap: break-word;=
 background-color: rgb(250, 250, 250);"><code><div><span style=3D"color: rg=
b(0, 0, 0);"><br></span><span style=3D"color: rgb(0, 0, 136);">extern</span=
><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(0, =
0, 136);">int</span><span style=3D"color: rgb(0, 0, 0);"> tab</span><span s=
tyle=3D"color: rgb(102, 102, 0);">[</span><span style=3D"color: rgb(0, 102,=
 102);">10</span><span style=3D"color: rgb(102, 102, 0);">];</span><span st=
yle=3D"color: rgb(0, 0, 0);"><br><br>std</span><span style=3D"color: rgb(10=
2, 102, 0);">::</span><span style=3D"color: rgb(0, 0, 0);">pair</span><span=
 style=3D"color: rgb(102, 102, 0);">&lt;</span><span style=3D"color: rgb(0,=
 0, 0);">std</span><span style=3D"color: rgb(102, 102, 0);">::</span><span =
style=3D"color: rgb(0, 0, 0);">begin_tag</span><span style=3D"color: rgb(10=
2, 102, 0);">&lt;</span><span style=3D"color: rgb(0, 0, 136);">int</span><s=
pan style=3D"color: rgb(102, 102, 0);">*&gt;,</span><span style=3D"color: r=
gb(0, 0, 0);"> std</span><span style=3D"color: rgb(102, 102, 0);">::</span>=
<span style=3D"color: rgb(0, 0, 0);">end_tag</span><span style=3D"color: rg=
b(102, 102, 0);">&lt;</span><span style=3D"color: rgb(0, 0, 136);">int</spa=
n><span style=3D"color: rgb(102, 102, 0);">*&gt;&gt;</span><span style=3D"c=
olor: rgb(0, 0, 0);"> a</span><span style=3D"color: rgb(102, 102, 0);">;</s=
pan><span style=3D"color: rgb(0, 0, 0);"><br>std</span><span style=3D"color=
: rgb(102, 102, 0);">::</span><span style=3D"color: rgb(0, 0, 0);">pair</sp=
an><span style=3D"color: rgb(102, 102, 0);">&lt;</span><span style=3D"color=
: rgb(0, 0, 0);">std</span><span style=3D"color: rgb(102, 102, 0);">::</spa=
n><span style=3D"color: rgb(0, 0, 0);">ptr_tag</span><span style=3D"color: =
rgb(102, 102, 0);">&lt;</span><span style=3D"color: rgb(0, 0, 136);">int</s=
pan><span style=3D"color: rgb(102, 102, 0);">*&gt;,</span><span style=3D"co=
lor: rgb(0, 0, 0);"> std</span><span style=3D"color: rgb(102, 102, 0);">::<=
/span><span style=3D"color: rgb(0, 0, 0);">success_tag</span><span style=3D=
"color: rgb(0, 136, 0);">&lt;bool&gt;</span><span style=3D"color: rgb(102, =
102, 0);">&gt;</span><span style=3D"color: rgb(0, 0, 0);"> b</span><span st=
yle=3D"color: rgb(102, 102, 0);">;</span><span style=3D"color: rgb(0, 0, 0)=
;"><br><br>a</span><span style=3D"color: rgb(102, 102, 0);">.</span><span s=
tyle=3D"color: rgb(0, 0, 136);">begin</span><span style=3D"color: rgb(102, =
102, 0);">()</span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=
=3D"color: rgb(102, 102, 0);">=3D</span><span style=3D"color: rgb(0, 0, 0);=
"> tab</span><span style=3D"color: rgb(102, 102, 0);">;</span><span style=
=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(136, 0, 0);">//=
equal a.first =3D tab;</span><span style=3D"color: rgb(0, 0, 0);"><br>a</sp=
an><span style=3D"color: rgb(102, 102, 0);">.</span><span style=3D"color: r=
gb(0, 0, 136);">end</span><span style=3D"color: rgb(102, 102, 0);">()</span=
><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102=
, 102, 0);">=3D</span><span style=3D"color: rgb(0, 0, 0);"> tab </span><spa=
n style=3D"color: rgb(102, 102, 0);">+</span><span style=3D"color: rgb(0, 0=
, 0);"> </span><span style=3D"color: rgb(0, 102, 102);">10</span><span styl=
e=3D"color: rgb(102, 102, 0);">;</span><span style=3D"color: rgb(0, 0, 0);"=
> </span><span style=3D"color: rgb(136, 0, 0);">//equal a.second =3D tab + =
10;</span><span style=3D"color: rgb(0, 0, 0);"><br></span><span style=3D"co=
lor: rgb(0, 0, 136);">for</span><span style=3D"color: rgb(0, 0, 0);"> </spa=
n><span style=3D"color: rgb(102, 102, 0);">(</span><span style=3D"color: rg=
b(0, 0, 136);">auto</span><span style=3D"color: rgb(102, 102, 0);">&amp;</s=
pan><span style=3D"color: rgb(0, 0, 0);"> x </span><span style=3D"color: rg=
b(102, 102, 0);">:</span><span style=3D"color: rgb(0, 0, 0);"> a</span><spa=
n style=3D"color: rgb(102, 102, 0);">)</span><span style=3D"color: rgb(0, 0=
, 0);"><br></span><span style=3D"color: rgb(102, 102, 0);">{</span><span st=
yle=3D"color: rgb(0, 0, 0);"><br>=C2=A0 =C2=A0 </span><span style=3D"color:=
 rgb(0, 0, 136);">if</span><span style=3D"color: rgb(0, 0, 0);"> </span><sp=
an style=3D"color: rgb(102, 102, 0);">(</span><span style=3D"color: rgb(0, =
0, 0);">x </span><span style=3D"color: rgb(102, 102, 0);">=3D=3D</span><spa=
n style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(0, 102, =
102);">5</span><span style=3D"color: rgb(102, 102, 0);">)</span><span style=
=3D"color: rgb(0, 0, 0);"><br>=C2=A0 =C2=A0 </span><span style=3D"color: rg=
b(102, 102, 0);">{</span><span style=3D"color: rgb(0, 0, 0);"><br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 b</span><span style=3D"color: rgb(102, 102, 0);">.</sp=
an><span style=3D"color: rgb(0, 0, 0);">ptr</span><span style=3D"color: rgb=
(102, 102, 0);">()</span><span style=3D"color: rgb(0, 0, 0);"> </span><span=
 style=3D"color: rgb(102, 102, 0);">=3D</span><span style=3D"color: rgb(0, =
0, 0);"> </span><span style=3D"color: rgb(102, 102, 0);">&amp;</span><span =
style=3D"color: rgb(0, 0, 0);">x</span><span style=3D"color: rgb(102, 102, =
0);">;</span><span style=3D"color: rgb(0, 0, 0);"><br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 b</span><span style=3D"color: rgb(102, 102, 0);">.</span><span style=
=3D"color: rgb(0, 0, 0);">success</span><span style=3D"color: rgb(102, 102,=
 0);">()</span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"=
color: rgb(102, 102, 0);">=3D</span><span style=3D"color: rgb(0, 0, 0);"> <=
/span><span style=3D"color: rgb(0, 0, 136);">true</span><span style=3D"colo=
r: rgb(102, 102, 0);">;</span><span style=3D"color: rgb(0, 0, 0);"><br>=C2=
=A0 =C2=A0 </span><span style=3D"color: rgb(102, 102, 0);">}</span><span st=
yle=3D"color: rgb(0, 0, 0);"><br></span><span style=3D"color: rgb(102, 102,=
 0);">}</span><span style=3D"color: rgb(0, 0, 0);"><br></span><span style=
=3D"color: rgb(0, 0, 136);">return</span><span style=3D"color: rgb(0, 0, 0)=
;"> b</span><span style=3D"color: rgb(102, 102, 0);">;</span></div></code><=
/div><br><br><br><br>On Friday, July 24, 2015 at 3:10:03 PM UTC+2, Vlad fro=
m Moscow wrote:<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"><br><br>On Fri=
day, July 24, 2015 at 3:50:58 PM UTC+3, Sasha Unknown wrote:<blockquote cla=
ss=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; b=
order-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-s=
tyle: solid;">To T. C. and Sean Middleditch: Thank you for you patience. Wh=
ile I
<br>don&#39;t like the this proposal of Vlad from Moscow for many reasons, =
I
<br>appreciate patience and level of detail in your responses. At some
<br>point in future these patience and detail-level may save some good but
<br>ugly-looking proposal.
<br>
<br>To Vlad from Moscow:
<br>1. Just to satisfy my interest: Aren&#39;t you coming to C++ from some
<br>dynamically-typed language?
<br>2. If n2995 and/or D4128 would be accepted, they will satisfy all your =
requests:
<br>=C2=A0 =C2=A0 for ( auto x : std::make_range( a + 3, a + 7 ) ) ...;
<br>=C2=A0 =C2=A0 for ( auto p : m.equal_range( &#39;A&#39; ) ) ...;
<br>
<br></blockquote><div><br></div><div>It seems you do not understand. There =
is no any need to=C2=A0build a superconstruction or to deform algorithms th=
at to do this in clear and natural way.</div><div><br></div><div>The C++ St=
andard already has all=C2=A0needed to do the task.=C2=A0 And if you have a =
pair of iterators that make up a range then why do you need to build a rang=
e from already existent valid range?! Simply write</div><div><br></div><div=
>=C2=A0=C2=A0=C2=A0 for ( auto=C2=A0x :=C2=A0p ) ...; </div><div><br></div>=
<div>There is such principle KISS in programming that means Keep It Simple =
Stupid.</div><div><br></div><div>The=C2=A0programmer should not pay for wha=
t he totally need not.</div><div><br></div><div>What you are suggesting loo=
ks the following way. I have a notebook. You come to my home take away my n=
otebook and say: &quot;Pay me and i will give you a notebook&quot;. And aft=
er I paid you=C2=A0return me my notebook.</div><div><br></div><div>Excelent=
 idea!</div><div><br></div><div><br></div><div><br></div><div><br></div><bl=
ockquote 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; b=
order-left-style: solid;">On Fri, Jul 24, 2015 at 10:36 AM, Vlad from Mosco=
w &lt;<a rel=3D"nofollow">vlad....@mail.ru</a>&gt; wrote:
<br>&gt;
<br>&gt;
<br>&gt; On Friday, July 24, 2015 at 1:58:22 AM UTC+3, Thiago Macieira wrot=
e:
<br>&gt;&gt;
<br>&gt;&gt; On Thursday 23 July 2015 12:31:59 Vlad from Moscow wrote:
<br>&gt;&gt; &gt; Could you explain why do I need some ranges when this pro=
gram looks
<br>&gt;&gt; &gt; clear
<br>&gt;&gt; &gt; and nice without any ranges?
<br>&gt;&gt;
<br>&gt;&gt; Because you made it so that std::pair&lt;T, T&gt; is always a =
range, but that
<br>&gt;&gt; isn&#39;t
<br>&gt;&gt; the case. In fact, I&#39;d argue that most people who think of=
 &quot;iterating&quot;
<br>&gt;&gt; over a
<br>&gt;&gt; pair expect it to behave as an array of two elements: the firs=
t and the
<br>&gt;&gt; second.
<br>&gt;&gt;
<br>&gt;
<br>&gt; There is a serious logical mistake. If for example two pointers ca=
n make up
<br>&gt; a range this does not mean that any two pointers is a range or tha=
t any
<br>&gt; range is two pointers. Even two iterators of the same container or=
 two
<br>&gt; pointers of the same array might not make a range.
<br>&gt;
<br>&gt; std::pair is simply a media that can store iterators. It is used i=
n
<br>&gt; algorithm std::mismatch where iterators does not make up a range o=
r in the
<br>&gt; algorithm or class methods =C2=A0equal_range where pointers make u=
p a range.
<br>&gt;
<br>&gt; It is a responsibility of the programmer to use appropriate iterat=
ors that
<br>&gt; are stored in the media.
<br>&gt;
<br>&gt; So you and Sean Middleditch attempts to substitute the meaning of =
=C2=A0std::pair
<br>&gt; for the role like just ranges are false and confuse programmers.
<br>&gt; It is responsibility of the programmer to correctly use std::pair =
in
<br>&gt; different situations.
<br>&gt;
<br>&gt; With the same success you can use any valid C++ construction incor=
rectly.
<br>&gt; For example you can return a reference to a local variable of a fu=
nction.
<br>&gt; Does it mean that something wrong with references and the programm=
ers shall
<br>&gt; not declare function return types as references?
<br>&gt;
<br>&gt; According to your false logic it follows that the programmers inde=
ed shall
<br>&gt; not declare function return types as references
<br>&gt;
<br>&gt; The ptoblem is why should the programmer pay for the means that he=
 totally
<br>&gt; need not?
<br>&gt;
<br>&gt; I showed already an example with std::multimap where the code look=
s clear
<br>&gt; and nice. But you are saying: &quot;Stop! Programs must not be so =
clear and nice.
<br>&gt; You have to declare a class hierarchy and use these additional cla=
sses to do
<br>&gt; a simple and entirely correct thing.&quot;
<br>&gt;
<br>&gt; Why do the programmer have to use a suoerstructure when he already=
 has a
<br>&gt; range that he stored on such a media like std::pair?
<br>&gt;
<br>&gt; And moreover now Sean Middleditch is even going to deform standard
<br>&gt; algorithms with the only purpose that all programmers used his use=
less
<br>&gt; superstructures where all can be done simply and clear without the=
m.
<br>&gt;
<br>&gt;
<br>&gt;&gt; I&#39;d expect:
<br>&gt;&gt;
<br>&gt;&gt; template&lt;typename T&gt; const T* begin(const pair&lt;T, T&g=
t; &amp;p)
<br>&gt;&gt; { return &amp;p.first; }
<br>&gt;&gt;
<br>&gt;&gt; template&lt;typename T&gt; const T *end(const pair&lt;T, T&gt;=
 &amp;p)
<br>&gt;&gt; { return &amp;p.second + 1; }
<br>&gt;&gt;
<br>&gt;&gt; Which allows me to run:
<br>&gt;&gt;
<br>&gt;&gt; int main()
<br>&gt;&gt; {
<br>&gt;&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 for (auto i : std::make_pair(1, 2)=
)
<br>&gt;&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 cout &=
lt;&lt; i &lt;&lt; &#39; &#39;;
<br>&gt;&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 cout &lt;&lt; endl;
<br>&gt;&gt; }
<br>&gt;&gt;
<br>&gt;&gt; output: 1 2
<br>&gt;&gt; --
<br>&gt;&gt; Thiago Macieira - thiago (AT) <a onmousedown=3D"this.href=3D&#=
39;http://www.google.com/url?q\75http%3A%2F%2Fmacieira.info\46sa\75D\46sntz=
\0751\46usg\75AFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;return true;" onclick=
=3D"this.href=3D&#39;http://www.google.com/url?q\75http%3A%2F%2Fmacieira.in=
fo\46sa\75D\46sntz\0751\46usg\75AFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;ret=
urn true;" href=3D"http://macieira.info" target=3D"_blank" rel=3D"nofollow"=
>macieira.info</a> - thiago (AT) <a onmousedown=3D"this.href=3D&#39;http://=
www.google.com/url?q\75http%3A%2F%2Fkde.org\46sa\75D\46sntz\0751\46usg\75AF=
QjCNHGRJdo5_JYG1DowztwAHAKs80XSA&#39;;return true;" onclick=3D"this.href=3D=
&#39;http://www.google.com/url?q\75http%3A%2F%2Fkde.org\46sa\75D\46sntz\075=
1\46usg\75AFQjCNHGRJdo5_JYG1DowztwAHAKs80XSA&#39;;return true;" href=3D"htt=
p://kde.org" target=3D"_blank" rel=3D"nofollow">kde.org</a>
<br>&gt;&gt; =C2=A0 =C2=A0Software Architect - Intel Open Source Technology=
 Center
<br>&gt;&gt; =C2=A0 =C2=A0 =C2=A0 PGP/GPG: 0x6EF45358; fingerprint:
<br>&gt;&gt; =C2=A0 =C2=A0 =C2=A0 E067 918B B660 DBD1 105C =C2=A0966C 33F5 =
F005 6EF4 5358
<br>&gt;&gt;
<br>&gt; --
<br>&gt;
<br>&gt; ---
<br>&gt; You received this message because you are subscribed to the Google=
 Groups
<br>&gt; &quot;ISO C++ Standard - Future Proposals&quot; group.
<br>&gt; To unsubscribe from this group and stop receiving emails from it, =
send an
<br>&gt; email to <a rel=3D"nofollow">std-proposal...@isocpp.org</a>.
<br>&gt; To post to this group, send email to <a rel=3D"nofollow">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></blockquote></div></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_1083_1495154463.1437768381873--
------=_Part_1082_1582433338.1437768381872--

.


Author: inkwizytoryankes@gmail.com
Date: Fri, 24 Jul 2015 14:13:38 -0700 (PDT)
Raw View
------=_Part_1078_853807004.1437772419047
Content-Type: multipart/alternative;
 boundary="----=_Part_1079_1425436621.1437772419053"

------=_Part_1079_1425436621.1437772419053
Content-Type: text/plain; charset=UTF-8


Pointers can made range, but they have `begin` and `end`? no. Because most
of them don't made any range. Can you point me std class that have `begin`
and `end` but they don't made range?

Over all what do you want is implicit conversation form pair to range. This
is exactly same situation that conversation form int to enum.
I know usage is right when why I need use cast every time? Its for making
you remember that not every int can map to enum.

Another approach, do pair have invariants of range? No. You should test
before each use as range if is range. Who you inform other people that you
use pair as range?
Using comments? C++ have lot better tools for this. Special classes that
will enforce it.

int b;
int a;

foo0(&a, &b);
foo1(std::make_pair(&a, &b));
foo2(std::make_range(&a, &b));
With of this functions are call incorrectly? I know that last one for sure
is broken because I beak invariants of range constructor.
I don't even need to read comments or look on implementation. This is why
we have `shared_ptr` and `unique_ptr` instead of `T*`.
This classes help us maintaining invariants, you can follow couple of
simple rules and you will never have problems with memory leaks again.

But with `std::pair` as range is impossible, you can have valid usage of
pair that aren't ranges in your program. How do you reliable separate both
usage?
Again use different types for different concepts.






On Friday, July 24, 2015 at 10:06:21 PM UTC+2, Vlad from Moscow wrote:
>
>
>
> On Friday, July 24, 2015 at 9:59:16 PM UTC+3, inkwizyt...@gmail.com wrote:
>>
>> If some object have `begin` and `end` then its range. Most pair aren't
>> ranges then they should not have this functions.
>>
>
> Most pointers are not ranges. Does it mean that pointers can not make up a
> range?
>
> Consider for example a dynamically allocated array. Does it has a range?
>
> How will you specify its range? I think you will specify it as a pair of
> pointers will not you? So for example if you allocated an integer array of
> size n and the address of the allocated area was stored in pointer a then
> pair a and a + n set a valid range. How do you specify pairs in C++? I
> suspect that you use std::pair.
>
> std::pair<int *, int *> range( a, a + n );
>
> or
>
> auto range = std::make_pair( a, a + n );
>
>
> So if you have a pair that specifiers a valid range then you expect this
> range can be used in for example the for range statement
>
> So it is natural and locgically consistent for example to write
>
> for ( int x : range ) std::cout << x << ' ';
>
> It is a valid record. Why? Because object range defines a valid range. It
> already exists. There is no need to invent some superconstructions that to
> convert this valid range in the same valid range, You already have it.
>
> Another example that I showed early is using either algorithm or class
> methods equal_range. They all return a valid range do not they?
>
> Thus std::pair is an integral part of algorithms and ranges. It is already
> used to specify a valid range. There is nothing to invent. All you need is
> to have an access to elements of the ranges they make up. To have an access
> means that you need to get accfess to the beginning of the range and to the
> end of the range.
>
> You have such an access simply writing
>
> for ( auto begin = p.first, end = p.second; begin != end; ++begin ) {
> /*...*/ }
>
> There is no any need to deform algorithms. All you need you already have
> in your disposal.
>
> Only instead of
>
> for ( auto begin = p.first, end = p.second; begin != end; ++begin ) {
> /*...*/ }
>
> it is better to write
>
> for ( x : p ) { /(...*/ }
>
> However according to your logic you prefer to use only this record of the
> loop
>
> for ( auto begin = p.first, end = p.second; begin != end; ++begin ) {
> /*...*/ }
>
> Why? Because your argument is that std::pair does not set a range.:) It is
> funny.:)
>
> I am sorry I do not see any logic in your words.
>
> Of course you can create a class that will be named something like
> ranges.  You can even to build a hierarchy of such classes and numerous
> specializations of the classes. :)
>
> But to use the range that is held in an object of type std::pair your
> classes are useless.
>
> All examples of code that I showed in this thread I wrote literally in
> 5-10 minutes without inventing any classes. Because it is natural way of
> using std::pair having a range.
>
> On the other hand your hierarchy of classes of ranges has been created if
> I am not mistaken already several years. And in the examples I showed their
> usage is no more than the usage of soap bubbles.
>
>
>
>> If some objects don't give you guarantees about something but you know in
>> some cases it true then proper way of use is EXPLICITLY show that it hold
>> true.
>> In our case `std::make_range` fulfill this requirements.
>>
>> Probably solution for this problem are tagged pairs and tuples (IIRC they
>> are form range proposition).
>> It look something like that:
>>
>> extern int tab[10];
>>
>> std::pair<std::begin_tag<int*>, std::end_tag<int*>> a;
>> std::pair<std::ptr_tag<int*>, std::success_tag<bool>> b;
>>
>> a.begin() = tab; //equal a.first = tab;
>> a.end() = tab + 10; //equal a.second = tab + 10;
>> for (auto& x : a)
>> {
>>     if (x == 5)
>>     {
>>         b.ptr() = &x;
>>         b.success() = true;
>>     }
>> }
>> return b;
>>
>>

--

---
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_1079_1425436621.1437772419053
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><br></div><div>Pointers can made range, but they have=
 `begin` and `end`? no. Because most of them don&#39;t made any range. Can =
you point me std class that have `begin` and `end` but they don&#39;t made =
range?<br><br>Over all what do you want is implicit conversation form pair =
to range. This is exactly same situation that conversation form int to enum=
..<br>I know usage is right when why I need use cast every time? Its for mak=
ing you remember that not every int can map to enum.<br><br>Another approac=
h, do pair have invariants of range? No. You should test before each use as=
 range if is range. Who you inform other people that you use pair as range?=
<br>Using comments? C++ have lot better tools for this. Special classes tha=
t will enforce it.<br><div class=3D"prettyprint" style=3D"background-color:=
 rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid;=
 border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><di=
v class=3D"subprettyprint"><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">int</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> b<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><br=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><code class=3D"p=
rettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">int</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> a</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span></code>foo0</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">(&amp;</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">a</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">b</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br>foo1</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">s=
td</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">make_pair</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">(&amp;</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">a</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">b</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">));</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br>foo2</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">std=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify">make_range</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">(&amp;</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify">a</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">b</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">));</span></div></code></div>With of this functions are call in=
correctly? I know that last one for sure is broken because I beak invariant=
s of range constructor.<br>I don&#39;t even need to read comments or look o=
n implementation. This is why we have `shared_ptr` and `unique_ptr` instead=
 of `T*`.<br>This classes help us maintaining invariants, you can follow co=
uple of simple rules and you will never have problems with memory leaks aga=
in.<br><br>But with `std::pair` as range is impossible, you can have valid =
usage of pair that aren&#39;t ranges in your program. How do you reliable s=
eparate both usage?<br>Again use different types for different concepts.<br=
><br><br><br><br></div><br><br>On Friday, July 24, 2015 at 10:06:21 PM UTC+=
2, Vlad from Moscow wrote:<blockquote class=3D"gmail_quote" style=3D"margin=
: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div=
 dir=3D"ltr"><br><br>On Friday, July 24, 2015 at 9:59:16 PM UTC+3, <a>inkwi=
zyt...@gmail.com</a> wrote:<blockquote class=3D"gmail_quote" style=3D"margi=
n:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);bor=
der-left-width:1px;border-left-style:solid"><div dir=3D"ltr">If some object=
 have `begin` and `end` then its range. Most pair aren&#39;t ranges then th=
ey should not have this functions.<br></div></blockquote><div><br></div><di=
v>Most pointers are not ranges. Does it mean that pointers can not make up =
a range? </div><div><br></div><div>Consider for example a dynamically alloc=
ated array. Does it has a range?</div><br></div></blockquote><blockquote cl=
ass=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px =
#ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div></div><div>How will yo=
u specify its range? I think you will specify it as a pair of pointers will=
 not you? So for example if you allocated an integer array of size n and th=
e address of the allocated area was stored in pointer=C2=A0a then pair=C2=
=A0a and=C2=A0a + n set a valid range. How do you specify pairs in C++? I s=
uspect that you use std::pair.</div><div><br></div><div>std::pair&lt;int *,=
 int *&gt; range( a, a + n );</div><div><br></div><div>or</div><div><br></d=
iv><div>auto range =3D std::make_pair( a, a + n );</div><div><br></div><div=
><br></div><div>So if you have a pair that specifiers a valid range then yo=
u expect this range can be used in for example the for range statement</div=
><div><br></div><div>So it is natural and locgically consistent for example=
 to write</div><div><br></div><div>for ( int x :=C2=A0range ) std::cout &lt=
;&lt; x &lt;&lt; &#39; &#39;;</div><div><br></div><div>It is a valid record=
.. Why? Because=C2=A0object range defines a valid range. It already exists. =
There is no need to invent some superconstructions that to convert this val=
id range in the same valid range, You already have it.</div><div><br></div>=
<div>Another example that I showed early is using either algorithm or class=
 methods equal_range. They all return a valid range do not they?</div><div>=
<br></div><div>Thus std::pair is an integral part of algorithms and ranges.=
 It is already used to specify a valid range. There is nothing to invent. A=
ll you need is to have an access to elements of the ranges they make up. To=
 have an access means that you need to get accfess to the beginning of the =
range and to the end of the range.</div><div><br></div><div>You have such a=
n access simply writing</div><div><br></div><div>for ( auto begin =3D p.fir=
st, end =3D p.second; begin !=3D end; ++begin ) { /*...*/ }</div><div><br><=
/div><div>There is no any need to deform algorithms.=C2=A0All you need you =
already have in your disposal.=C2=A0</div><div><br></div><div>Only instead =
of </div><div><br></div><div><div>for ( auto begin =3D p.first, end =3D p.s=
econd; begin !=3D end; ++begin ) { /*...*/ }</div><div><br></div><div>it is=
 better to write</div><div><br></div><div>for ( x : p ) { /(...*/ }</div><d=
iv><br></div><div>However according to your logic you prefer to use only=C2=
=A0this=C2=A0record of the loop</div><div><br></div><div><div>for ( auto be=
gin =3D p.first, end =3D p.second; begin !=3D end; ++begin ) { /*...*/ }</d=
iv><div><br></div><div>Why? Because your argument is that std::pair does no=
t set a range.:) It is funny.:)=C2=A0</div><div><br></div><div>I am sorry I=
 do not see any logic in your words. </div><div><br></div><div>Of course yo=
u can create a class that will be named something=C2=A0like ranges.=C2=A0 Y=
ou can even to build a hierarchy of such classes and numerous specializatio=
ns of the classes. :)</div><div><br></div><div>But to use the range that is=
 held in an object of type std::pair your classes are useless.</div><div><b=
r></div><div>All examples of code that I showed in this thread I wrote lite=
rally in 5-10 minutes without inventing any classes. Because it is natural =
way of using std::pair having a range.</div><div><br></div><div>On the othe=
r hand your hierarchy of classes of ranges has been created if I am not mis=
taken already several years. And in the examples I showed their usage is no=
 more than the usage of soap bubbles. </div><div><br></div><div>=C2=A0</div=
></div></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"ltr">If some objects don&#39;t gi=
ve you guarantees about something but you know in some cases it true then p=
roper way of use is EXPLICITLY show that it hold true.<br>In our case `std:=
:make_range` fulfill this requirements.<br><br>Probably solution for this p=
roblem are tagged pairs and tuples (IIRC they are form range proposition).<=
br>It look something like that:<br><div style=3D"border:1px solid rgb(187,1=
87,187);background-color:rgb(250,250,250)"><code><div><span style=3D"color:=
rgb(0,0,0)"><br></span><span style=3D"color:rgb(0,0,136)">extern</span><spa=
n style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">int=
</span><span style=3D"color:rgb(0,0,0)"> tab</span><span style=3D"color:rgb=
(102,102,0)">[</span><span style=3D"color:rgb(0,102,102)">10</span><span st=
yle=3D"color:rgb(102,102,0)">];</span><span style=3D"color:rgb(0,0,0)"><br>=
<br>std</span><span style=3D"color:rgb(102,102,0)">::</span><span style=3D"=
color:rgb(0,0,0)">pair</span><span style=3D"color:rgb(102,102,0)">&lt;</spa=
n><span style=3D"color:rgb(0,0,0)">std</span><span style=3D"color:rgb(102,1=
02,0)">::</span><span style=3D"color:rgb(0,0,0)">begin_tag</span><span styl=
e=3D"color:rgb(102,102,0)">&lt;</span><span style=3D"color:rgb(0,0,136)">in=
t</span><span style=3D"color:rgb(102,102,0)">*&gt;,</span><span style=3D"co=
lor:rgb(0,0,0)"> std</span><span style=3D"color:rgb(102,102,0)">::</span><s=
pan style=3D"color:rgb(0,0,0)">end_tag</span><span style=3D"color:rgb(102,1=
02,0)">&lt;</span><span style=3D"color:rgb(0,0,136)">int</span><span style=
=3D"color:rgb(102,102,0)">*&gt;&gt;</span><span style=3D"color:rgb(0,0,0)">=
 a</span><span style=3D"color:rgb(102,102,0)">;</span><span style=3D"color:=
rgb(0,0,0)"><br>std</span><span style=3D"color:rgb(102,102,0)">::</span><sp=
an style=3D"color:rgb(0,0,0)">pair</span><span style=3D"color:rgb(102,102,0=
)">&lt;</span><span style=3D"color:rgb(0,0,0)">std</span><span style=3D"col=
or:rgb(102,102,0)">::</span><span style=3D"color:rgb(0,0,0)">ptr_tag</span>=
<span style=3D"color:rgb(102,102,0)">&lt;</span><span style=3D"color:rgb(0,=
0,136)">int</span><span style=3D"color:rgb(102,102,0)">*&gt;,</span><span s=
tyle=3D"color:rgb(0,0,0)"> std</span><span style=3D"color:rgb(102,102,0)">:=
:</span><span style=3D"color:rgb(0,0,0)">success_tag</span><span style=3D"c=
olor:rgb(0,136,0)">&lt;bool&gt;</span><span style=3D"color:rgb(102,102,0)">=
&gt;</span><span style=3D"color:rgb(0,0,0)"> b</span><span style=3D"color:r=
gb(102,102,0)">;</span><span style=3D"color:rgb(0,0,0)"><br><br>a</span><sp=
an style=3D"color:rgb(102,102,0)">.</span><span style=3D"color:rgb(0,0,136)=
">begin</span><span style=3D"color:rgb(102,102,0)">()</span><span style=3D"=
color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">=3D</span><s=
pan style=3D"color:rgb(0,0,0)"> tab</span><span style=3D"color:rgb(102,102,=
0)">;</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:r=
gb(136,0,0)">//equal a.first =3D tab;</span><span style=3D"color:rgb(0,0,0)=
"><br>a</span><span style=3D"color:rgb(102,102,0)">.</span><span style=3D"c=
olor:rgb(0,0,136)">end</span><span style=3D"color:rgb(102,102,0)">()</span>=
<span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0=
)">=3D</span><span style=3D"color:rgb(0,0,0)"> tab </span><span style=3D"co=
lor:rgb(102,102,0)">+</span><span style=3D"color:rgb(0,0,0)"> </span><span =
style=3D"color:rgb(0,102,102)">10</span><span style=3D"color:rgb(102,102,0)=
">;</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb=
(136,0,0)">//equal a.second =3D tab + 10;</span><span style=3D"color:rgb(0,=
0,0)"><br></span><span style=3D"color:rgb(0,0,136)">for</span><span style=
=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">(</span>=
<span style=3D"color:rgb(0,0,136)">auto</span><span style=3D"color:rgb(102,=
102,0)">&amp;</span><span style=3D"color:rgb(0,0,0)"> x </span><span style=
=3D"color:rgb(102,102,0)">:</span><span style=3D"color:rgb(0,0,0)"> a</span=
><span style=3D"color:rgb(102,102,0)">)</span><span style=3D"color:rgb(0,0,=
0)"><br></span><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"=
color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136=
)">if</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:r=
gb(102,102,0)">(</span><span style=3D"color:rgb(0,0,0)">x </span><span styl=
e=3D"color:rgb(102,102,0)">=3D=3D</span><span style=3D"color:rgb(0,0,0)"> <=
/span><span style=3D"color:rgb(0,102,102)">5</span><span style=3D"color:rgb=
(102,102,0)">)</span><span style=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 </s=
pan><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(0=
,0,0)"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 b</span><span style=3D"color:rgb(102=
,102,0)">.</span><span style=3D"color:rgb(0,0,0)">ptr</span><span style=3D"=
color:rgb(102,102,0)">()</span><span style=3D"color:rgb(0,0,0)"> </span><sp=
an style=3D"color:rgb(102,102,0)">=3D</span><span style=3D"color:rgb(0,0,0)=
"> </span><span style=3D"color:rgb(102,102,0)">&amp;</span><span style=3D"c=
olor:rgb(0,0,0)">x</span><span style=3D"color:rgb(102,102,0)">;</span><span=
 style=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 b</span><span s=
tyle=3D"color:rgb(102,102,0)">.</span><span style=3D"color:rgb(0,0,0)">succ=
ess</span><span style=3D"color:rgb(102,102,0)">()</span><span style=3D"colo=
r:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">=3D</span><span =
style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">true<=
/span><span style=3D"color:rgb(102,102,0)">;</span><span style=3D"color:rgb=
(0,0,0)"><br>=C2=A0 =C2=A0 </span><span style=3D"color:rgb(102,102,0)">}</s=
pan><span style=3D"color:rgb(0,0,0)"><br></span><span style=3D"color:rgb(10=
2,102,0)">}</span><span style=3D"color:rgb(0,0,0)"><br></span><span style=
=3D"color:rgb(0,0,136)">return</span><span style=3D"color:rgb(0,0,0)"> b</s=
pan><span style=3D"color:rgb(102,102,0)">;</span></div></code></div><br></d=
iv></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_1079_1425436621.1437772419053--
------=_Part_1078_853807004.1437772419047--

.


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Sat, 25 Jul 2015 07:10:18 -0700 (PDT)
Raw View
------=_Part_34_418058296.1437833418851
Content-Type: multipart/alternative;
 boundary="----=_Part_35_2038876857.1437833418852"

------=_Part_35_2038876857.1437833418852
Content-Type: text/plain; charset=UTF-8



On Saturday, July 25, 2015 at 12:13:39 AM UTC+3, inkwizyt...@gmail.com
wrote:
>
>
> Pointers can made range, but they have `begin` and `end`? no. Because most
> of them don't made any range. Can you point me std class that have `begin`
> and `end` but they don't made range?
>
> Neither pointers nor arrays have begin and end. It is only user-defined
classes can have begin and end.

You can write any class that will provide begin and end and these begin and
end will not make up a range.

So in any case it is only the user responsibility to provide a valid range.

 The range-base for loop does not bother whether it has a valid range or
not. Moreover you can write a user class such a way that operators ++ and *
will have nothing common with ranges and the for-range loop will have
well-defined behaviour.

Relative to the range based for loop begin and end are not properties of a
container as you think.

 It is own interface of the range-based for loop. Simply the names of the
interface of the range-based for loop and names of member functions of some
containers can coincide. That is containers can provide its own
implementation of this interface of the range-based for loop.

It is similar to interfaces in C#. That is in fact it is a demonstration of
the C# notion of the interface  in C++.

Used by the range-based for statement functions begin and end and defined
in some class member functions begin and end are two different entities.
The range-based for loop provides an interface for the client code. How the
client code will use this interface (for example a class can
define member functions with the same name or you can define a
non-class function) is not important for the range-based for loop.

The only thing you have to guarantee that the work of the range-based for
loop using your implementation of its open interface would be well-defined.

Standard containers and standard algorithms already use std::pair to
specify a valid range. It is a basic type of the algorithms and containers.
And for this basic type basic operations should be provided  including
using it the range-based for loop.

Consider an example. There are character arrays in C that can contain
strings. You are going to write a class named string that will substitute
im the most situations using of the character arrays. I am going to write a
function named strlen that will define the length of a string stored in a
character array. And you say me: "Do not write the function because I will
write class string that will have member function size or length that will
return the size of a string" And implementing your class string you are
using the function that I was going to write. :)

A similar situation takes place with std::pair. There is a basic type that
is used to store valid ranges. And you say me: "Do not write begin and end
for std:; pair because I will write a suoerconstruction that will return
the same range as std::pair. Only I am sorry I also deform several
algorithms.":)

I do not see a great sense in this. Of course you may write a
superconstruction for ranges but I am sure that the basic type that is used
to store valid ranges should have also basic operations that will be used
where your suoerconstruction is btotally useless and all what it does is
forse the programmer to pay for what he does not use.

Over all what do you want is implicit conversation form pair to range. This
> is exactly same situation that conversation form int to enum.
> I know usage is right when why I need use cast every time? Its for making
> you remember that not every int can map to enum.
>
> Another approach, do pair have invariants of range? No. You should test
> before each use as range if is range. Who you inform other people that you
> use pair as range?
> Using comments? C++ have lot better tools for this. Special classes that
> will enforce it.
>
> int b;
> int a;
>
> foo0(&a, &b);
> foo1(std::make_pair(&a, &b));
> foo2(std::make_range(&a, &b));
> With of this functions are call incorrectly? I know that last one for sure
> is broken because I beak invariants of range constructor.
> I don't even need to read comments or look on implementation. This is why
> we have `shared_ptr` and `unique_ptr` instead of `T*`.
> This classes help us maintaining invariants, you can follow couple of
> simple rules and you will never have problems with memory leaks again.
>
> But with `std::pair` as range is impossible, you can have valid usage of
> pair that aren't ranges in your program. How do you reliable separate both
> usage?
> Again use different types for different concepts.
>
>
>
>
>
>
> On Friday, July 24, 2015 at 10:06:21 PM UTC+2, Vlad from Moscow wrote:
>>
>>
>>
>> On Friday, July 24, 2015 at 9:59:16 PM UTC+3, inkwizyt...@gmail.com
>> wrote:
>>>
>>> If some object have `begin` and `end` then its range. Most pair aren't
>>> ranges then they should not have this functions.
>>>
>>
>> Most pointers are not ranges. Does it mean that pointers can not make up
>> a range?
>>
>> Consider for example a dynamically allocated array. Does it has a range?
>>
>> How will you specify its range? I think you will specify it as a pair of
>> pointers will not you? So for example if you allocated an integer array of
>> size n and the address of the allocated area was stored in pointer a then
>> pair a and a + n set a valid range. How do you specify pairs in C++? I
>> suspect that you use std::pair.
>>
>> std::pair<int *, int *> range( a, a + n );
>>
>> or
>>
>> auto range = std::make_pair( a, a + n );
>>
>>
>> So if you have a pair that specifiers a valid range then you expect this
>> range can be used in for example the for range statement
>>
>> So it is natural and locgically consistent for example to write
>>
>> for ( int x : range ) std::cout << x << ' ';
>>
>> It is a valid record. Why? Because object range defines a valid range. It
>> already exists. There is no need to invent some superconstructions that to
>> convert this valid range in the same valid range, You already have it.
>>
>> Another example that I showed early is using either algorithm or class
>> methods equal_range. They all return a valid range do not they?
>>
>> Thus std::pair is an integral part of algorithms and ranges. It is
>> already used to specify a valid range. There is nothing to invent. All you
>> need is to have an access to elements of the ranges they make up. To have
>> an access means that you need to get accfess to the beginning of the range
>> and to the end of the range.
>>
>> You have such an access simply writing
>>
>> for ( auto begin = p.first, end = p.second; begin != end; ++begin ) {
>> /*...*/ }
>>
>> There is no any need to deform algorithms. All you need you already have
>> in your disposal.
>>
>> Only instead of
>>
>> for ( auto begin = p.first, end = p.second; begin != end; ++begin ) {
>> /*...*/ }
>>
>> it is better to write
>>
>> for ( x : p ) { /(...*/ }
>>
>> However according to your logic you prefer to use only this record of the
>> loop
>>
>> for ( auto begin = p.first, end = p.second; begin != end; ++begin ) {
>> /*...*/ }
>>
>> Why? Because your argument is that std::pair does not set a range.:) It
>> is funny.:)
>>
>> I am sorry I do not see any logic in your words.
>>
>> Of course you can create a class that will be named something like
>> ranges.  You can even to build a hierarchy of such classes and numerous
>> specializations of the classes. :)
>>
>> But to use the range that is held in an object of type std::pair your
>> classes are useless.
>>
>> All examples of code that I showed in this thread I wrote literally in
>> 5-10 minutes without inventing any classes. Because it is natural way of
>> using std::pair having a range.
>>
>> On the other hand your hierarchy of classes of ranges has been created if
>> I am not mistaken already several years. And in the examples I showed their
>> usage is no more than the usage of soap bubbles.
>>
>>
>>
>>> If some objects don't give you guarantees about something but you know
>>> in some cases it true then proper way of use is EXPLICITLY show that it
>>> hold true.
>>> In our case `std::make_range` fulfill this requirements.
>>>
>>> Probably solution for this problem are tagged pairs and tuples (IIRC
>>> they are form range proposition).
>>> It look something like that:
>>>
>>> extern int tab[10];
>>>
>>> std::pair<std::begin_tag<int*>, std::end_tag<int*>> a;
>>> std::pair<std::ptr_tag<int*>, std::success_tag<bool>> b;
>>>
>>> a.begin() = tab; //equal a.first = tab;
>>> a.end() = tab + 10; //equal a.second = tab + 10;
>>> for (auto& x : a)
>>> {
>>>     if (x == 5)
>>>     {
>>>         b.ptr() = &x;
>>>         b.success() = true;
>>>     }
>>> }
>>> return b;
>>>
>>>

--

---
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_35_2038876857.1437833418852
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Saturday, July 25, 2015 at 12:13:39 AM UTC+3, i=
nkwizyt...@gmail.com wrote:<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><br></div><div>Pointers can made range, but they have `begin` and `end`?=
 no. Because most of them don&#39;t made any range. Can you point me std cl=
ass that have `begin` and `end` but they don&#39;t made range?<br><br></div=
></div></blockquote><div>Neither pointers nor arrays have begin and end. It=
 is only user-defined classes can have begin and end.</div><div><br></div><=
div>You can write any class that will provide begin and end and these begin=
 and end will not make up a range.</div><div><br></div><div>So in any case =
it is only the user responsibility to provide a valid range.</div><div><br>=
</div><div>=C2=A0The range-base for=C2=A0loop does not bother whether it ha=
s a valid range or not. Moreover you can write a user class such a way that=
 operators ++ and * will have nothing common with ranges and the for-range =
loop will have well-defined behaviour.</div><div><br></div><div>Relative to=
 the range based for loop begin and end=C2=A0are not=C2=A0properties of a c=
ontainer as you think.</div><div><br></div><div>=C2=A0It is=C2=A0own interf=
ace of the range-based for loop. Simply the names of the interface of the r=
ange-based for loop and names of member functions of=C2=A0some containers c=
an coincide. That is=C2=A0containers can provide its own implementation of =
this interface of the range-based for loop.</div><div><br></div><div>It is =
similar to interfaces in C#. That is in fact it is a demonstration of the C=
# notion of the interface=C2=A0 in C++.</div><div><br></div><div>Used by th=
e range-based for statement functions begin and end and defined in some cla=
ss member functions begin and end=C2=A0are=C2=A0two different entities. The=
=C2=A0range-based for loop provides an interface for the client code. How t=
he client code will use this interface (for example a class=C2=A0can define=
=C2=A0member=C2=A0functions with the same name or you can define a non-clas=
s=C2=A0function) is not important for the range-based for loop.=C2=A0=C2=A0=
</div><div>=C2=A0</div><div>The only thing you have to guarantee that the=
=C2=A0work of the range-based for loop using your implementation of its ope=
n interface=C2=A0would be well-defined.</div><div><br></div><div>Standard c=
ontainers and standard algorithms already use std::pair to specify a valid =
range. It is a basic type of the algorithms and containers. And for this ba=
sic type basic operations should be provided=C2=A0 including using it the r=
ange-based for loop.</div><div><br></div><div>Consider an example. There ar=
e character arrays in C that can contain strings. You are going to write a =
class named string that will substitute im the most situations using of the=
 character arrays. I am going to write a function named strlen that will de=
fine the length of a string stored in a character array. And you say me: &q=
uot;Do not write the function because I will write class string that will h=
ave member function size or length that will return the size of a string&qu=
ot; And implementing your class string you are using the function that I wa=
s going to write. :)</div><div><br></div><div>A similar situation takes pla=
ce with std::pair. There is a basic type that is used to store valid ranges=
.. And you say me: &quot;Do not write begin and end for std:; pair because I=
 will write a suoerconstruction that will return the same range as std::pai=
r. Only I am sorry I also deform several algorithms.&quot;:)</div><div><br>=
</div><div>I do not see a great sense in this. Of course you may write a su=
perconstruction for ranges but I am sure that the basic type that is used t=
o store valid ranges should have also basic operations that will be used wh=
ere your suoerconstruction is btotally useless and all what it does is fors=
e the programmer to pay for what he does not use.</div><div><br></div><bloc=
kquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-le=
ft: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; bor=
der-left-style: solid;"><div dir=3D"ltr"><div>Over all what do you want is =
implicit conversation form pair to range. This is exactly same situation th=
at conversation form int to enum.<br>I know usage is right when why I need =
use cast every time? Its for making you remember that not every int can map=
 to enum.<br><br>Another approach, do pair have invariants of range? No. Yo=
u should test before each use as range if is range. Who you inform other pe=
ople that you use pair as range?<br>Using comments? C++ have lot better too=
ls for this. Special classes that will enforce it.<br><div style=3D"border:=
 1px solid rgb(187, 187, 187); border-image: none; -ms-word-wrap: break-wor=
d; background-color: rgb(250, 250, 250);"><code><div><span style=3D"color: =
rgb(0, 0, 0);"><br></span><span style=3D"color: rgb(0, 0, 136);">int</span>=
<span style=3D"color: rgb(0, 0, 0);"> b</span><span style=3D"color: rgb(102=
, 102, 0);">;</span><br><span style=3D"color: rgb(0, 0, 0);"><code><span st=
yle=3D"color: rgb(0, 0, 136);">int</span><span style=3D"color: rgb(0, 0, 0)=
;"> a</span><span style=3D"color: rgb(102, 102, 0);">;</span><span style=3D=
"color: rgb(0, 0, 0);"><br><br></span></code>foo0</span><span style=3D"colo=
r: rgb(102, 102, 0);">(&amp;</span><span style=3D"color: rgb(0, 0, 0);">a</=
span><span style=3D"color: rgb(102, 102, 0);">,</span><span style=3D"color:=
 rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 102, 0);">&amp;</spa=
n><span style=3D"color: rgb(0, 0, 0);">b</span><span style=3D"color: rgb(10=
2, 102, 0);">);</span><span style=3D"color: rgb(0, 0, 0);"><br>foo1</span><=
span style=3D"color: rgb(102, 102, 0);">(</span><span style=3D"color: rgb(0=
, 0, 0);">std</span><span style=3D"color: rgb(102, 102, 0);">::</span><span=
 style=3D"color: rgb(0, 0, 0);">make_pair</span><span style=3D"color: rgb(1=
02, 102, 0);">(&amp;</span><span style=3D"color: rgb(0, 0, 0);">a</span><sp=
an style=3D"color: rgb(102, 102, 0);">,</span><span style=3D"color: rgb(0, =
0, 0);"> </span><span style=3D"color: rgb(102, 102, 0);">&amp;</span><span =
style=3D"color: rgb(0, 0, 0);">b</span><span style=3D"color: rgb(102, 102, =
0);">));</span><span style=3D"color: rgb(0, 0, 0);"><br>foo2</span><span st=
yle=3D"color: rgb(102, 102, 0);">(</span><span style=3D"color: rgb(0, 0, 0)=
;">std</span><span style=3D"color: rgb(102, 102, 0);">::</span><span style=
=3D"color: rgb(0, 0, 0);">make_range</span><span style=3D"color: rgb(102, 1=
02, 0);">(&amp;</span><span style=3D"color: rgb(0, 0, 0);">a</span><span st=
yle=3D"color: rgb(102, 102, 0);">,</span><span style=3D"color: rgb(0, 0, 0)=
;"> </span><span style=3D"color: rgb(102, 102, 0);">&amp;</span><span style=
=3D"color: rgb(0, 0, 0);">b</span><span style=3D"color: rgb(102, 102, 0);">=
));</span></div></code></div>With of this functions are call incorrectly? I=
 know that last one for sure is broken because I beak invariants of range c=
onstructor.<br>I don&#39;t even need to read comments or look on implementa=
tion. This is why we have `shared_ptr` and `unique_ptr` instead of `T*`.<br=
>This classes help us maintaining invariants, you can follow couple of simp=
le rules and you will never have problems with memory leaks again.<br><br>B=
ut with `std::pair` as range is impossible, you can have valid usage of pai=
r that aren&#39;t ranges in your program. How do you reliable separate both=
 usage?<br>Again use different types for different concepts.<br><br><br><br=
><br></div><br><br>On Friday, July 24, 2015 at 10:06:21 PM UTC+2, Vlad from=
 Moscow wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0p=
x 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-l=
eft-width: 1px; border-left-style: solid;"><div dir=3D"ltr"><br><br>On Frid=
ay, July 24, 2015 at 9:59:16 PM UTC+3, <a>inkwizyt...@gmail.com</a> wrote:<=
blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; paddin=
g-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px;=
 border-left-style: solid;"><div dir=3D"ltr">If some object have `begin` an=
d `end` then its range. Most pair aren&#39;t ranges then they should not ha=
ve this functions.<br></div></blockquote><div><br></div><div>Most pointers =
are not ranges. Does it mean that pointers can not make up a range? </div><=
div><br></div><div>Consider for example a dynamically allocated array. Does=
 it has a range?</div><br></div></blockquote><blockquote class=3D"gmail_quo=
te" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-colo=
r: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;"><=
div dir=3D"ltr"><div></div><div>How will you specify its range? I think you=
 will specify it as a pair of pointers will not you? So for example if you =
allocated an integer array of size n and the address of the allocated area =
was stored in pointer=C2=A0a then pair=C2=A0a and=C2=A0a + n set a valid ra=
nge. How do you specify pairs in C++? I suspect that you use std::pair.</di=
v><div><br></div><div>std::pair&lt;int *, int *&gt; range( a, a + n );</div=
><div><br></div><div>or</div><div><br></div><div>auto range =3D std::make_p=
air( a, a + n );</div><div><br></div><div><br></div><div>So if you have a p=
air that specifiers a valid range then you expect this range can be used in=
 for example the for range statement</div><div><br></div><div>So it is natu=
ral and locgically consistent for example to write</div><div><br></div><div=
>for ( int x :=C2=A0range ) std::cout &lt;&lt; x &lt;&lt; &#39; &#39;;</div=
><div><br></div><div>It is a valid record. Why? Because=C2=A0object range d=
efines a valid range. It already exists. There is no need to invent some su=
perconstructions that to convert this valid range in the same valid range, =
You already have it.</div><div><br></div><div>Another example that I showed=
 early is using either algorithm or class methods equal_range. They all ret=
urn a valid range do not they?</div><div><br></div><div>Thus std::pair is a=
n integral part of algorithms and ranges. It is already used to specify a v=
alid range. There is nothing to invent. All you need is to have an access t=
o elements of the ranges they make up. To have an access means that you nee=
d to get accfess to the beginning of the range and to the end of the range.=
</div><div><br></div><div>You have such an access simply writing</div><div>=
<br></div><div>for ( auto begin =3D p.first, end =3D p.second; begin !=3D e=
nd; ++begin ) { /*...*/ }</div><div><br></div><div>There is no any need to =
deform algorithms.=C2=A0All you need you already have in your disposal.=C2=
=A0</div><div><br></div><div>Only instead of </div><div><br></div><div><div=
>for ( auto begin =3D p.first, end =3D p.second; begin !=3D end; ++begin ) =
{ /*...*/ }</div><div><br></div><div>it is better to write</div><div><br></=
div><div>for ( x : p ) { /(...*/ }</div><div><br></div><div>However accordi=
ng to your logic you prefer to use only=C2=A0this=C2=A0record of the loop</=
div><div><br></div><div><div>for ( auto begin =3D p.first, end =3D p.second=
; begin !=3D end; ++begin ) { /*...*/ }</div><div><br></div><div>Why? Becau=
se your argument is that std::pair does not set a range.:) It is funny.:)=
=C2=A0</div><div><br></div><div>I am sorry I do not see any logic in your w=
ords. </div><div><br></div><div>Of course you can create a class that will =
be named something=C2=A0like ranges.=C2=A0 You can even to build a hierarch=
y of such classes and numerous specializations of the classes. :)</div><div=
><br></div><div>But to use the range that is held in an object of type std:=
:pair your classes are useless.</div><div><br></div><div>All examples of co=
de that I showed in this thread I wrote literally in 5-10 minutes without i=
nventing any classes. Because it is natural way of using std::pair having a=
 range.</div><div><br></div><div>On the other hand your hierarchy of classe=
s of ranges has been created if I am not mistaken already several years. An=
d in the examples I showed their usage is no more than the usage of soap bu=
bbles. </div><div><br></div><div>=C2=A0</div></div></div><blockquote class=
=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; bor=
der-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-sty=
le: solid;"><div dir=3D"ltr">If some objects don&#39;t give you guarantees =
about something but you know in some cases it true then proper way of use i=
s EXPLICITLY show that it hold true.<br>In our case `std::make_range` fulfi=
ll this requirements.<br><br>Probably solution for this problem are tagged =
pairs and tuples (IIRC they are form range proposition).<br>It look somethi=
ng like that:<br><div style=3D"border: 1px solid rgb(187, 187, 187); border=
-image: none; background-color: rgb(250, 250, 250);"><code><div><span style=
=3D"color: rgb(0, 0, 0);"><br></span><span style=3D"color: rgb(0, 0, 136);"=
>extern</span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"c=
olor: rgb(0, 0, 136);">int</span><span style=3D"color: rgb(0, 0, 0);"> tab<=
/span><span style=3D"color: rgb(102, 102, 0);">[</span><span style=3D"color=
: rgb(0, 102, 102);">10</span><span style=3D"color: rgb(102, 102, 0);">];</=
span><span style=3D"color: rgb(0, 0, 0);"><br><br>std</span><span style=3D"=
color: rgb(102, 102, 0);">::</span><span style=3D"color: rgb(0, 0, 0);">pai=
r</span><span style=3D"color: rgb(102, 102, 0);">&lt;</span><span style=3D"=
color: rgb(0, 0, 0);">std</span><span style=3D"color: rgb(102, 102, 0);">::=
</span><span style=3D"color: rgb(0, 0, 0);">begin_tag</span><span style=3D"=
color: rgb(102, 102, 0);">&lt;</span><span style=3D"color: rgb(0, 0, 136);"=
>int</span><span style=3D"color: rgb(102, 102, 0);">*&gt;,</span><span styl=
e=3D"color: rgb(0, 0, 0);"> std</span><span style=3D"color: rgb(102, 102, 0=
);">::</span><span style=3D"color: rgb(0, 0, 0);">end_tag</span><span style=
=3D"color: rgb(102, 102, 0);">&lt;</span><span style=3D"color: rgb(0, 0, 13=
6);">int</span><span style=3D"color: rgb(102, 102, 0);">*&gt;&gt;</span><sp=
an style=3D"color: rgb(0, 0, 0);"> a</span><span style=3D"color: rgb(102, 1=
02, 0);">;</span><span style=3D"color: rgb(0, 0, 0);"><br>std</span><span s=
tyle=3D"color: rgb(102, 102, 0);">::</span><span style=3D"color: rgb(0, 0, =
0);">pair</span><span style=3D"color: rgb(102, 102, 0);">&lt;</span><span s=
tyle=3D"color: rgb(0, 0, 0);">std</span><span style=3D"color: rgb(102, 102,=
 0);">::</span><span style=3D"color: rgb(0, 0, 0);">ptr_tag</span><span sty=
le=3D"color: rgb(102, 102, 0);">&lt;</span><span style=3D"color: rgb(0, 0, =
136);">int</span><span style=3D"color: rgb(102, 102, 0);">*&gt;,</span><spa=
n style=3D"color: rgb(0, 0, 0);"> std</span><span style=3D"color: rgb(102, =
102, 0);">::</span><span style=3D"color: rgb(0, 0, 0);">success_tag</span><=
span style=3D"color: rgb(0, 136, 0);">&lt;bool&gt;</span><span style=3D"col=
or: rgb(102, 102, 0);">&gt;</span><span style=3D"color: rgb(0, 0, 0);"> b</=
span><span style=3D"color: rgb(102, 102, 0);">;</span><span style=3D"color:=
 rgb(0, 0, 0);"><br><br>a</span><span style=3D"color: rgb(102, 102, 0);">.<=
/span><span style=3D"color: rgb(0, 0, 136);">begin</span><span style=3D"col=
or: rgb(102, 102, 0);">()</span><span style=3D"color: rgb(0, 0, 0);"> </spa=
n><span style=3D"color: rgb(102, 102, 0);">=3D</span><span style=3D"color: =
rgb(0, 0, 0);"> tab</span><span style=3D"color: rgb(102, 102, 0);">;</span>=
<span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(136,=
 0, 0);">//equal a.first =3D tab;</span><span style=3D"color: rgb(0, 0, 0);=
"><br>a</span><span style=3D"color: rgb(102, 102, 0);">.</span><span style=
=3D"color: rgb(0, 0, 136);">end</span><span style=3D"color: rgb(102, 102, 0=
);">()</span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"co=
lor: rgb(102, 102, 0);">=3D</span><span style=3D"color: rgb(0, 0, 0);"> tab=
 </span><span style=3D"color: rgb(102, 102, 0);">+</span><span style=3D"col=
or: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(0, 102, 102);">10</spa=
n><span style=3D"color: rgb(102, 102, 0);">;</span><span style=3D"color: rg=
b(0, 0, 0);"> </span><span style=3D"color: rgb(136, 0, 0);">//equal a.secon=
d =3D tab + 10;</span><span style=3D"color: rgb(0, 0, 0);"><br></span><span=
 style=3D"color: rgb(0, 0, 136);">for</span><span style=3D"color: rgb(0, 0,=
 0);"> </span><span style=3D"color: rgb(102, 102, 0);">(</span><span style=
=3D"color: rgb(0, 0, 136);">auto</span><span style=3D"color: rgb(102, 102, =
0);">&amp;</span><span style=3D"color: rgb(0, 0, 0);"> x </span><span style=
=3D"color: rgb(102, 102, 0);">:</span><span style=3D"color: rgb(0, 0, 0);">=
 a</span><span style=3D"color: rgb(102, 102, 0);">)</span><span style=3D"co=
lor: rgb(0, 0, 0);"><br></span><span style=3D"color: rgb(102, 102, 0);">{</=
span><span style=3D"color: rgb(0, 0, 0);"><br>=C2=A0 =C2=A0 </span><span st=
yle=3D"color: rgb(0, 0, 136);">if</span><span style=3D"color: rgb(0, 0, 0);=
"> </span><span style=3D"color: rgb(102, 102, 0);">(</span><span style=3D"c=
olor: rgb(0, 0, 0);">x </span><span style=3D"color: rgb(102, 102, 0);">=3D=
=3D</span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color=
: rgb(0, 102, 102);">5</span><span style=3D"color: rgb(102, 102, 0);">)</sp=
an><span style=3D"color: rgb(0, 0, 0);"><br>=C2=A0 =C2=A0 </span><span styl=
e=3D"color: rgb(102, 102, 0);">{</span><span style=3D"color: rgb(0, 0, 0);"=
><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 b</span><span style=3D"color: rgb(102, 102=
, 0);">.</span><span style=3D"color: rgb(0, 0, 0);">ptr</span><span style=
=3D"color: rgb(102, 102, 0);">()</span><span style=3D"color: rgb(0, 0, 0);"=
> </span><span style=3D"color: rgb(102, 102, 0);">=3D</span><span style=3D"=
color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 102, 0);">&amp=
;</span><span style=3D"color: rgb(0, 0, 0);">x</span><span style=3D"color: =
rgb(102, 102, 0);">;</span><span style=3D"color: rgb(0, 0, 0);"><br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 b</span><span style=3D"color: rgb(102, 102, 0);">.</sp=
an><span style=3D"color: rgb(0, 0, 0);">success</span><span style=3D"color:=
 rgb(102, 102, 0);">()</span><span style=3D"color: rgb(0, 0, 0);"> </span><=
span style=3D"color: rgb(102, 102, 0);">=3D</span><span style=3D"color: rgb=
(0, 0, 0);"> </span><span style=3D"color: rgb(0, 0, 136);">true</span><span=
 style=3D"color: rgb(102, 102, 0);">;</span><span style=3D"color: rgb(0, 0,=
 0);"><br>=C2=A0 =C2=A0 </span><span style=3D"color: rgb(102, 102, 0);">}</=
span><span style=3D"color: rgb(0, 0, 0);"><br></span><span style=3D"color: =
rgb(102, 102, 0);">}</span><span style=3D"color: rgb(0, 0, 0);"><br></span>=
<span style=3D"color: rgb(0, 0, 136);">return</span><span style=3D"color: r=
gb(0, 0, 0);"> b</span><span style=3D"color: rgb(102, 102, 0);">;</span></d=
iv></code></div><br></div></blockquote></div></blockquote></div></blockquot=
e></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_35_2038876857.1437833418852--
------=_Part_34_418058296.1437833418851--

.


Author: Thiago Macieira <thiago@macieira.org>
Date: Sat, 25 Jul 2015 10:40:23 -0700
Raw View
On Saturday 25 July 2015 07:10:18 Vlad from Moscow wrote:
> A similar situation takes place with std::pair. There is a basic type that
> is used to store valid ranges.

Those two sentences are true but the latter does not imply that std::pair is
that type.

A range is a pair of iterators. But any pair of iterators does not make a
range. The problem is that a pair is, on itself, a container and could be
iterated on.

I don't have a problem in providing a way to iterate over a pair of iterators
as a range. Just don't mess with std::pair.

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

--

---
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/.

.


Author: Matthew Woehlke <mwoehlke.floss@gmail.com>
Date: Mon, 27 Jul 2015 11:11:58 -0400
Raw View
On 2015-07-24 09:10, Vlad from Moscow wrote:
> The C++ Standard already has all needed to do the task.  And if you have a
> pair of iterators that make up a range then why do you need to build a
> range from already existent valid range?! Simply write
>
>     for ( auto x : p ) ...;

....because you have stated that 'p' is a std::pair, i.e. a generic
container type (albeit of exactly two elements). Range-based for on a
container iterates over the elements in that container. It does NOT
magically reinterpret the container according to some arbitrary assumed
semantics.

If you want a range, give a range. Don't give "something that kinda
sorta maybe might look a little like a range if you tilt your head
sideways and squint".

> There is such principle KISS in programming that means Keep It Simple
> Stupid.

There is also the Principle of Least Surprise. Your proposal
gratuitously violates it.

I don't see that any of your examples are valid. Your examples where you
used make_pair are clearly wrong; you meant to use make_range. Your
minmax_element example is highly dubious; the return of said function is
not semantically a range, and the contortions you go through to make it
such ought to be telling you that you're doing something that's not
intended use. (And equal_range clearly should be returning a range...
that might be interesting to fix, but fixing it is the right thing to
do. Not abusing std::pair.)

On 2015-07-25 10:10, Vlad from Moscow wrote:
> You can write any class that will provide begin and end and these begin and
> end will not make up a range.

I think you are reading more into the idea of "range" than is intended.
A "range" is a valid, bounded iteration sequence. Nothing more. In
particular, it does not necessarily have any relation to container
iterators. The IP subnet 192.168.0.0/24 is a "range". More generally, I
would say that any iterator pair where the iterators are equal (empty
range) or incrementing from the first iterator will eventually arrive at
the second iterator without at any point going off into la la land
(valid range) is a "range".

This does not precisely mean that a "range" *is* an iterator pair,
although being iterable implies that one can always *get* an iterator
pair from a range. Keep in mind also that the notion of "iterator" is
quite broad, e.g. checking for equality to the "end" iterator may mean
checking the dereferenced iterator against a sentinel value.

If, given that definition, some class has begin() and end() that do NOT
form a range, then that class is badly designed. Most would say "broken".

> Standard containers and standard algorithms already use std::pair to
> specify a valid range.

....which, per above, is a problem that should be fixed, not made worse
by compounding the mistake.

--
Matthew

--

---
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/.

.