Re: STL vector

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

 



Hi marcel,

> can someone explain it to me?

The *STANDARD* says that pop_back on an empty std::vector has an undefined
effect.

The safer version you suggest complies with the standard -- but it's not
reliable behavior on all C++ compilers, and it has a performance penalty for
code that does not expect nor rely upon the safe behavior you've suggested.
Even though the performance penalty is slight, it is enough that certain
situations may opt not to use std::vector because of the performance
overhead.

You can get that same safe behavior by doing a if(v.size()) v.pop_back(); in
your code.  Or better yet, create a marcel::vector template class that adds
the additional safety feature you desire *AND* is cross-platform compatible.
That same guarantee cannot be made of the std:: namespace's implementation
of std::vector.

HTH,
--Eljay


[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