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: [C++] Should the complexity of std::list::size() be O(n) or O(1)?


Howard Hinnant wrote:
On Nov 25, 2005, at 9:06 PM, Gabriel Dos Reis wrote:

An error was made in putting it there in the first place.  I rather
sequester that error instead of spreading through over the rest of
the interface.

I'll grant you that putting list::size in may have been an error.

size() is part of Table 65. Is this an error?


template<class C> void f( C & c )
{
   c.size(); // error?
   std::distance( c.begin(), c.end() ); // "proper"?
}

Note how this penalizes _all_ containers that have O(1) size() and non-random access iterators.


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