Chris@16
|
1 /*==============================================================================
|
Chris@16
|
2 Copyright (c) 2010-2011 Bryce Lelbach
|
Chris@16
|
3
|
Chris@16
|
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 ==============================================================================*/
|
Chris@16
|
7
|
Chris@16
|
8 #ifndef BOOST_DETAIL_SORTED_HPP
|
Chris@16
|
9 #define BOOST_DETAIL_SORTED_HPP
|
Chris@16
|
10
|
Chris@16
|
11 #include <boost/detail/iterator.hpp>
|
Chris@16
|
12
|
Chris@16
|
13 #include <functional>
|
Chris@16
|
14
|
Chris@16
|
15 namespace boost {
|
Chris@16
|
16 namespace detail {
|
Chris@16
|
17
|
Chris@16
|
18 template<class Iterator, class Comp>
|
Chris@16
|
19 inline Iterator is_sorted_until (Iterator first, Iterator last, Comp c) {
|
Chris@16
|
20 if (first == last)
|
Chris@16
|
21 return last;
|
Chris@16
|
22
|
Chris@16
|
23 Iterator it = first; ++it;
|
Chris@16
|
24
|
Chris@16
|
25 for (; it != last; first = it, ++it)
|
Chris@16
|
26 if (c(*it, *first))
|
Chris@16
|
27 return it;
|
Chris@16
|
28
|
Chris@16
|
29 return it;
|
Chris@16
|
30 }
|
Chris@16
|
31
|
Chris@16
|
32 template<class Iterator>
|
Chris@16
|
33 inline Iterator is_sorted_until (Iterator first, Iterator last) {
|
Chris@16
|
34 typedef typename boost::detail::iterator_traits<Iterator>::value_type
|
Chris@16
|
35 value_type;
|
Chris@16
|
36
|
Chris@16
|
37 typedef std::less<value_type> c;
|
Chris@16
|
38
|
Chris@16
|
39 return ::boost::detail::is_sorted_until(first, last, c());
|
Chris@16
|
40 }
|
Chris@16
|
41
|
Chris@16
|
42 template<class Iterator, class Comp>
|
Chris@16
|
43 inline bool is_sorted (Iterator first, Iterator last, Comp c) {
|
Chris@16
|
44 return ::boost::detail::is_sorted_until(first, last, c) == last;
|
Chris@16
|
45 }
|
Chris@16
|
46
|
Chris@16
|
47 template<class Iterator>
|
Chris@16
|
48 inline bool is_sorted (Iterator first, Iterator last) {
|
Chris@16
|
49 return ::boost::detail::is_sorted_until(first, last) == last;
|
Chris@16
|
50 }
|
Chris@16
|
51
|
Chris@16
|
52 } // detail
|
Chris@16
|
53 } // boost
|
Chris@16
|
54
|
Chris@16
|
55 #endif // BOOST_DETAIL_SORTED_HPP
|
Chris@16
|
56
|