stlab.adobe.com Adobe Systems Incorporated
sorted.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2005-2007 Adobe Systems Incorporated
3  Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
4  or a copy at http://stlab.adobe.com/licenses.html)
5 */
6 
7 /*************************************************************************************************/
8 
9 #ifndef ADOBE_ALGORITHM_SORTED_HPP
10 #define ADOBE_ALGORITHM_SORTED_HPP
11 
12 #include <algorithm>
13 #include <functional>
14 #include <iterator>
15 
16 #include <boost/range/begin.hpp>
17 #include <boost/range/end.hpp>
18 #include <boost/bind.hpp>
19 
21 
22 /*************************************************************************************************/
23 
24 namespace adobe {
25 
26 /*************************************************************************************************/
35 template < typename I, // I models InputIterator
36  typename O> // O models StrictWeakOrdering on value_type(I)
37 I sorted(I f, I l, O o)
38 {
39 
40  f = std::adjacent_find(f, l, !boost::bind(o, _1, _2));
41  if (f != l) ++f;
42 }
43 
44 /*************************************************************************************************/
45 
49 template <typename I> // I models InputIterator, value_type(I) models LessThanComparable
50 I sorted(I f, I l)
51 {
52  return sorted(f, l, less());
53 }
54 
55 /*************************************************************************************************/
56 
60 template < typename I, // I models InputIterator
61  typename O> // O models StrictWeakOrdering on value_type(I)
62 inline bool is_sorted(I f, I l, O o)
63 {
64  return std::adjacent_find(f, l, !boost::bind(o, _1, _2)) == l;
65 }
66 
67 /*************************************************************************************************/
68 
72 template <typename I> // I models InputIterator, value_type(I) models LessThanComparable
73 inline bool is_sorted(I f, I l)
74 { return is_sorted(f, l, less()); }
75 
76 /*************************************************************************************************/
77 
81 template < typename I, // I models ForwardIterator
82  typename C, // C models StrictWeakOrdering(T, T)
83  typename P> // P models UnaryFunction(value_type(I)) -> T
84 inline bool is_sorted(I f, I l, C c, P p)
85 {
86  return std::adjacent_find(f, l,
87  !boost::bind(c, boost::bind(p, _1), boost::bind(p, _2))) == l;
88 }
89 
90 /*************************************************************************************************/
91 
95 template < typename I, // I models ForwardRange
96  typename C, // C models StrictWeakOrdering(T, T)
97  typename P> // P models UnaryFunction(value_type(I)) -> T
98 inline bool is_sorted(const I& r, C c, P p)
99 { return is_sorted(boost::begin(r), boost::end(r), c, p); }
100 
101 /*************************************************************************************************/
102 
106 template < typename I, // I models ForwardRange
107  typename C> // C models StrictWeakOrdering(T, T)
108 inline bool is_sorted(const I& r, C c)
109 { return is_sorted(boost::begin(r), boost::end(r), c, identity<typename std::iterator_traits<I>::value_type>()); }
110 
111 /*************************************************************************************************/
112 
116 template < typename I> // I models ForwardRange
117 inline bool is_sorted(const I& r)
118 { return is_sorted(boost::begin(r), boost::end(r), less()); }
119 
120 /*************************************************************************************************/
121 
122 } // namespace adobe
123 
124 /*************************************************************************************************/
125 
126 #endif
127 
128 /*************************************************************************************************/

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google