one line assert to test if STL container is sorted

后端 未结 3 1570
自闭症患者
自闭症患者 2021-02-05 16:22

Is there a way to write a one line condition that would return true if STL container is sorted? The container in question is std::vector

I intend to use it in an assert<

3条回答
  •  猫巷女王i
    2021-02-05 17:05

    You can use std::is_sorted(vec.begin(),vec.end()) to test if it is sorted. Note, though, that this is O(n).

提交回复
热议问题