This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: STL vector
- From: Mws <mws at twisted-brains dot org>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 31 Oct 2005 13:32:56 +0100
- Subject: Re: STL vector
- References: <BF8B675D.3FA9%eljay@adobe.com>
On Monday 31 October 2005 12:17, John Love-Jensen wrote:
> Hi marcel,
>
> Doing a pop_back on an empty std::vector has undefined effect.
>
> Probably a safe bet that whatever the undefined effect, it isn't a desirable
> effect.
>
> The size method can be called before the pop_back, to assure that there is
> something to pop.
>
> HTH,
> --Eljay
>
>
it's implemented like
void
pop_back()
{
--this->_M_impl._M_finish;
std::_Destroy(this->_M_impl._M_finish);
}
but, imho a
void
pop_back()
{
if ( this->_M_impl._M_finish != this->_M_impl._M_start)
{
--this->_M_impl._M_finish;
std::_Destroy(this->_M_impl._M_finish);
}
}
would be save and shouldn't be that performance specific. also the programmer can save his ( if (!foo.empty()) ... things for all occurences of pop_back();
i do not really know, why the stl implementation's - in my point of view - regression is applicalable.
can someone explain it to me?
regards
marcel