source: NonGTP/Boost/boost/pending/is_heap.hpp @ 857

Revision 857, 1.8 KB checked in by igarcia, 18 years ago (diff)
Line 
1//
2//=======================================================================
3// Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
4// Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
5//
6// Distributed under the Boost Software License, Version 1.0. (See
7// accompanying file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt)
9//=======================================================================
10//
11#if __KCC
12namespace std {
13
14template <class RandomAccessIterator, class Distance>
15bool __is_heap(RandomAccessIterator first, RandomAccessIterator last,
16               Distance*)
17{
18  const Distance n = last - first;
19
20  Distance parent = 0;
21  for (Distance child = 1; child < n; ++child) {
22    if (first[parent] < first[child])
23      return false;
24    if ((child & 1) == 0)
25      ++parent;
26  }
27  return true;
28}
29
30template <class RandomAccessIterator>
31inline bool is_heap(RandomAccessIterator first, RandomAccessIterator last)
32{
33  return __is_heap(first, last, distance_type(first));
34}
35
36
37template <class RandomAccessIterator, class Distance, class StrictWeakOrdering>
38bool __is_heap(RandomAccessIterator first, RandomAccessIterator last,
39               StrictWeakOrdering comp,
40               Distance*)
41{
42  const Distance n = last - first;
43
44  Distance parent = 0;
45  for (Distance child = 1; child < n; ++child) {
46    if (comp(first[parent], first[child]))
47      return false;
48    if ((child & 1) == 0)
49      ++parent;
50  }
51  return true;
52}
53
54template <class RandomAccessIterator, class StrictWeakOrdering>
55inline bool is_heap(RandomAccessIterator first, RandomAccessIterator last,
56                    StrictWeakOrdering comp)
57{
58  return __is_heap(first, last, comp, distance_type(first));
59}
60
61}
62#endif
Note: See TracBrowser for help on using the repository browser.