Topic: Extended pop methods
Author: morwenn29@gmail.com
Date: Thu, 20 Jun 2013 01:52:31 -0700 (PDT)
Raw View
------=_Part_47_23021301.1371718351847
Content-Type: text/plain; charset=ISO-8859-1
I think this issue may have been discussed at least once - I would be
surprised if this wasn't the case -, but I
would like t propose some overloads to the containers pop, pop_front and
pop_back methods, whose behaviour
would look like this (for a std::stack for example):
template<typename T>
auto pop(const T& default_val)
-> T
{
if (empty())
{
return default_val;
}
T ret = top();
pop();
return ret;
}
Pop and return the poped value if it exists, otherwise, return the default
value passed to the function. It is easy
to extend this behaviour to pop_front and pop_back.
I suppose there are some good arguments against, otherwise, there would
probably be some equivalent in the standard.
--
---
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_47_23021301.1371718351847
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
I think this issue may have been discussed at least once - I would be surpr=
ised if this wasn't the case -, but I<br>would like t propose some overload=
s to the containers pop, pop_front and pop_back methods, whose behaviour<br=
>would look like this (for a std::stack for example):<br><br> &n=
bsp; template<typename T><br> auto pop(const T&=
default_val)<br> -> T<br>&nbs=
p; {<br> if (empty())=
<br> {<br>  =
; return default_val;<br> &n=
bsp; }<br>  =
; T ret =3D top();<br> pop(=
);<br> return ret;<br>  =
; }<br><br>Pop and return the poped value if it exists, otherwise, re=
turn the default value passed to the function. It is easy<br>to extend this=
behaviour to pop_front and pop_back.<br><br>I suppose there are some good =
arguments against, otherwise, there would probably be some equivalent in th=
e standard.<br>
<p></p>
-- <br />
<br />
--- <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 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 />
<br />
<br />
------=_Part_47_23021301.1371718351847--
.