Should std::list::size have constant complexity in C++11?
问题 I am using gcc 4.8.1 and after hours of debugging a horrible mysterious performance issue I found out that the std::list::size is actually implemented as a call to std::distance . /** Returns the number of elements in the %list. */ size_type size() const _GLIBCXX_NOEXCEPT { return std::distance(begin(), end()); } This surprised me, since the reference says that the complexity of std::list::size should be constant and the complexity of std::distance is linear for std::list::iterator . I am