Adobe Source Libraries 1.49.0
A collection of C++ libraries.
Loading...
Searching...
No Matches
sorted.hpp
Go to the documentation of this file.
1/*
2 Copyright 2013 Adobe
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5*/
6/**************************************************************************************************/
7
8#ifndef ADOBE_ALGORITHM_SORTED_HPP
9#define ADOBE_ALGORITHM_SORTED_HPP
10
11#include <algorithm>
12#include <functional>
13#include <iterator>
14
15#include <boost/range/begin.hpp>
16#include <boost/range/end.hpp>
17
19
20/**************************************************************************************************/
21
22namespace adobe {
23
24/**************************************************************************************************/
29
33template <typename I, // I models InputIterator
34 typename O>
35// O models StrictWeakOrdering on value_type(I)
36I sorted(I f, I l, O o) {
37
38 f = std::adjacent_find(f, l,
39 std::bind(std::logical_not<bool>(),
40 std::bind(o, std::placeholders::_1, std::placeholders::_2)));
41 if (f != l)
42 ++f;
43 return f;
44}
45
46/**************************************************************************************************/
47
51template <typename I> // I models InputIterator, value_type(I) models LessThanComparable
52I sorted(I f, I l) {
53 return sorted(f, l, less());
54}
55
56/**************************************************************************************************/
57
61template <typename I, // I models InputIterator
62 typename O>
63// O models StrictWeakOrdering on value_type(I)
64inline bool is_sorted(I f, I l, O o) {
65 return std::adjacent_find(
66 f, l,
67 std::bind(std::logical_not<bool>(),
68 std::bind(o, std::placeholders::_1, std::placeholders::_2))) == l;
69}
70
71/**************************************************************************************************/
72
76template <typename I> // I models InputIterator, value_type(I) models LessThanComparable
77inline bool is_sorted(I f, I l) {
78 return is_sorted(f, l, less());
79}
80
81/**************************************************************************************************/
82
86template <typename I, // I models ForwardIterator
87 typename C, // C models StrictWeakOrdering(T, T)
88 typename P>
89// P models UnaryFunction(value_type(I)) -> T
90inline bool is_sorted(I f, I l, C c, P p) {
91 return std::adjacent_find(f, l,
92 std::bind(std::logical_not<bool>(),
93 std::bind(c, std::bind(p, std::placeholders::_1),
94 std::bind(p, std::placeholders::_2)))) == l;
95}
96
97/**************************************************************************************************/
98
102template <typename I, // I models ForwardRange
103 typename C, // C models StrictWeakOrdering(T, T)
104 typename P>
105// P models UnaryFunction(value_type(I)) -> T
106inline bool is_sorted(const I& r, C c, P p) {
107 return is_sorted(boost::begin(r), boost::end(r), c, p);
108}
109
110/**************************************************************************************************/
111
115template <typename I, // I models ForwardRange
116 typename C>
117// C models StrictWeakOrdering(T, T)
118inline bool is_sorted(const I& r, C c) {
119 return is_sorted(boost::begin(r), boost::end(r), c,
120 identity<typename std::iterator_traits<I>::value_type>());
121}
122
123/**************************************************************************************************/
124
128template <typename I> // I models ForwardRange
129inline bool is_sorted(const I& r) {
130 return std::is_sorted(boost::begin(r), boost::end(r), less());
131}
132
133/**************************************************************************************************/
134
135} // namespace adobe
136
137/**************************************************************************************************/
138
139#endif
140
141/**************************************************************************************************/
bool is_sorted(I f, I l, O o)
Definition sorted.hpp:64
I sorted(I f, I l, O o)
Definition sorted.hpp:36