btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / headers / cpp / stl_queue.h
blobc1e2b6984403619f3d757801d55e8b18ea336bb8
1 /*
3 * Copyright (c) 1994
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
34 __STL_BEGIN_NAMESPACE
36 #ifndef __STL_LIMITED_DEFAULT_TEMPLATES
37 template <class _Tp, class _Sequence = deque<_Tp> >
38 #else
39 template <class _Tp, class _Sequence>
40 #endif
41 class queue {
42 friend bool operator== __STL_NULL_TMPL_ARGS (const queue&, const queue&);
43 friend bool operator< __STL_NULL_TMPL_ARGS (const queue&, const queue&);
44 public:
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;
51 protected:
52 _Sequence c;
53 public:
54 queue() : c() {}
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>
68 bool
69 operator==(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
71 return __x.c == __y.c;
74 template <class _Tp, class _Sequence>
75 bool
76 operator<(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
78 return __x.c < __y.c;
81 #ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
83 template <class _Tp, class _Sequence>
84 bool
85 operator!=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
87 return !(__x == __y);
90 template <class _Tp, class _Sequence>
91 bool
92 operator>(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
94 return __y < __x;
97 template <class _Tp, class _Sequence>
98 bool
99 operator<=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
101 return !(__y < __x);
104 template <class _Tp, class _Sequence>
105 bool
106 operator>=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
108 return !(__x < __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> >
116 #else
117 template <class _Tp, class _Sequence, class _Compare>
118 #endif
119 class priority_queue {
120 public:
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;
127 protected:
128 _Sequence c;
129 _Compare comp;
130 public:
131 priority_queue() : c() {}
132 explicit priority_queue(const _Compare& __x) : c(), comp(__x) {}
133 priority_queue(const _Compare& __x, const _Sequence& __s)
134 : c(__s), comp(__x)
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)
151 : c(__s), comp(__x)
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,
162 const _Compare& __x)
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)
168 : c(__c), comp(__x)
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) {
179 __STL_TRY {
180 c.push_back(__x);
181 push_heap(c.begin(), c.end(), comp);
183 __STL_UNWIND(c.clear());
185 void pop() {
186 __STL_TRY {
187 pop_heap(c.begin(), c.end(), comp);
188 c.pop_back();
190 __STL_UNWIND(c.clear());
194 // no equality is provided
196 __STL_END_NAMESPACE
198 #endif /* __SGI_STL_INTERNAL_QUEUE_H */
200 // Local Variables:
201 // mode:C++
202 // End: