75 class CompareT = std::less<T>>
80 using container_type = std::vector<T>;
81 using compare = CompareT;
82 using iterator =
typename container_type::iterator;
83 using const_iterator =
typename container_type::const_iterator;
91 template<
class InputIt>
100 inline iterator begin();
101 inline const_iterator begin()
const;
102 inline const_iterator cbegin()
const;
104 inline iterator end();
105 inline const_iterator end()
const;
106 inline const_iterator cend()
const;
110 inline const T& top()
const;
111 inline const T& bottom()
const;
118 inline bool empty()
const;
119 inline bool full()
const;
120 inline size_t size()
const;
121 inline size_t capacity()
const;
125 inline bool push(
const T& value);
126 inline bool push(T&& value);
130 inline void reserve(
int capacity);
136 inline const container_type& container()
const;
151template<
class T,
class Cmp>
160template<
class T,
class Cmp>
161limited_priority_queue<T,Cmp>::limited_priority_queue(
const this_type& other) :
163 m_comp(other.m_comp),
168template<
class T,
class Cmp>
169limited_priority_queue<T,Cmp>::limited_priority_queue(
int capacity) :
176template<
class T,
class Cmp>
177template<
class InputIt>
178limited_priority_queue<T,Cmp>::limited_priority_queue(
int capacity, InputIt first, InputIt last) :
183 for(InputIt it=first; it<last; ++it)
189template<
class T,
class Cmp>
190limited_priority_queue<T,Cmp>::~limited_priority_queue()
194template<
class T,
class Cmp>
195limited_priority_queue<T,Cmp>& limited_priority_queue<T,Cmp>::operator=(
const this_type& other)
198 m_comp = other.m_comp;
199 m_size = other.m_size;
205template<
class T,
class Cmp>
206typename limited_priority_queue<T,Cmp>::iterator limited_priority_queue<T,Cmp>::begin()
211template<
class T,
class Cmp>
212typename limited_priority_queue<T,Cmp>::const_iterator limited_priority_queue<T,Cmp>::begin()
const
217template<
class T,
class Cmp>
218typename limited_priority_queue<T,Cmp>::const_iterator limited_priority_queue<T,Cmp>::cbegin()
const
223template<
class T,
class Cmp>
224typename limited_priority_queue<T,Cmp>::iterator limited_priority_queue<T,Cmp>::end()
226 return m_c.begin() + m_size;
229template<
class T,
class Cmp>
230typename limited_priority_queue<T,Cmp>::const_iterator limited_priority_queue<T,Cmp>::end()
const
232 return m_c.begin() + m_size;
235template<
class T,
class Cmp>
236typename limited_priority_queue<T,Cmp>::const_iterator limited_priority_queue<T,Cmp>::cend()
const
238 return m_c.cbegin() + m_size;
243template<
class T,
class Cmp>
244const T& limited_priority_queue<T,Cmp>::top()
const
249template<
class T,
class Cmp>
250const T& limited_priority_queue<T,Cmp>::bottom()
const
252 return m_c[m_size-1];
255template<
class T,
class Cmp>
256T& limited_priority_queue<T,Cmp>::top()
261template<
class T,
class Cmp>
262T& limited_priority_queue<T,Cmp>::bottom()
264 return m_c[m_size-1];
269template<
class T,
class Cmp>
270bool limited_priority_queue<T,Cmp>::empty()
const
275template<
class T,
class Cmp>
276bool limited_priority_queue<T,Cmp>::full()
const
278 return m_size == capacity();
281template<
class T,
class Cmp>
282size_t limited_priority_queue<T,Cmp>::size()
const
287template<
class T,
class Cmp>
288size_t limited_priority_queue<T,Cmp>::capacity()
const
295template<
class T,
class Cmp>
296bool limited_priority_queue<T,Cmp>::push(
const T& value)
309 iterator it = std::upper_bound(begin(), end(), value, m_comp);
323 std::copy_backward(it, end()-1, end());
328 std::copy_backward(it, end(), end()+1);
338template<
class T,
class Cmp>
339bool limited_priority_queue<T,Cmp>::push(T&& value)
345 m_c.front() = std::move(value);
352 iterator it = std::upper_bound(begin(), end(), std::move(value), m_comp);
357 *it = std::move(value);
366 std::copy_backward(it, end()-1, end());
367 *it = std::move(value);
371 std::copy_backward(it, end(), end()+1);
372 *it = std::move(value);
381template<
class T,
class Cmp>
382void limited_priority_queue<T,Cmp>::pop()
387template<
class T,
class Cmp>
388void limited_priority_queue<T,Cmp>::reserve(
int capacity)
394 m_c.resize(capacity);
397template<
class T,
class Cmp>
398void limited_priority_queue<T,Cmp>::clear()
405template<
class T,
class Cmp>
406const typename limited_priority_queue<T,Cmp>::container_type& limited_priority_queue<T,Cmp>::container()
const
The limited_priority_queue class is similar to std::priority_queue but has a limited capacity and han...
This Source Code Form is subject to the terms of the Mozilla Public License, v.