c++ - What the effect of std::nth_element(a.begin(), a.end(), a.end())? -
i read description of std::nth_element @ http://www.sgi.com/tech/stl/nth_element.html
template <class randomaccessiterator> void nth_element(randomaccessiterator first, randomaccessiterator nth, randomaccessiterator last); note preconditions are
- [first, nth) valid range.
- [nth, last) valid range.
my question is:
is valid call std::nth_element(a.begin(), a.end(), a.end())? if so, what's effect? doesn't violate preconditions above, anyway. anywhere in language standard (or other documents) stated nth must pointing element in a?
it's valid , probably, not guaranteed standard, null operation. given data, 2 preconditions become:
[a.begin(), a.end()) valid range. [a.end(), a.end()) valid range. which both true, second interval empty though. standard 25.3.2/1:
after nth_element element in position pointed nth element in position if whole range sorted. iterator in range [first, nth) , iterator j in range [nth, last) holds that: !(*i > *j) or comp(*j, *i) == false.
if whole range sorted original a.end() @ a.end() , second part range [nth, last) empty there no elements evaluate !(*i > *j) , comp(*j, *i) == false conditions.
Comments
Post a Comment