forked from boostorg/algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreasing.hpp
More file actions
94 lines (77 loc) · 2.72 KB
/
creasing.hpp
File metadata and controls
94 lines (77 loc) · 2.72 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Boost creasing.hpp header file -----------------------------------------//
// Copyright (c) 2010 Nuovation System Designs, LLC
// Grant Erickson <gerickson@nuovations.com>
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/ for latest version.
//
// Description:
// A set of four algorithms for inquiring about the properties of
// sequences, including:
//
// - Increasing
// - Decreasing
// - Strictly Increasing
// - Strictly Decreasing
#ifndef BOOST_ALGORITHM_CREASING_HPP
#define BOOST_ALGORITHM_CREASING_HPP
#include <algorithm>
#include <functional>
#include <iterator>
namespace boost {
namespace detail {
template <typename ForwardIterator, typename BinaryPredicate>
bool
is_creasing(ForwardIterator first, ForwardIterator last,
BinaryPredicate binary_pred)
{
return std::adjacent_find(first,
last,
std::not2(binary_pred)) == last;
}
} // namespace detail
template <typename ForwardIterator>
bool
is_increasing(ForwardIterator first, ForwardIterator last)
{
typedef typename std::iterator_traits<ForwardIterator>::value_type
value_type;
return detail::is_creasing(first,
last,
std::less_equal<value_type>());
}
template <typename ForwardIterator>
bool
is_decreasing(ForwardIterator first, ForwardIterator last)
{
typedef typename std::iterator_traits<ForwardIterator>::value_type
value_type;
return detail::is_creasing(first,
last,
std::greater_equal<value_type>());
}
template <typename ForwardIterator>
bool
is_strictly_increasing(ForwardIterator first, ForwardIterator last)
{
typedef typename std::iterator_traits<ForwardIterator>::value_type
value_type;
return detail::is_creasing(first,
last,
std::less<value_type>());
}
template <typename ForwardIterator>
bool
is_strictly_decreasing(ForwardIterator first, ForwardIterator last)
{
typedef typename std::iterator_traits<ForwardIterator>::value_type
value_type;
return detail::is_creasing(first,
last,
std::greater<value_type>());
}
} // namespace boost
#endif // BOOST_ALGORITHM_CREASING_HPP