C++ standard sort documentation issue
My copy of the C++ standard document documents the standard sort function.
25.4.1.1 sort
template<class RandomAccessIterator>
void sort(RandomAccessIterator first, RandomAccessIterator last);
...
Effects: Sorts the elements in the range [first,last).
Requires: RandomAccessIterator shall satisfy the requirements of
ValueSwappable (17.6.3.2). The type of *first shall satisfy the
requirements of MoveConstructible (Table 20) and of MoveAssignable
OK - but shouldn't it also require that the elements referred to also be
comparable?
I would expect the "Requires" clause to include something like:
"type which results from dereferencing the RandomAccessIterator should
satisfy the requirements of LessThanComparable."
Or better yet
"iterator_traits<RandomAccessIterator>::value_type should satisfy the
requirements of LessThanComparable."
since 24.4.1 says in part "it is required that if Iterator is the type of
an iterator, the types ... iterator_traits<Iterator>::value_type be
defined"
Why isn't such language included. Surely the sort function can't sort
elements which can't be compared.
No comments:
Post a Comment