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