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>&nbsp;&nbsp;&n=
bsp; template&lt;typename T&gt;<br>&nbsp;&nbsp;&nbsp; auto pop(const T&amp;=
 default_val)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt; T<br>&nbs=
p;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (empty())=
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return default_val;<br>&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp; T ret =3D top();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pop(=
);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ret;<br>&nbsp;&nbsp=
;&nbsp; }<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 />
&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 />
&nbsp;<br />
&nbsp;<br />

------=_Part_47_23021301.1371718351847--

.