partial_sort 的中间迭代器可以等于结束迭代器吗?

Can partial_sort's middle iterator equal the end iterator?

根据 http://www.cplusplus.com/reference/algorithm/partial_sort/middle 参数是:

Random-access iterator pointing to the element within the range [first,last) that is used as the upper boundary of the elements that are fully sorted.

具体来说,middle 不允许等于 last。然而,https://en.cppreference.com/w/cpp/algorithm/partial_sort 似乎有完全不同的文档并且没有提到任何范围限制(但显然 middle 不应该在 [first, last] 之外)。

是否在 middle == last 时定义了行为?

Can partial_sort's middle iterator equal the end iterator?

是的,可以。在这种情况下,效果与使用 std::sort.

相同

标准规定了这样的先决条件:

Preconditions: [first, middle) and [middle, last) are valid ranges.

标准(N4659,28.7.1.3/2)中std::partial_sort的描述为

  1. Effects: Places the first middle - first sorted elements from the range [first, last) into the range [first, middle). The rest of the elements in the range [middle, last) are placed in an unspecified order.

我在这里看不到任何东西会禁止 middle 等于 last