why no sort(v) in C++?

前端 未结 6 1118
感动是毒
感动是毒 2021-01-17 15:15

I always wondered why there is no

sort(v);// same as std::sort(v.begin(),v.end())

If I recall correctly long time ago I saw a boostcon cli

6条回答
  •  醉话见心
    2021-01-17 15:45

    functions don't work on container directly. They only interacts with iterators, without any context knowledge of the container. I see no harm if you use a short full range sort notation for you own purpose, but you have to assume the object have begin / end interface, which also happen to be bidirectional iterators.

提交回复
热议问题