1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2016-2016. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://www.boost.org/libs/container for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
10 #ifndef BOOST_CONTAINER_DETAIL_IS_SORTED_HPP
11 #define BOOST_CONTAINER_DETAIL_IS_SORTED_HPP
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 container {
23 namespace dtl {
24 
25 template <class ForwardIterator, class Pred>
is_sorted(ForwardIterator first,ForwardIterator last,Pred pred)26 bool is_sorted (ForwardIterator first, ForwardIterator last, Pred pred)
27 {
28    if(first != last){
29       ForwardIterator next = first;
30       while (++next != last){
31          if(pred(*next, *first))
32             return false;
33          ++first;
34       }
35    }
36    return true;
37 }
38 
39 template <class ForwardIterator, class Pred>
is_sorted_and_unique(ForwardIterator first,ForwardIterator last,Pred pred)40 bool is_sorted_and_unique (ForwardIterator first, ForwardIterator last, Pred pred)
41 {
42    if(first != last){
43       ForwardIterator next = first;
44       while (++next != last){
45          if(!pred(*first, *next))
46             return false;
47          ++first;
48       }
49    }
50    return true;
51 }
52 
53 }  //namespace dtl {
54 }  //namespace container {
55 }  //namespace boost {
56 
57 #endif   //#ifndef BOOST_CONTAINER_DETAIL_IS_SORTED_HPP
58