]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
20effc67 | 11 | #include <iterator> |
7c673cae FG |
12 | #include <functional> |
13 | ||
14 | namespace boost { | |
15 | namespace detail { | |
16 | ||
17 | template<class Iterator, class Comp> | |
18 | inline Iterator is_sorted_until (Iterator first, Iterator last, Comp c) { | |
19 | if (first == last) | |
20 | return last; | |
21 | ||
22 | Iterator it = first; ++it; | |
23 | ||
24 | for (; it != last; first = it, ++it) | |
25 | if (c(*it, *first)) | |
26 | return it; | |
27 | ||
28 | return it; | |
29 | } | |
30 | ||
31 | template<class Iterator> | |
32 | inline Iterator is_sorted_until (Iterator first, Iterator last) { | |
20effc67 | 33 | typedef typename std::iterator_traits<Iterator>::value_type |
7c673cae FG |
34 | value_type; |
35 | ||
20effc67 | 36 | typedef std::less<value_type> c; |
7c673cae | 37 | |
20effc67 | 38 | return ::boost::detail::is_sorted_until(first, last, c()); |
7c673cae FG |
39 | } |
40 | ||
41 | template<class Iterator, class Comp> | |
42 | inline bool is_sorted (Iterator first, Iterator last, Comp c) { | |
43 | return ::boost::detail::is_sorted_until(first, last, c) == last; | |
20effc67 | 44 | } |
7c673cae FG |
45 | |
46 | template<class Iterator> | |
47 | inline bool is_sorted (Iterator first, Iterator last) { | |
48 | return ::boost::detail::is_sorted_until(first, last) == last; | |
20effc67 | 49 | } |
7c673cae FG |
50 | |
51 | } // detail | |
52 | } // boost | |
53 | ||
54 | #endif // BOOST_DETAIL_SORTED_HPP | |
55 |