This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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: Some new ideas for our STL too?


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.


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