C++ standard sort documentation issue -
my copy of c++ standard document documents standard sort function.
25.4.1.1 sort
template<class randomaccessiterator> void sort(randomaccessiterator first, randomaccessiterator last); ... effects: sorts elements in range [first,last).
requires: randomaccessiterator shall satisfy requirements of valueswappable (17.6.3.2). type of *first shall satisfy requirements of moveconstructible (table 20) , of moveassignable
ok - shouldn't require elements referred comparable?
i expect "requires" clause include like:
"type results dereferencing randomaccessiterator
should satisfy requirements of lessthancomparable
."
or better yet
"iterator_traits<randomaccessiterator>::value_type
should satisfy requirements of lessthancomparable."
since 24.4.1 says in part "it required if iterator
type of iterator, types ... iterator_traits<iterator>::value_type
defined"
why isn't such language included. surely sort function can't sort elements can't compared.
- ok - shouldn't require elements referred comparable?
if scrolled above in standard have found these requirements (under § 25.4) sorting algorithms:
all operations in 25.4 have 2 versions: 1 takes function object of type compare , 1 uses operator<.
which means it's enforced in standard types required use operator<
or custom comparator.
the custom comparator has following requirements:
compare
function object type (20.8). return value of function call operation applied object of typecompare
, when contextually convertedbool
(4), yields true if first argument of call less second, , false otherwise.compare
comp used throughout algorithms assuming ordering relation. assumed comp not apply non-constant function through dereferenced iterator.
Comments
Post a Comment