Chris@102
|
1 //////////////////////////////////////////////////////////////////////////////
|
Chris@102
|
2 //
|
Chris@102
|
3 // (C) Copyright Ion Gaztanaga 2014-2014.
|
Chris@102
|
4 //
|
Chris@102
|
5 // Distributed under the Boost Software License, Version 1.0.
|
Chris@102
|
6 // (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@102
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@102
|
8 //
|
Chris@102
|
9 // See http://www.boost.org/libs/intrusive for documentation.
|
Chris@102
|
10 //
|
Chris@102
|
11 //////////////////////////////////////////////////////////////////////////////
|
Chris@102
|
12
|
Chris@102
|
13 #ifndef BOOST_INTRUSIVE_DETAIL_ALGORITHM_HPP
|
Chris@102
|
14 #define BOOST_INTRUSIVE_DETAIL_ALGORITHM_HPP
|
Chris@102
|
15
|
Chris@102
|
16 #ifndef BOOST_CONFIG_HPP
|
Chris@102
|
17 # include <boost/config.hpp>
|
Chris@102
|
18 #endif
|
Chris@102
|
19
|
Chris@102
|
20 #if defined(BOOST_HAS_PRAGMA_ONCE)
|
Chris@102
|
21 # pragma once
|
Chris@102
|
22 #endif
|
Chris@102
|
23
|
Chris@102
|
24 namespace boost {
|
Chris@102
|
25 namespace intrusive {
|
Chris@102
|
26
|
Chris@102
|
27 struct algo_pred_equal
|
Chris@102
|
28 {
|
Chris@102
|
29 template<class T>
|
Chris@102
|
30 bool operator()(const T &x, const T &y) const
|
Chris@102
|
31 { return x == y; }
|
Chris@102
|
32 };
|
Chris@102
|
33
|
Chris@102
|
34 struct algo_pred_less
|
Chris@102
|
35 {
|
Chris@102
|
36 template<class T>
|
Chris@102
|
37 bool operator()(const T &x, const T &y) const
|
Chris@102
|
38 { return x < y; }
|
Chris@102
|
39 };
|
Chris@102
|
40
|
Chris@102
|
41 template<class InputIt1, class InputIt2, class BinaryPredicate>
|
Chris@102
|
42 bool algo_equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, BinaryPredicate p)
|
Chris@102
|
43 {
|
Chris@102
|
44 for (; first1 != last1; ++first1, ++first2) {
|
Chris@102
|
45 if (!p(*first1, *first2)) {
|
Chris@102
|
46 return false;
|
Chris@102
|
47 }
|
Chris@102
|
48 }
|
Chris@102
|
49 return true;
|
Chris@102
|
50 }
|
Chris@102
|
51
|
Chris@102
|
52 template<class InputIt1, class InputIt2>
|
Chris@102
|
53 bool algo_equal(InputIt1 first1, InputIt1 last1, InputIt2 first2)
|
Chris@102
|
54 { return (algo_equal)(first1, last1, first2, algo_pred_equal()); }
|
Chris@102
|
55
|
Chris@102
|
56 template<class InputIt1, class InputIt2, class BinaryPredicate>
|
Chris@102
|
57 bool algo_equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, BinaryPredicate pred)
|
Chris@102
|
58 {
|
Chris@102
|
59 for (; first1 != last1 && first2 != last2; ++first1, ++first2)
|
Chris@102
|
60 if (!pred(*first1, *first2))
|
Chris@102
|
61 return false;
|
Chris@102
|
62 return first1 == last1 && first2 == last2;
|
Chris@102
|
63 }
|
Chris@102
|
64
|
Chris@102
|
65 template<class InputIt1, class InputIt2>
|
Chris@102
|
66 bool algo_equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2)
|
Chris@102
|
67 { return (algo_equal)(first1, last1, first2, last2, algo_pred_equal()); }
|
Chris@102
|
68
|
Chris@102
|
69 template <class InputIterator1, class InputIterator2, class BinaryPredicate>
|
Chris@102
|
70 bool algo_lexicographical_compare (InputIterator1 first1, InputIterator1 last1,
|
Chris@102
|
71 InputIterator2 first2, InputIterator2 last2,
|
Chris@102
|
72 BinaryPredicate pred)
|
Chris@102
|
73 {
|
Chris@102
|
74 while (first1 != last1){
|
Chris@102
|
75 if (first2 == last2 || *first2 < *first1) return false;
|
Chris@102
|
76 else if (pred(*first1, *first2)) return true;
|
Chris@102
|
77 ++first1; ++first2;
|
Chris@102
|
78 }
|
Chris@102
|
79 return (first2 != last2);
|
Chris@102
|
80 }
|
Chris@102
|
81
|
Chris@102
|
82 template <class InputIterator1, class InputIterator2>
|
Chris@102
|
83 bool algo_lexicographical_compare (InputIterator1 first1, InputIterator1 last1,
|
Chris@102
|
84 InputIterator2 first2, InputIterator2 last2)
|
Chris@102
|
85 { return (algo_lexicographical_compare)(first1, last1, first2, last2, algo_pred_less()); }
|
Chris@102
|
86
|
Chris@102
|
87 } //namespace intrusive {
|
Chris@102
|
88 } //namespace boost {
|
Chris@102
|
89
|
Chris@102
|
90 #endif //#ifndef BOOST_INTRUSIVE_DETAIL_ALGORITHM_HPP
|