File: helper_algorithm.hpp

package info (click to toggle)
libpmemobj-cpp 1.12-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 8,388 kB
  • sloc: cpp: 136,076; sh: 1,022; perl: 381; ansic: 163; makefile: 13
file content (46 lines) | stat: -rw-r--r-- 959 bytes parent folder | download
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 */