This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Some new ideas for our STL too?
- From: Joe Buck <jbuck at synopsys dot com>
- To: Paolo Carlini <pcarlini at unitus dot it>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Thu, 19 Jun 2003 15:37:50 -0700
- Subject: Re: Some new ideas for our STL too?
- References: <3EF18C46.9040707@unitus.it>
On Thu, Jun 19, 2003 at 12:11:18PM +0200, Paolo Carlini wrote:
> there is this message on the STLPort forum which I'm finding interesting
> (the references therein too):
>
> http://www.stlport.com/dcforum/DCForumID5/682.html
Some of the proposed optimizations in that article will break valid
programs.
Consider this rather inefficient size function.
unsigned joe_size(const std::vector<int>& v)
{
if (v.empty())
return 0;
else {
const int* last_element = *v.back();
const int* first_element = &*v.begin();
return last_element - first_element + 1;
}
}
This is legal and useful, and must return the length, but the
"performance patch" changes v.back, for const vectors, to just
return the last element's value, rather than a reference to it,
so the program breaks.