4 * Hewlett-Packard Company
6 * Permission to use, copy, modify, distribute and sell this software
7 * and its documentation for any purpose is hereby granted without fee,
8 * provided that the above copyright notice appear in all copies and
9 * that both that copyright notice and this permission notice appear
10 * in supporting documentation. Hewlett-Packard Company makes no
11 * representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
15 * Copyright (c) 1996,1997
16 * Silicon Graphics Computer Systems, Inc.
18 * Permission to use, copy, modify, distribute and sell this software
19 * and its documentation for any purpose is hereby granted without fee,
20 * provided that the above copyright notice appear in all copies and
21 * that both that copyright notice and this permission notice appear
22 * in supporting documentation. Silicon Graphics makes no
23 * representations about the suitability of this software for any
24 * purpose. It is provided "as is" without express or implied warranty.
27 /* NOTE: This is an internal header file, included by other STL headers.
28 * You should not attempt to use it directly.
31 #ifndef __SGI_STL_INTERNAL_QUEUE_H
32 #define __SGI_STL_INTERNAL_QUEUE_H
36 #ifndef __STL_LIMITED_DEFAULT_TEMPLATES
37 template <class _Tp
, class _Sequence
= deque
<_Tp
> >
39 template <class _Tp
, class _Sequence
>
42 friend bool operator== __STL_NULL_TMPL_ARGS (const queue
&, const queue
&);
43 friend bool operator< __STL_NULL_TMPL_ARGS (const queue
&, const queue
&);
45 typedef typename
_Sequence::value_type value_type
;
46 typedef typename
_Sequence::size_type size_type
;
47 typedef _Sequence container_type
;
49 typedef typename
_Sequence::reference reference
;
50 typedef typename
_Sequence::const_reference const_reference
;
55 explicit queue(const _Sequence
& __c
) : c(__c
) {}
57 bool empty() const { return c
.empty(); }
58 size_type
size() const { return c
.size(); }
59 reference
front() { return c
.front(); }
60 const_reference
front() const { return c
.front(); }
61 reference
back() { return c
.back(); }
62 const_reference
back() const { return c
.back(); }
63 void push(const value_type
& __x
) { c
.push_back(__x
); }
64 void pop() { c
.pop_front(); }
67 template <class _Tp
, class _Sequence
>
69 operator==(const queue
<_Tp
, _Sequence
>& __x
, const queue
<_Tp
, _Sequence
>& __y
)
71 return __x
.c
== __y
.c
;
74 template <class _Tp
, class _Sequence
>
76 operator<(const queue
<_Tp
, _Sequence
>& __x
, const queue
<_Tp
, _Sequence
>& __y
)
81 #ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
83 template <class _Tp
, class _Sequence
>
85 operator!=(const queue
<_Tp
, _Sequence
>& __x
, const queue
<_Tp
, _Sequence
>& __y
)
90 template <class _Tp
, class _Sequence
>
92 operator>(const queue
<_Tp
, _Sequence
>& __x
, const queue
<_Tp
, _Sequence
>& __y
)
97 template <class _Tp
, class _Sequence
>
99 operator<=(const queue
<_Tp
, _Sequence
>& __x
, const queue
<_Tp
, _Sequence
>& __y
)
104 template <class _Tp
, class _Sequence
>
106 operator>=(const queue
<_Tp
, _Sequence
>& __x
, const queue
<_Tp
, _Sequence
>& __y
)
111 #endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
113 #ifndef __STL_LIMITED_DEFAULT_TEMPLATES
114 template <class _Tp
, class _Sequence
= vector
<_Tp
>,
115 class _Compare
= less
<typename
_Sequence::value_type
> >
117 template <class _Tp
, class _Sequence
, class _Compare
>
119 class priority_queue
{
121 typedef typename
_Sequence::value_type value_type
;
122 typedef typename
_Sequence::size_type size_type
;
123 typedef _Sequence container_type
;
125 typedef typename
_Sequence::reference reference
;
126 typedef typename
_Sequence::const_reference const_reference
;
131 priority_queue() : c() {}
132 explicit priority_queue(const _Compare
& __x
) : c(), comp(__x
) {}
133 priority_queue(const _Compare
& __x
, const _Sequence
& __s
)
135 { make_heap(c
.begin(), c
.end(), comp
); }
137 #ifdef __STL_MEMBER_TEMPLATES
138 template <class _InputIterator
>
139 priority_queue(_InputIterator __first
, _InputIterator __last
)
140 : c(__first
, __last
) { make_heap(c
.begin(), c
.end(), comp
); }
142 template <class _InputIterator
>
143 priority_queue(_InputIterator __first
,
144 _InputIterator __last
, const _Compare
& __x
)
145 : c(__first
, __last
), comp(__x
)
146 { make_heap(c
.begin(), c
.end(), comp
); }
148 template <class _InputIterator
>
149 priority_queue(_InputIterator __first
, _InputIterator __last
,
150 const _Compare
& __x
, const _Sequence
& __s
)
153 c
.insert(c
.end(), __first
, __last
);
154 make_heap(c
.begin(), c
.end(), comp
);
157 #else /* __STL_MEMBER_TEMPLATES */
158 priority_queue(const value_type
* __first
, const value_type
* __last
)
159 : c(__first
, __last
) { make_heap(c
.begin(), c
.end(), comp
); }
161 priority_queue(const value_type
* __first
, const value_type
* __last
,
163 : c(__first
, __last
), comp(__x
)
164 { make_heap(c
.begin(), c
.end(), comp
); }
166 priority_queue(const value_type
* __first
, const value_type
* __last
,
167 const _Compare
& __x
, const _Sequence
& __c
)
170 c
.insert(c
.end(), __first
, __last
);
171 make_heap(c
.begin(), c
.end(), comp
);
173 #endif /* __STL_MEMBER_TEMPLATES */
175 bool empty() const { return c
.empty(); }
176 size_type
size() const { return c
.size(); }
177 const_reference
top() const { return c
.front(); }
178 void push(const value_type
& __x
) {
181 push_heap(c
.begin(), c
.end(), comp
);
183 __STL_UNWIND(c
.clear());
187 pop_heap(c
.begin(), c
.end(), comp
);
190 __STL_UNWIND(c
.clear());
194 // no equality is provided
198 #endif /* __SGI_STL_INTERNAL_QUEUE_H */