1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2020, Intel Corporation */
/*
* Helper algorithms to test C++ containers
*/
#ifndef HELPER_ALGORITHM_HPP
#define HELPER_ALGORITHM_HPP
#include <functional>
/**
* Checks if the elements in range [first, last) are sorted in a strictly
* ascending order.
*/
template <class ForwardIt, class Compare>
bool
is_strictly_increased(ForwardIt first, ForwardIt last, Compare comp)
{
if (first != last) {
ForwardIt next = first;
while (++next != last) {
if (!comp(*first, *next))
return false;
first = next;
}
}
return true;
}
/**
* Checks if the elements in range [first, last) are sorted in a strictly
* ascending order.
*/
template <class ForwardIt>
bool
is_strictly_increased(ForwardIt first, ForwardIt last)
{
return is_strictly_increased(first, last,
std::less<typename std::iterator_traits<
ForwardIt>::value_type>());
}
#endif /* HELPER_ALGORITHM_HPP */
|