Hacker News new | ask | show | jobs
by to3m 3843 days ago
std::sort requires random-access iterators, which std::list - being a list - can't supply.

std::list's iterator type: http://en.cppreference.com/w/cpp/container/list

std::sort's iterator requirements: http://en.cppreference.com/w/cpp/algorithm/sort

All the different types of iterator: http://en.cppreference.com/w/cpp/iterator

(This might seem like needless nitpicking to some; to me, it's more like knowing why you can't, say, seek on a socket.)

1 comments

Yeah, I know why. Problem is, it is a bad design. I don't work for the API, the API works for me. Conceptually sorting a list is the same as sorting a vector, so it should look the same in the code. The fact that it may require a different algorithm underneath is what the API is there to figure out for me. Other languages and APIs (including Qt) don't have problems like this, hence my complaint.