Some new ideas for our STL too?

Joe Buck jbuck@synopsys.com
Thu Jun 19 22:51:00 GMT 2003


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.



More information about the Libstdc++ mailing list