Topic: Re: [std-proposals] Add value function for ass


Author: Tony V E <tvaneerd@gmail.com>
Date: Mon, 27 Jan 2014 17:32:31 -0500
Raw View
--089e012289348a0f1e04f0fb4837
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

On Mon, Jan 27, 2014 at 5:30 PM, Andrey Matveyakin
<a.matveyakin@gmail.com>wrote:

> I propose to add a function called =93value=94 to all standard associativ=
e
> containers. It should work like =93operator[]=94 or =93at=94 function exc=
ept that
> it returns a default value when there is not such key in the container.
>
> The signature is
>
> T container::value(const Key& key, const T& default_value =3D T()) const;
> for std::map, std::unordered_map, etc. and
>
> T container::value(int index, const T& default_value =3D T()) const;
> for std::vector, etc.
>
> Qt users are already familiar with the =93value=94 function: all the Qt
> containers (QList, QMap, QHash, etc.) have it. Java provides similar
> functionality via =93get=94 function. The =93value=94 function is very co=
nvenient
> in many cases and its equivalent expression (find + if or ternary operato=
r)
> bloats the code a lot, so I no reason why we can't have it.
>
> --
>
>
>

std::experimental::optional will have a value_or() function with similar
signature (ie with a default_value).  Maybe that's what it should be called=
?

Tony

--=20

---=20
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 e=
mail 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-proposa=
ls/.

--089e012289348a0f1e04f0fb4837
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><br><div class=3D"gmail=
_quote">On Mon, Jan 27, 2014 at 5:30 PM, Andrey Matveyakin <span dir=3D"ltr=
">&lt;<a href=3D"mailto:a.matveyakin@gmail.com" target=3D"_blank">a.matveya=
kin@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr">I propose to add a function=
 called =93value=94 to all standard associative containers. It should work =
like =93operator[]=94 or =93at=94 function except that it returns a default=
 value when there is not such key in the container.<br>
<br>The signature is<br><br>T container::value(const Key&amp; key, const T&=
amp; default_value =3D T()) const;<br>for std::map, std::unordered_map, etc=
.. and<br><br>T container::value(int index, const T&amp; default_value =3D T=
()) const;<br>
for std::vector, etc.<br><br>Qt users are already familiar with the =93valu=
e=94 function: all the Qt containers (QList, QMap, QHash, etc.) have it. Ja=
va provides similar functionality via =93get=94 function. The =93value=94 f=
unction is very convenient in many cases and its equivalent expression (fin=
d + if or ternary operator) bloats the code a lot, so I no reason why we ca=
n&#39;t have it.<span class=3D"HOEnZb"><font color=3D"#888888"><br>
</font></span></div><span class=3D"HOEnZb"><font color=3D"#888888">

<p></p>

-- <br>=A0
<br><br></font></span></blockquote><div><br><br></div><div>std::experimenta=
l::optional will have a value_or() function with similar signature (ie with=
 a default_value).=A0 Maybe that&#39;s what it should be called?<br><br>
Tony<br><br></div></div><br></div></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />

--089e012289348a0f1e04f0fb4837--

.


Author: "Billy O'Neal" <billy.oneal@gmail.com>
Date: Mon, 27 Jan 2014 14:45:09 -0800
Raw View
--089e0149ce3c18cc4704f0fb7887
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

What do you want to happen when T is noncopyable?

You can always write your own function that has the semantics you want;
e.g. value_or_default(Container, Index).

Billy O'Neal
https://github.com/BillyONeal/ <https://bitbucket.org/BillyONeal/>
http://stackoverflow.com/users/82320/billy-oneal


On Mon, Jan 27, 2014 at 2:30 PM, Andrey Matveyakin
<a.matveyakin@gmail.com>wrote:

> I propose to add a function called =E2=80=9Cvalue=E2=80=9D to all standar=
d associative
> containers. It should work like =E2=80=9Coperator[]=E2=80=9D or =E2=80=9C=
at=E2=80=9D function except that
> it returns a default value when there is not such key in the container.
>
> The signature is
>
> T container::value(const Key& key, const T& default_value =3D T()) const;
> for std::map, std::unordered_map, etc. and
>
> T container::value(int index, const T& default_value =3D T()) const;
> for std::vector, etc.
>
> Qt users are already familiar with the =E2=80=9Cvalue=E2=80=9D function: =
all the Qt
> containers (QList, QMap, QHash, etc.) have it. Java provides similar
> functionality via =E2=80=9Cget=E2=80=9D function. The =E2=80=9Cvalue=E2=
=80=9D function is very convenient
> in many cases and its equivalent expression (find + if or ternary operato=
r)
> bloats the code a lot, so I no reason why we can't have it.
>
> --
>
> ---
> 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/.
>

--=20

---=20
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 e=
mail 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-proposa=
ls/.

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

<div dir=3D"ltr">What do you want to happen when T is noncopyable?<div><br>=
</div><div>You can always write your own function that has the semantics yo=
u want; e.g. value_or_default(Container, Index).</div></div><div class=3D"g=
mail_extra">

<br clear=3D"all"><div><div dir=3D"ltr"><div>Billy O&#39;Neal</div><div><a =
href=3D"https://bitbucket.org/BillyONeal/" target=3D"_blank">https://github=
..com/BillyONeal/</a></div><div><a href=3D"http://stackoverflow.com/users/82=
320/billy-oneal" target=3D"_blank">http://stackoverflow.com/users/82320/bil=
ly-oneal</a></div>

</div></div>
<br><br><div class=3D"gmail_quote">On Mon, Jan 27, 2014 at 2:30 PM, Andrey =
Matveyakin <span dir=3D"ltr">&lt;<a href=3D"mailto:a.matveyakin@gmail.com" =
target=3D"_blank">a.matveyakin@gmail.com</a>&gt;</span> wrote:<br><blockquo=
te class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc so=
lid;padding-left:1ex">

<div dir=3D"ltr">I propose to add a function called =E2=80=9Cvalue=E2=80=9D=
 to all standard associative containers. It should work like =E2=80=9Copera=
tor[]=E2=80=9D or =E2=80=9Cat=E2=80=9D function except that it returns a de=
fault value when there is not such key in the container.<br>

<br>The signature is<br><br>T container::value(const Key&amp; key, const T&=
amp; default_value =3D T()) const;<br>for std::map, std::unordered_map, etc=
.. and<br><br>T container::value(int index, const T&amp; default_value =3D T=
()) const;<br>

for std::vector, etc.<br><br>Qt users are already familiar with the =E2=80=
=9Cvalue=E2=80=9D function: all the Qt containers (QList, QMap, QHash, etc.=
) have it. Java provides similar functionality via =E2=80=9Cget=E2=80=9D fu=
nction. The =E2=80=9Cvalue=E2=80=9D function is very convenient in many cas=
es and its equivalent expression (find + if or ternary operator) bloats the=
 code a lot, so I no reason why we can&#39;t have it.<span class=3D"HOEnZb"=
><font color=3D"#888888"><br>

</font></span></div><span class=3D"HOEnZb"><font color=3D"#888888">

<p></p>

-- <br>
=C2=A0<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%2Bunsubscribe@isocpp.org" target=3D=
"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</font></span></blockquote></div><br></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />

--089e0149ce3c18cc4704f0fb7887--

.


Author: matveyakin@gmail.com
Date: Mon, 27 Jan 2014 14:54:16 -0800 (PST)
Raw View
------=_Part_922_18446838.1390863256832
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Name is not really important for me. I just thought that the one used in Qt=
=20
is good because it's short and Qt programmers are already familiar with it.=
=20
But the consistency across the standard library is of course more=20
important. So if all the functions like these will be called =E2=80=9Cvalue=
_or=E2=80=9D =E2=80=94=20
let it be.

=D0=B2=D1=82=D0=BE=D1=80=D0=BD=D0=B8=D0=BA, 28 =D1=8F=D0=BD=D0=B2=D0=B0=D1=
=80=D1=8F 2014 =D0=B3., 2:32:31 UTC+4 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=
=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C Tony V E =D0=BD=D0=B0=D0=BF=D0=B8=D1=
=81=D0=B0=D0=BB:
>
>
>
>
> On Mon, Jan 27, 2014 at 5:30 PM, Andrey Matveyakin <a.matv...@gmail.com<j=
avascript:>
> > wrote:
>
>> I propose to add a function called =E2=80=9Cvalue=E2=80=9D to all standa=
rd associative=20
>> containers. It should work like =E2=80=9Coperator[]=E2=80=9D or =E2=80=
=9Cat=E2=80=9D function except that=20
>> it returns a default value when there is not such key in the container.
>>
>> The signature is
>>
>> T container::value(const Key& key, const T& default_value =3D T()) const=
;
>> for std::map, std::unordered_map, etc. and
>>
>> T container::value(int index, const T& default_value =3D T()) const;
>> for std::vector, etc.
>>
>> Qt users are already familiar with the =E2=80=9Cvalue=E2=80=9D function:=
 all the Qt=20
>> containers (QList, QMap, QHash, etc.) have it. Java provides similar=20
>> functionality via =E2=80=9Cget=E2=80=9D function. The =E2=80=9Cvalue=E2=
=80=9D function is very convenient=20
>> in many cases and its equivalent expression (find + if or ternary operat=
or)=20
>> bloats the code a lot, so I no reason why we can't have it.
>> =20
>> --=20
>>  =20
>>
>>
>
> std::experimental::optional will have a value_or() function with similar=
=20
> signature (ie with a default_value).  Maybe that's what it should be call=
ed?
>
> Tony
>
>
>

--=20

---=20
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 e=
mail 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-proposa=
ls/.

------=_Part_922_18446838.1390863256832
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Name is not really important for me. I just thought that t=
he one used in Qt is good because it's short and Qt programmers are already=
 familiar with it. But the consistency across the standard library is of co=
urse more important. So if all the functions like these will be called =E2=
=80=9Cvalue_or=E2=80=9D =E2=80=94 let it be.<br><br>=D0=B2=D1=82=D0=BE=D1=
=80=D0=BD=D0=B8=D0=BA, 28 =D1=8F=D0=BD=D0=B2=D0=B0=D1=80=D1=8F 2014&nbsp;=
=D0=B3., 2:32:31 UTC+4 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=
=82=D0=B5=D0=BB=D1=8C Tony V E =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:<=
blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bord=
er-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><br><div><br><=
br><div class=3D"gmail_quote">On Mon, Jan 27, 2014 at 5:30 PM, Andrey Matve=
yakin <span dir=3D"ltr">&lt;<a href=3D"javascript:" target=3D"_blank" gdf-o=
bfuscated-mailto=3D"pfFizROMYSgJ" onmousedown=3D"this.href=3D'javascript:';=
return true;" onclick=3D"this.href=3D'javascript:';return true;">a.matv...@=
gmail.com</a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr">I propose to add a function=
 called =E2=80=9Cvalue=E2=80=9D to all standard associative containers. It =
should work like =E2=80=9Coperator[]=E2=80=9D or =E2=80=9Cat=E2=80=9D funct=
ion except that it returns a default value when there is not such key in th=
e container.<br>
<br>The signature is<br><br>T container::value(const Key&amp; key, const T&=
amp; default_value =3D T()) const;<br>for std::map, std::unordered_map, etc=
.. and<br><br>T container::value(int index, const T&amp; default_value =3D T=
()) const;<br>
for std::vector, etc.<br><br>Qt users are already familiar with the =E2=80=
=9Cvalue=E2=80=9D function: all the Qt containers (QList, QMap, QHash, etc.=
) have it. Java provides similar functionality via =E2=80=9Cget=E2=80=9D fu=
nction. The =E2=80=9Cvalue=E2=80=9D function is very convenient in many cas=
es and its equivalent expression (find + if or ternary operator) bloats the=
 code a lot, so I no reason why we can't have it.<span><font color=3D"#8888=
88"><br>
</font></span></div><span><font color=3D"#888888">

<p></p>

-- <br>&nbsp;
<br><br></font></span></blockquote><div><br><br></div><div>std::experimenta=
l::optional will have a value_or() function with similar signature (ie with=
 a default_value).&nbsp; Maybe that's what it should be called?<br><br>
Tony<br><br></div></div><br></div></div>
</blockquote></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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_922_18446838.1390863256832--

.


Author: Matthew Woehlke <mw_triad@users.sourceforge.net>
Date: Mon, 27 Jan 2014 18:12:04 -0500
Raw View
On 2014-01-27 17:45, Billy O'Neal wrote:
> What do you want to happen when T is noncopyable?

Ideally there would exist some form of specialization such that the
method would not exist in that case.

> You can always write your own function that has the semantics you want;
> e.g. value_or_default(Container, Index).

I could write my own implementation of (almost?) anything in STL... that
doesn't mean STL shouldn't include things that are widely useful. IMHO
this qualifies; I've also wished for such a method.

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

.


Author: matveyakin@gmail.com
Date: Mon, 27 Jan 2014 15:18:25 -0800 (PST)
Raw View
------=_Part_962_31468999.1390864705213
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

That's exactly what I wanted to say.

=D0=B2=D1=82=D0=BE=D1=80=D0=BD=D0=B8=D0=BA, 28 =D1=8F=D0=BD=D0=B2=D0=B0=D1=
=80=D1=8F 2014 =D0=B3., 3:12:04 UTC+4 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=
=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C Matthew Woehlke=20
=D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
>
> On 2014-01-27 17:45, Billy O'Neal wrote:=20
> > What do you want to happen when T is noncopyable?=20
>
> Ideally there would exist some form of specialization such that the=20
> method would not exist in that case.=20
>

I don't see how this can be extended to noncopyable types either, because=
=20
=E2=80=9Cvalue=E2=80=9D (or =E2=80=9Cvalue_or=E2=80=9D) is supposed to retu=
rn a copy of T in case the=20
container has the requested key. So if T is noncopyable the program should=
=20
refuse to compile.
=20

>
> > You can always write your own function that has the semantics you want;=
=20
> > e.g. value_or_default(Container, Index).=20
>
> I could write my own implementation of (almost?) anything in STL... that=
=20
> doesn't mean STL shouldn't include things that are widely useful. IMHO=20
> this qualifies; I've also wished for such a method.=20
>

Exactly. In my view the code looks better when such basic functions are=20
implemented as class members. For comparison: was there any reason why the=
=20
=E2=80=9Cat=E2=80=9D function added in C++11 can not be implemented externa=
lly? I don't=20
think =E2=80=9Cat=E2=80=9D is really much more useful.
=20

>
> --=20
> Matthew=20
>
>

--=20

---=20
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 e=
mail 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-proposa=
ls/.

------=_Part_962_31468999.1390864705213
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">That's exactly what I wanted to say.<br><br>=D0=B2=D1=82=
=D0=BE=D1=80=D0=BD=D0=B8=D0=BA, 28 =D1=8F=D0=BD=D0=B2=D0=B0=D1=80=D1=8F 201=
4&nbsp;=D0=B3., 3:12:04 UTC+4 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=
=B0=D1=82=D0=B5=D0=BB=D1=8C Matthew Woehlke =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=
=D0=B0=D0=BB:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-le=
ft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 2014-01-27 17:=
45, Billy O'Neal wrote:
<br>&gt; What do you want to happen when T is noncopyable?
<br>
<br>Ideally there would exist some form of specialization such that the=20
<br>method would not exist in that case.
<br></blockquote><div><br>I don't see how this can be extended to noncopyab=
le types either, because =E2=80=9Cvalue=E2=80=9D (or =E2=80=9Cvalue_or=E2=
=80=9D) is supposed to return a copy of T in case the container has the req=
uested key. So if T is noncopyable the program should refuse to compile.<br=
>&nbsp;</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-le=
ft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
<br>&gt; You can always write your own function that has the semantics you =
want;
<br>&gt; e.g. value_or_default(Container, Index).
<br>
<br>I could write my own implementation of (almost?) anything in STL... tha=
t=20
<br>doesn't mean STL shouldn't include things that are widely useful. IMHO=
=20
<br>this qualifies; I've also wished for such a method.
<br></blockquote><div><br>Exactly. In my view the code looks better when su=
ch basic functions are implemented as class members. For comparison: was th=
ere any reason why the =E2=80=9Cat=E2=80=9D function added in C++11 can not=
 be implemented externally? I don't think =E2=80=9Cat=E2=80=9D is really mu=
ch more useful.<br>&nbsp;</div><blockquote class=3D"gmail_quote" style=3D"m=
argin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"=
>
<br>--=20
<br>Matthew
<br>
<br></blockquote></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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_962_31468999.1390864705213--

.


Author: Andrey Matveyakin <a.matveyakin@gmail.com>
Date: Mon, 27 Jan 2014 15:22:27 -0800 (PST)
Raw View
------=_Part_487_14348777.1390864947888
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Sorry, I didn't want to answer from 2 emails. That happened accidentally.

On Tuesday, January 28, 2014 3:18:25 AM UTC+4, matve...@gmail.com wrote:
>
> That's exactly what I wanted to say.
>
> =D0=B2=D1=82=D0=BE=D1=80=D0=BD=D0=B8=D0=BA, 28 =D1=8F=D0=BD=D0=B2=D0=B0=
=D1=80=D1=8F 2014 =D0=B3., 3:12:04 UTC+4 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=
=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C Matthew Woehlke=20
> =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
>>
>> On 2014-01-27 17:45, Billy O'Neal wrote:=20
>> > What do you want to happen when T is noncopyable?=20
>>
>> Ideally there would exist some form of specialization such that the=20
>> method would not exist in that case.=20
>>
>
> I don't see how this can be extended to noncopyable types either, because=
=20
> =E2=80=9Cvalue=E2=80=9D (or =E2=80=9Cvalue_or=E2=80=9D) is supposed to re=
turn a copy of T in case the=20
> container has the requested key. So if T is noncopyable the program shoul=
d=20
> refuse to compile.
> =20
>
>>
>> > You can always write your own function that has the semantics you want=
;=20
>> > e.g. value_or_default(Container, Index).=20
>>
>> I could write my own implementation of (almost?) anything in STL... that=
=20
>> doesn't mean STL shouldn't include things that are widely useful. IMHO=
=20
>> this qualifies; I've also wished for such a method.=20
>>
>
> Exactly. In my view the code looks better when such basic functions are=
=20
> implemented as class members. For comparison: was there any reason why th=
e=20
> =E2=80=9Cat=E2=80=9D function added in C++11 can not be implemented exter=
nally? I don't=20
> think =E2=80=9Cat=E2=80=9D is really much more useful.
> =20
>
>>
>> --=20
>> Matthew=20
>>
>>

--=20

---=20
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 e=
mail 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-proposa=
ls/.

------=_Part_487_14348777.1390864947888
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Sorry, I didn't want to answer from 2 emails. That happene=
d accidentally.<br><br>On Tuesday, January 28, 2014 3:18:25 AM UTC+4, matve=
....@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;ma=
rgin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr">That's exactly what I wanted to say.<br><br>=D0=B2=D1=82=D0=BE=D1=
=80=D0=BD=D0=B8=D0=BA, 28 =D1=8F=D0=BD=D0=B2=D0=B0=D1=80=D1=8F 2014&nbsp;=
=D0=B3., 3:12:04 UTC+4 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=
=82=D0=B5=D0=BB=D1=8C Matthew Woehlke =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=
=D0=BB:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8e=
x;border-left:1px #ccc solid;padding-left:1ex">On 2014-01-27 17:45, Billy O=
'Neal wrote:
<br>&gt; What do you want to happen when T is noncopyable?
<br>
<br>Ideally there would exist some form of specialization such that the=20
<br>method would not exist in that case.
<br></blockquote><div><br>I don't see how this can be extended to noncopyab=
le types either, because =E2=80=9Cvalue=E2=80=9D (or =E2=80=9Cvalue_or=E2=
=80=9D) is supposed to return a copy of T in case the container has the req=
uested key. So if T is noncopyable the program should refuse to compile.<br=
>&nbsp;</div><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-lef=
t:0.8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>&gt; You can always write your own function that has the semantics you =
want;
<br>&gt; e.g. value_or_default(Container, Index).
<br>
<br>I could write my own implementation of (almost?) anything in STL... tha=
t=20
<br>doesn't mean STL shouldn't include things that are widely useful. IMHO=
=20
<br>this qualifies; I've also wished for such a method.
<br></blockquote><div><br>Exactly. In my view the code looks better when su=
ch basic functions are implemented as class members. For comparison: was th=
ere any reason why the =E2=80=9Cat=E2=80=9D function added in C++11 can not=
 be implemented externally? I don't think =E2=80=9Cat=E2=80=9D is really mu=
ch more useful.<br>&nbsp;</div><blockquote class=3D"gmail_quote" style=3D"m=
argin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>--=20
<br>Matthew
<br>
<br></blockquote></div></blockquote></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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_487_14348777.1390864947888--

.


Author: Evgeny Panasyuk <evgeny.panasyuk@gmail.com>
Date: Tue, 28 Jan 2014 12:23:52 -0800 (PST)
Raw View
------=_Part_615_31267771.1390940632473
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

28 January 2014 =D0=B3., 3:18:25 UTC+4 matve...@gmail.com:
>
>
>> > You can always write your own function that has the semantics you want=
;=20
>> > e.g. value_or_default(Container, Index).=20
>>
>> I could write my own implementation of (almost?) anything in STL... that=
=20
>> doesn't mean STL shouldn't include things that are widely useful. IMHO=
=20
>> this qualifies; I've also wished for such a method.=20
>>
>
> Exactly. In my view the code looks better when such basic functions are=
=20
> implemented as class members. For comparison: was there any reason why th=
e=20
> =E2=80=9Cat=E2=80=9D function added in C++11 can not be implemented exter=
nally? I don't=20
> think =E2=80=9Cat=E2=80=9D is really much more useful.
>

Non-member functions are more preferable than methods when possible.
For example, Alexander Stepanov, author of STL, at his Notes on Programming=
=20
says ( http://www.stepanovpapers.com/notes.pdf ):
"While we could make a member function to return length, it is better to=20
make it a global friend function. If we do that, we will be able eventually=
=20
to define the same function to work on built-in arrays and achieve greater=
=20
uniformity of design. I made size into a member function in STL in an=20
attempt to please the standard committee. I knew that begin, end and size=
=20
should be global functions but was not willing to risk another fight with=
=20
the committee. In general, there were many compromises of which I am=20
ashamed. It would have been harder to succeed without making them, but I=20
still get a metallic taste in my mouth when I encounter all the things that=
=20
I did wrong while knowing full how to do them right. Success, after all, is=
=20
much overrated. I will be pointing to the incorrect designs in STL here and=
=20
there: some were done because of political considerations, but many were=20
mistakes caused by my inability to discern general principles.)"

Also refer SO:=20
http://stackoverflow.com/questions/1638394/when-should-functions-be-member-=
functions

--=20

---=20
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 e=
mail 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-proposa=
ls/.

------=_Part_615_31267771.1390940632473
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">28 January 2014&nbsp;=D0=B3., 3:18:25 UTC+4 matve...@gmail=
..com:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8e=
x;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><blockqu=
ote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1=
px #ccc solid;padding-left:1ex">
<br>&gt; You can always write your own function that has the semantics you =
want;
<br>&gt; e.g. value_or_default(Container, Index).
<br>
<br>I could write my own implementation of (almost?) anything in STL... tha=
t=20
<br>doesn't mean STL shouldn't include things that are widely useful. IMHO=
=20
<br>this qualifies; I've also wished for such a method.
<br></blockquote><div><br>Exactly. In my view the code looks better when su=
ch basic functions are implemented as class members. For comparison: was th=
ere any reason why the =E2=80=9Cat=E2=80=9D function added in C++11 can not=
 be implemented externally? I don't think =E2=80=9Cat=E2=80=9D is really mu=
ch more useful.</div></div></blockquote><div><br>Non-member functions are m=
ore preferable than methods when possible.<br>For example, Alexander Stepan=
ov, author of STL, at his Notes on Programming says  ( http://www.stepanovp=
apers.com/notes.pdf ):<br>"While we could make a member function to return =
length, it is better to make it a global friend function. If we do that, we=
 will be able eventually to define the same function to work on built-in ar=
rays and achieve greater uniformity of design. I made size into a member fu=
nction in STL in an attempt to please the standard committee. I knew that b=
egin, end and size should be global functions but was not willing to risk a=
nother fight with the committee. In general, there were many compromises of=
 which I am ashamed. It would have been harder to succeed without making th=
em, but I still get a metallic taste in my mouth when I encounter all the t=
hings that I did wrong while knowing full how to do them right. Success, af=
ter all, is much overrated. I will be pointing to the incorrect designs in =
STL here and there: some were done because of political considerations, but=
 many were mistakes caused by my inability to discern general principles.)"=
<br><br>Also refer SO: http://stackoverflow.com/questions/1638394/when-shou=
ld-functions-be-member-functions<br></div></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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_615_31267771.1390940632473--

.