1 #ifndef BOOST_MOVE_DETAIL_IS_SORTED_HPP
2 #define BOOST_MOVE_DETAIL_IS_SORTED_HPP
3 ///////////////////////////////////////////////////////////////////////////////
4 //
5 // (C) Copyright Ion Gaztanaga 2017-2018. Distributed under the Boost
6 // Software License, Version 1.0. (See accompanying file
7 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 //
9 // See http://www.boost.org/libs/container for documentation.
10 //
11 ///////////////////////////////////////////////////////////////////////////////
12
13 #ifndef BOOST_CONFIG_HPP
14 # include <boost/config.hpp>
15 #endif
16
17 #if defined(BOOST_HAS_PRAGMA_ONCE)
18 # pragma once
19 #endif
20
21 namespace boost {
22 namespace movelib {
23
24 template<class ForwardIt, class Pred>
is_sorted(ForwardIt const first,ForwardIt last,Pred pred)25 bool is_sorted(ForwardIt const first, ForwardIt last, Pred pred)
26 {
27 if (first != last) {
28 ForwardIt next = first, cur(first);
29 while (++next != last) {
30 if (pred(*next, *cur))
31 return false;
32 cur = next;
33 }
34 }
35 return true;
36 }
37
38 template<class ForwardIt, class Pred>
is_sorted_and_unique(ForwardIt first,ForwardIt last,Pred pred)39 bool is_sorted_and_unique(ForwardIt first, ForwardIt last, Pred pred)
40 {
41 if (first != last) {
42 ForwardIt next = first;
43 while (++next != last) {
44 if (!pred(*first, *next))
45 return false;
46 first = next;
47 }
48 }
49 return true;
50 }
51
52 } //namespace movelib {
53 } //namespace boost {
54
55 #endif //BOOST_MOVE_DETAIL_IS_SORTED_HPP
56