why no sort(v) in C++?

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

    It's not the std::sort(v) -> std::sort(v.begin(), v.end()) expansion that would need concepts, but the alternate sort function taking an additional parameter for the comparison - std::sort(v.begin(), v.end(), compare).

    If you have a call std::sort(v, compare), the implementation would need concepts to distinguish it from std::sort(start, end) for a non-container.

    The header is full of templates with this kind of problem.

提交回复
热议问题