std::is_sorted and strictly less comparison?

前端 未结 3 2075
旧时难觅i
旧时难觅i 2021-02-20 09:51

I do not understand well the std::is_sorted algorithm and its default behaviour. If we look to cppreference, it says that by default std::is_sorted use

3条回答
  •  清歌不尽
    2021-02-20 10:51

    Per 25.4/5:

    A sequence is sorted with respect to a comparator comp if for any iterator i pointing to the sequence and any non-negative integer n such that i + n is a valid iterator pointing to an element of the sequence, comp(*(i + n), *i) == false.

    So, for

    1 2 3 3 4 5
    

    std::less()(*(i + n), *i) will return false for all n, while std::less_equal will return true for case 3 3.

提交回复
热议问题