4 * Hewlett-Packard Company
6 * Copyright (c) 1996,1997
7 * Silicon Graphics Computer Systems, Inc.
10 * Moscow Center for SPARC Technology
15 * This material is provided "as is", with absolutely no warranty expressed
16 * or implied. Any use is at your own risk.
18 * Permission to use or copy this software for any purpose is hereby granted
19 * without fee, provided the above notices are retained on all copies.
20 * Permission to modify the code and to distribute modified code is granted,
21 * provided the above notices are retained, and a notice that the code was
22 * modified is included with the above copyright notice.
26 /* NOTE: This is an internal header file, included by other STL headers.
27 * You should not attempt to use it directly.
30 #ifndef _STLP_INTERNAL_QUEUE_H
31 #define _STLP_INTERNAL_QUEUE_H
33 #ifndef _STLP_INTERNAL_DEQUE_H
34 # include <stl/_deque.h>
37 #ifndef _STLP_INTERNAL_VECTOR_H
38 # include <stl/_vector.h>
41 #ifndef _STLP_INTERNAL_HEAP_H
42 # include <stl/_heap.h>
45 #ifndef _STLP_INTERNAL_FUNCTION_BASE_H
46 # include <stl/_function_base.h>
49 #if defined(__SC__) && !defined(__DMC__) //*ty 12/07/2001 - since "comp" is a built-in type and reserved under SCpp
55 # if ! defined ( _STLP_LIMITED_DEFAULT_TEMPLATES )
56 template <class _Tp, class _Sequence = deque<_Tp> >
57 # elif defined ( _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS )
58 # define _STLP_QUEUE_ARGS _Tp
61 template <class _Tp, class _Sequence>
64 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
65 # if defined (_STLP_QUEUE_ARGS)
66 : public __stlport_class<queue<_Tp> >
68 : public __stlport_class<queue<_Tp, _Sequence> >
72 # if defined ( _STLP_QUEUE_ARGS )
73 typedef deque<_Tp> _Sequence;
74 typedef queue<_Tp> _Self;
76 typedef queue<_Tp, _Sequence> _Self;
79 typedef typename _Sequence::value_type value_type;
80 typedef typename _Sequence::size_type size_type;
81 typedef _Sequence container_type;
83 typedef typename _Sequence::reference reference;
84 typedef typename _Sequence::const_reference const_reference;
87 //c is a Standard name (23.2.3.1), do no make it STLport naming convention compliant.
91 explicit queue(const _Sequence& __c) : c(__c) {}
93 queue(__move_source<_Self> src)
94 : c(_STLP_PRIV _AsMoveSource(src.get().c)) {}
96 bool empty() const { return c.empty(); }
97 size_type size() const { return c.size(); }
98 reference front() { return c.front(); }
99 const_reference front() const { return c.front(); }
100 reference back() { return c.back(); }
101 const_reference back() const { return c.back(); }
102 void push(const value_type& __x) { c.push_back(__x); }
103 void pop() { c.pop_front(); }
104 const _Sequence& _Get_s() const { return c; }
107 #ifndef _STLP_QUEUE_ARGS
108 # define _STLP_QUEUE_ARGS _Tp, _Sequence
109 # define _STLP_QUEUE_HEADER_ARGS class _Tp, class _Sequence
111 # define _STLP_QUEUE_HEADER_ARGS class _Tp
114 template < _STLP_QUEUE_HEADER_ARGS >
115 inline bool _STLP_CALL
116 operator==(const queue<_STLP_QUEUE_ARGS >& __x, const queue<_STLP_QUEUE_ARGS >& __y) {
117 return __x._Get_s() == __y._Get_s();
120 template < _STLP_QUEUE_HEADER_ARGS >
121 inline bool _STLP_CALL
122 operator<(const queue<_STLP_QUEUE_ARGS >& __x, const queue<_STLP_QUEUE_ARGS >& __y) {
123 return __x._Get_s() < __y._Get_s();
126 _STLP_RELOPS_OPERATORS( template < _STLP_QUEUE_HEADER_ARGS >, queue<_STLP_QUEUE_ARGS > )
128 # if !(defined ( _STLP_LIMITED_DEFAULT_TEMPLATES ) || defined ( _STLP_TEMPLATE_PARAM_SUBTYPE_BUG ))
129 template <class _Tp, class _Sequence = vector<_Tp>,
130 class _Compare = less<_STLP_HEADER_TYPENAME _Sequence::value_type> >
131 # elif defined ( _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS )
134 template <class _Tp, class _Sequence, class _Compare>
137 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
138 # if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS)
139 : public __stlport_class<priority_queue<_Tp> >
141 : public __stlport_class<priority_queue<_Tp, _Sequence> >
145 # ifdef _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS
146 typedef vector<_Tp> _Sequence;
147 typedef less< typename vector<_Tp>::value_type> _Compare;
148 typedef priority_queue<_Tp> _Self;
150 typedef priority_queue<_Tp, _Sequence, _Compare> _Self;
153 typedef typename _Sequence::value_type value_type;
154 typedef typename _Sequence::size_type size_type;
155 typedef _Sequence container_type;
157 typedef typename _Sequence::reference reference;
158 typedef typename _Sequence::const_reference const_reference;
160 //c is a Standard name (23.2.3.2), do no make it STLport naming convention compliant.
164 priority_queue() : c() {}
165 explicit priority_queue(const _Compare& __x) : c(), comp(__x) {}
166 priority_queue(const _Compare& __x, const _Sequence& __s)
168 { make_heap(c.begin(), c.end(), comp); }
170 priority_queue(__move_source<_Self> src)
171 : c(_STLP_PRIV _AsMoveSource(src.get().c)),
172 comp(_STLP_PRIV _AsMoveSource(src.get().comp)) {}
174 #ifdef _STLP_MEMBER_TEMPLATES
175 template <class _InputIterator>
176 priority_queue(_InputIterator __first, _InputIterator __last)
177 : c(__first, __last) { make_heap(c.begin(), c.end(), comp); }
179 template <class _InputIterator>
180 priority_queue(_InputIterator __first,
181 _InputIterator __last, const _Compare& __x)
182 : c(__first, __last), comp(__x)
183 { make_heap(c.begin(), c.end(), comp); }
185 template <class _InputIterator>
186 priority_queue(_InputIterator __first, _InputIterator __last,
187 const _Compare& __x, const _Sequence& __s)
190 c.insert(c.end(), __first, __last);
191 make_heap(c.begin(), c.end(), comp);
194 #else /* _STLP_MEMBER_TEMPLATES */
195 priority_queue(const value_type* __first, const value_type* __last)
196 : c(__first, __last) { make_heap(c.begin(), c.end(), comp); }
198 priority_queue(const value_type* __first, const value_type* __last,
200 : c(__first, __last), comp(__x)
201 { make_heap(c.begin(), c.end(), comp); }
203 priority_queue(const value_type* __first, const value_type* __last,
204 const _Compare& __x, const _Sequence& __c)
207 c.insert(c.end(), __first, __last);
208 make_heap(c.begin(), c.end(), comp);
210 #endif /* _STLP_MEMBER_TEMPLATES */
212 bool empty() const { return c.empty(); }
213 size_type size() const { return c.size(); }
214 const_reference top() const { return c.front(); }
215 void push(const value_type& __x) {
218 push_heap(c.begin(), c.end(), comp);
220 _STLP_UNWIND(c.clear())
224 pop_heap(c.begin(), c.end(), comp);
227 _STLP_UNWIND(c.clear())
231 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
232 template <class _Tp, class _Sequence>
233 struct __move_traits<queue<_Tp, _Sequence> > :
234 _STLP_PRIV __move_traits_aux<_Sequence>
237 template <class _Tp, class _Sequence, class _Compare>
238 struct __move_traits<priority_queue<_Tp, _Sequence, _Compare> > :
239 _STLP_PRIV __move_traits_aux2<_Sequence, _Compare>
241 #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
245 #undef _STLP_QUEUE_ARGS
246 #undef _STLP_QUEUE_HEADER_ARGS
249 #endif /* _STLP_INTERNAL_QUEUE_H */