This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: STL vector


On Monday 31 October 2005 12:49, John Love-Jensen wrote:
> 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
> 
> 
thanks for clarify.
i'll think i'll implement my own templates for the std::<classes> with extended safety.

regards
marcel


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]