This is the mail archive of the gcc-bugs@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]

Bug in STL list<> template?


G'day.

I'm not sure who to send this to as it appears to be a problem with the SGI 
STL code as shipped with egcs 1.1b & earlier.

According to my reading of the C++ spec (CD2 section 23.1
[lib.container.requirements], table 3) we see the following requirements for
the size() routine of any container a:

  |a.size()     size_type           a.end()-a.begin()               (Note A)   |

where the notes say
	Those entries marked ``(Note  A)'' should have constant complexity.

In the SGI list<> template, the size() member does
 size_type size() const {
    size_type result = 0;
    distance(begin(), end(), result);
    return result;
  }
which is clearly linear complexity.

I discovered this when trying to speed up some code using the STL list<> and
this turned one of my algorithms from linear to quadratic time!

Greg.




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