Topic: std::contains algorithm
Author: kerndog73@gmail.com
Date: Sun, 4 Nov 2018 14:38:47 -0800 (PST)
Raw View
------=_Part_1355_88996584.1541371127050
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
std::set has a find member function. This member function uses the nature o=
f a set to achieve O(log n) complexity. There exists a std::find algorithm =
that can be used with any container and has a complexity of O(n).
C++20 added a contains member function to some containers. Once again, the =
contains member function of std::set uses the nature of a set to achieve O(=
log n) complexity. However, there isn't (to my knowledge) a generic std::co=
ntains algorithm for containers that don't have a contains member function.
Personally, the absence of std::contains seems like an oversight. Is it?
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/689fd0dc-0ddf-464f-b041-f5c071d643df%40isocpp.or=
g.
------=_Part_1355_88996584.1541371127050--
.
Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Mon, 5 Nov 2018 18:21:58 -0800 (PST)
Raw View
------=_Part_2308_1955111174.1541470918310
Content-Type: multipart/alternative;
boundary="----=_Part_2309_1132038042.1541470918310"
------=_Part_2309_1132038042.1541470918310
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Sunday, November 4, 2018 at 5:38:47 PM UTC-5, kern...@gmail.com wrote:
>
> std::set has a find member function. This member function uses the nature=
=20
> of a set to achieve O(log n) complexity. There exists a std::find algorit=
hm=20
> that can be used with any container and has a complexity of O(n).
>
> C++20 added a contains member function to some containers. Once again, th=
e=20
> contains member function of std::set uses the nature of a set to achieve=
=20
> O(log n) complexity. However, there isn't (to my knowledge) a generic=20
> std::contains algorithm for containers that don't have a contains member=
=20
> function.
>
> Personally, the absence of std::contains seems like an oversight. Is it?
>
The point of .contains(), I think, is to be able to write
if (myset.contains("foo")) { do a thing; }
if (mymap.contains("foo")) { do a thing; }
if (myvector.contains("foo")) { do a thing; } // whoops, this doesn't=
=20
exist in C++2a yet!
I wouldn't want to write
if (std::contains(myvector.begin(), myvector.end(), "foo")) { do a=20
thing; }
using a generic algorithm like that. That's just super verbose. I'd rather=
=20
write a helper function
if (my::contains(myvector, "foo")) { do a thing; }
in which case the existence of a generic range-based algorithm in std::=20
wouldn't help me at all, because I could just as easily implement=20
`my::contains` in terms of the already-existing std::find as in terms of=20
the hypothetical std::contains.
my $.02,
=E2=80=93Arthur
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/75210e6c-0ed6-4743-bd17-878d0cf128a3%40isocpp.or=
g.
------=_Part_2309_1132038042.1541470918310
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Sunday, November 4, 2018 at 5:38:47 PM UTC-5, kern...@g=
mail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-=
left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">std::set has a =
find member function. This member function uses the nature of a set to achi=
eve O(log n) complexity. There exists a std::find algorithm that can be use=
d with any container and has a complexity of O(n).<p>C++20 added a contains=
member function to some containers. Once again, the contains member functi=
on of std::set uses the nature of a set to achieve O(log n) complexity. How=
ever, there isn't (to my knowledge) a generic std::contains algorithm f=
or containers that don't have a contains member function.</p><p>Persona=
lly, the absence of std::contains seems like an oversight. Is it?</p></bloc=
kquote><div><br></div><div>The point of .contains(), I think, is to be able=
to write</div><div><br></div><div>=C2=A0 =C2=A0 if (myset.contains("f=
oo")) { do a thing; }</div><div>=C2=A0 =C2=A0 if (mymap.contains("=
;foo")) { do a thing; }</div><div>=C2=A0 =C2=A0 if (myvector.contains(=
"foo")) { do a thing; } =C2=A0// whoops, this doesn't exist i=
n C++2a yet!<br></div><div><br></div><div>I wouldn't want to write</div=
><div><br></div><div>=C2=A0 =C2=A0 if (std::contains(myvector.begin(), myve=
ctor.end(), "foo")) { do a thing; }</div><div><br></div><div>usin=
g a generic algorithm like that. That's just super verbose. I'd rat=
her write a helper function</div><div><br></div><div>=C2=A0 =C2=A0 if (my::=
contains(myvector, "foo")) { do a thing; }</div><div><br></div><d=
iv>in which case the existence of a generic range-based algorithm in std:: =
wouldn't help me at all, because I could just as easily implement `my::=
contains` in terms of the already-existing std::find as in terms of the hyp=
othetical std::contains.</div><div><br></div><div>my $.02,</div><div>=E2=80=
=93Arthur</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/75210e6c-0ed6-4743-bd17-878d0cf128a3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/75210e6c-0ed6-4743-bd17-878d0cf128a3=
%40isocpp.org</a>.<br />
------=_Part_2309_1132038042.1541470918310--
------=_Part_2308_1955111174.1541470918310--
.
Author: kerndog73@gmail.com
Date: Mon, 5 Nov 2018 19:09:01 -0800 (PST)
Raw View
------=_Part_2150_977411790.1541473741544
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
I agree. Writing my::contains is trivial. However, you raised one of my cri=
ticisms of the standard algorithms. The verbosity. Every time I use a stand=
ard algorithm, I have to wrap the call into multiple lines (I don't like to=
go over 80 characters). Its ugly!
The only way to clean up the call site is to create helper functions like y=
ou suggested.
I used to think the Ranges TS will let me do this:
std::find(myvec.range(), "foo")
but then I actually read about Ranges and I was kind of disappointed.
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/c424b255-437d-40b6-a9e9-652dc4b1c8f9%40isocpp.or=
g.
------=_Part_2150_977411790.1541473741544--
.
Author: peterdenbra@gmail.com
Date: Wed, 7 Nov 2018 01:22:23 -0800 (PST)
Raw View
------=_Part_2906_253196883.1541582543336
Content-Type: multipart/alternative;
boundary="----=_Part_2907_2118724280.1541582543337"
------=_Part_2907_2118724280.1541582543337
Content-Type: text/plain; charset="UTF-8"
Den tisdag 6 november 2018 kl. 03:09:01 UTC skrev kern...@gmail.com:
>
> I agree. Writing my::contains is trivial. However, you raised one of my
> criticisms of the standard algorithms. The verbosity. Every time I use a
> standard algorithm, I have to wrap the call into multiple lines (I don't
> like to go over 80 characters). Its ugly!
>
> The only way to clean up the call site is to create helper functions like
> you suggested.
>
> I used to think the Ranges TS will let me do this:
> std::find(myvec.range(), "foo")
> but then I actually read about Ranges and I was kind of disappointed.
>
In Ranges TS you can do
std::find(myvec, "foo")
which is even less verbose than what you hoped for.
--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/11bbf69f-81ac-4783-953a-e47da3c1eee0%40isocpp.org.
------=_Part_2907_2118724280.1541582543337
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br>Den tisdag 6 november 2018 kl. 03:09:01 UTC skrev kern=
....@gmail.com:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">I agree. Writing=
my::contains is trivial. However, you raised one of my criticisms of the s=
tandard algorithms. The verbosity. Every time I use a standard algorithm, I=
have to wrap the call into multiple lines (I don't like to go over 80 =
characters). Its ugly!<p>The only way to clean up the call site is to creat=
e helper functions like you suggested.</p><p>I used to think the Ranges TS =
will let me do this:<br>std::find(myvec.range(), "foo")<br>but th=
en I actually read about Ranges and I was kind of disappointed.</p></blockq=
uote><div>=C2=A0</div><div>In Ranges TS you can do<br>=C2=A0 =C2=A0 std::fi=
nd(myvec, "foo")<br>which is even less verbose than what you hope=
d for.<br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/11bbf69f-81ac-4783-953a-e47da3c1eee0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/11bbf69f-81ac-4783-953a-e47da3c1eee0=
%40isocpp.org</a>.<br />
------=_Part_2907_2118724280.1541582543337--
------=_Part_2906_253196883.1541582543336--
.
Author: kerndog73@gmail.com
Date: Wed, 7 Nov 2018 03:40:04 -0800 (PST)
Raw View
------=_Part_3095_1783891858.1541590804277
Content-Type: multipart/alternative;
boundary="----=_Part_3096_1826741821.1541590804277"
------=_Part_3096_1826741821.1541590804277
Content-Type: text/plain; charset="UTF-8"
It looks like I misread something. Yep, you're right. Ranges are gonna be
great! std::contains makes much more sense with Ranges. Maybe it makes
sense to add std::contains after all.
On Wednesday, 7 November 2018 19:52:23 UTC+10:30, peter...@gmail.com wrote:
>
>
> Den tisdag 6 november 2018 kl. 03:09:01 UTC skrev kern...@gmail.com:
>>
>> I agree. Writing my::contains is trivial. However, you raised one of my
>> criticisms of the standard algorithms. The verbosity. Every time I use a
>> standard algorithm, I have to wrap the call into multiple lines (I don't
>> like to go over 80 characters). Its ugly!
>>
>> The only way to clean up the call site is to create helper functions like
>> you suggested.
>>
>> I used to think the Ranges TS will let me do this:
>> std::find(myvec.range(), "foo")
>> but then I actually read about Ranges and I was kind of disappointed.
>>
>
> In Ranges TS you can do
> std::find(myvec, "foo")
> which is even less verbose than what you hoped for.
>
--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/37a59148-47ad-4973-8788-b6dffb5ca0b5%40isocpp.org.
------=_Part_3096_1826741821.1541590804277
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">It looks like I misread something. Yep, you're right. =
Ranges are gonna be great! std::contains makes much more sense with Ranges.=
Maybe it makes sense to add std::contains after all.<br><br>On Wednesday, =
7 November 2018 19:52:23 UTC+10:30, peter...@gmail.com wrote:<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"><br>Den tisdag 6 november 2=
018 kl. 03:09:01 UTC skrev <a>kern...@gmail.com</a>:<blockquote class=3D"gm=
ail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;p=
adding-left:1ex">I agree. Writing my::contains is trivial. However, you rai=
sed one of my criticisms of the standard algorithms. The verbosity. Every t=
ime I use a standard algorithm, I have to wrap the call into multiple lines=
(I don't like to go over 80 characters). Its ugly!<p>The only way to c=
lean up the call site is to create helper functions like you suggested.</p>=
<p>I used to think the Ranges TS will let me do this:<br>std::find(myvec.ra=
nge(), "foo")<br>but then I actually read about Ranges and I was =
kind of disappointed.</p></blockquote><div>=C2=A0</div><div>In Ranges TS yo=
u can do<br>=C2=A0 =C2=A0 std::find(myvec, "foo")<br>which is eve=
n less verbose than what you hoped for.<br></div></div></blockquote></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/37a59148-47ad-4973-8788-b6dffb5ca0b5%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/37a59148-47ad-4973-8788-b6dffb5ca0b5=
%40isocpp.org</a>.<br />
------=_Part_3096_1826741821.1541590804277--
------=_Part_3095_1783891858.1541590804277--
.