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:53:25 +0100
- Subject: Re: STL vector
- References: <BF8B6EE9.3FAF%eljay@adobe.com>
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