Re: STL vector

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux