File indexing completed on 2024-04-06 12:19:21
0001 #ifndef NPSTAT_ISMONOTONOUS_HH_
0002 #define NPSTAT_ISMONOTONOUS_HH_
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 namespace npstat {
0016
0017 template <class Iter>
0018 inline bool isStrictlyIncreasing(Iter begin, Iter const end) {
0019 if (begin == end)
0020 return false;
0021 Iter first(begin);
0022 bool status = ++begin != end;
0023 for (; begin != end && status; ++begin, ++first)
0024 if (!(*first < *begin))
0025 status = false;
0026 return status;
0027 }
0028
0029
0030 template <class Iter>
0031 inline bool isStrictlyDecreasing(Iter begin, Iter const end) {
0032 if (begin == end)
0033 return false;
0034 Iter first(begin);
0035 bool status = ++begin != end;
0036 for (; begin != end && status; ++begin, ++first)
0037 if (!(*begin < *first))
0038 status = false;
0039 return status;
0040 }
0041
0042
0043 template <class Iter>
0044 inline bool isStrictlyMonotonous(Iter const begin, Iter const end) {
0045 return isStrictlyIncreasing(begin, end) || isStrictlyDecreasing(begin, end);
0046 }
0047
0048
0049 template <class Iter>
0050 inline bool isNonDecreasing(Iter begin, Iter const end) {
0051 if (begin == end)
0052 return false;
0053 Iter first(begin);
0054 bool status = ++begin != end;
0055 for (; begin != end && status; ++begin, ++first)
0056 if (*begin < *first)
0057 status = false;
0058 return status;
0059 }
0060
0061
0062 template <class Iter>
0063 inline bool isNonIncreasing(Iter begin, Iter const end) {
0064 if (begin == end)
0065 return false;
0066 Iter first(begin);
0067 bool status = ++begin != end;
0068 for (; begin != end && status; ++begin, ++first)
0069 if (*begin > *first)
0070 status = false;
0071 return status;
0072 }
0073
0074
0075
0076
0077
0078 template <class Iter>
0079 inline bool isMonotonous(Iter const begin, Iter const end) {
0080 return isNonDecreasing(begin, end) || isNonIncreasing(begin, end);
0081 }
0082 }
0083
0084 #endif