Topic: Proposal : Add front() and back() to std::(multi)map


Author: Olivier Sohn <olivier.sohn@gmail.com>
Date: Wed, 18 Jul 2018 05:10:21 -0700 (PDT)
Raw View
------=_Part_175725_2056188286.1531915821758
Content-Type: multipart/alternative;
 boundary="----=_Part_175726_738223106.1531915821758"

------=_Part_175726_738223106.1531915821758
Content-Type: text/plain; charset="UTF-8"

Hello,

I recently encountered an algorithm where I needed to access the map's last
element, knowing the map was non-empty. But I found that there is no
straightforward way to access the last (or first) element of a map.

So as suggested by this process : https://isocpp.org/std/submit-a-proposal
I'd like to propose the following: add the front() and back() methods, with
const and non const versions, to std::(multi)map and std::(multi)set, to
return a (const-) reference to the last / first element(s).

Like with other containers implementing these methods, no guaranty would be
given when the container is empty.

What do you think?

Cheers,
Olivier

--
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/e6d18f4e-6337-45df-9536-e0bfab52962b%40isocpp.org.

------=_Part_175726_738223106.1531915821758
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hello,<div><br></div><div>I recently encountered an algori=
thm where I needed to access the map&#39;s last element, knowing the map wa=
s non-empty. But I found that there is no straightforward way to access the=
 last (or first) element of a map.</div><div><br></div><div>So as suggested=
 by this process :=C2=A0https://isocpp.org/std/submit-a-proposal I&#39;d li=
ke to propose the following: add the front() and back() methods, with const=
 and non const versions, to std::(multi)map and std::(multi)set, to return =
a (const-) reference to the last / first element(s).</div><div><br></div><d=
iv>Like with other containers implementing these methods, no guaranty would=
 be given when the container is empty.</div><div><br></div><div>What do you=
 think?</div><div><br></div><div>Cheers,</div><div>Olivier</div><div><br></=
div></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/e6d18f4e-6337-45df-9536-e0bfab52962b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/e6d18f4e-6337-45df-9536-e0bfab52962b=
%40isocpp.org</a>.<br />

------=_Part_175726_738223106.1531915821758--

------=_Part_175725_2056188286.1531915821758--

.


Author: Vishal Oza <vickoza@gmail.com>
Date: Thu, 19 Jul 2018 05:45:04 -0700 (PDT)
Raw View
------=_Part_3400_569208855.1532004304980
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

I would think first try benchmarking map and set using begin() and rbegin()=
 for having to access the first and last elements vs similar access with fr=
ont and back on vector as well as begin() and rbegin(). I think some implem=
entation of begin() and rbegin() are slower than front() and back(). I thin=
k that front() and back() can make more sense in map and set then in vector=
 because they would represent min and max key values.

--=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/78ed8565-b36c-475e-83a8-c542ab14341b%40isocpp.or=
g.

------=_Part_3400_569208855.1532004304980--

.