why no sort(v) in C++?

前端 未结 6 1174
感动是毒
感动是毒 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:42

    From Learning Standard C++ as a New Language (PDF) Stroustrup, C/C++ Users Journal. pp 43-54. May 1999:

    Plain sort(v) would have been simpler in this case, but sometimes we want to sort part of a container so it’s more general to specify the beginning and end of what we want to sort.

    That makes sense to me. It's trivial to create a wrapper, as you've demonstrated, and it's not terribly cumbersome to use without a wrapper. Having a second sort() that took the Container just doesn't seem worth it.

提交回复
热议问题