[C++] Should the complexity of std::list::size() be O(n) or O(1)?

Paolo Carlini pcarlini@suse.de
Thu Nov 24 18:33:00 GMT 2005


Howard Hinnant wrote:

[snip the real beef, will return to it later, thanks!!!]

> It is somewhat analogous to:
>
> basic_string(const charT* s);
> basic_string(const charT* s, size_type n);
>
> Now certainly you might want to pass a non-null-terminated char* to a 
> string, and the second ctor is handy for that.  But you also might 
> already know the length of a null-terminated char* from previous 
> computations, and use the second ctor for that case too.  Why have 
> basic_string do an O(n) computation that you've already gone to the 
> trouble to compute?

Exactly! Earlier today I came to the *very same* conclusion, it's the
closer analogous!

Paolo.



More information about the Libstdc++ mailing list