37 #ifndef NVWA_FC_QUEUE_H 38 #define NVWA_FC_QUEUE_H 46 #include "type_traits.h" 68 template <
class _Tp,
class _Alloc = std::allocator<_Tp> >
72 typedef _Tp value_type;
73 typedef _Alloc allocator_type;
74 typedef size_t size_type;
75 typedef value_type* pointer;
76 typedef const value_type* const_pointer;
77 typedef value_type& reference;
78 typedef const value_type& const_reference;
96 const allocator_type& alloc = allocator_type())
99 assert(max_size != 0);
100 if (max_size + 1 == 0)
101 throw std::bad_alloc();
102 _M_begin = _M_alloc.allocate(max_size + 1);
103 _M_end = _M_begin + max_size + 1;
104 _M_head = _M_tail = _M_begin;
122 while (_M_head != _M_tail)
125 _M_head = increment(_M_head);
128 _M_alloc.deallocate(_M_begin, _M_end - _M_begin);
155 return _M_head == _M_tail;
166 return _M_head == increment(_M_tail);
176 return _M_end - _M_begin - 1;
184 size_type
size() const _NOEXCEPT
186 ptrdiff_t dist = _M_tail - _M_head;
188 dist += _M_end - _M_begin;
222 return *decrement(_M_tail);
233 return *decrement(_M_tail);
246 void push(
const value_type& value)
248 construct(_M_tail, value);
251 _M_tail = increment(_M_tail);
265 _M_head = increment(_M_head);
277 pointer ptr = _M_head;
278 while (ptr != _M_tail)
282 ptr = increment(ptr);
298 _NOEXCEPT_(noexcept(
std::swap(std::declval<allocator_type&>(),
299 std::declval<allocator_type&>())))
302 swap(_M_alloc, rhs._M_alloc);
303 swap(_M_head, rhs._M_head);
304 swap(_M_tail, rhs._M_tail);
305 swap(_M_begin, rhs._M_begin);
306 swap(_M_end, rhs._M_end);
324 allocator_type _M_alloc;
327 pointer increment(pointer ptr)
const _NOEXCEPT
334 pointer decrement(pointer ptr)
const _NOEXCEPT
340 void construct(
void* ptr,
const _Tp& value)
342 new (ptr) _Tp(value);
344 void destroy(
void* ptr) _NOEXCEPT_(noexcept(std::declval<_Tp*>()->~_Tp()))
346 _M_destroy(ptr, is_trivially_destructible<_Tp>());
350 void _M_destroy(
void*, true_type)
352 void _M_destroy(
void* ptr, false_type)
358 template <
class _Tp,
class _Alloc>
360 : _M_head(_NULLPTR), _M_tail(_NULLPTR), _M_begin(_NULLPTR)
363 pointer ptr = rhs._M_head;
364 while (ptr != rhs._M_tail)
367 ptr = rhs.increment(ptr);
382 template <
class _Tp,
class _Alloc>
384 _NOEXCEPT_(noexcept(lhs.swap(rhs)))
391 #endif // NVWA_FC_QUEUE_H void swap(fc_queue &rhs)
Exchanges the elements of two queues.
Definition: fc_queue.h:297
fc_queue(size_type max_size, const allocator_type &alloc=allocator_type())
Constructor that creates the queue with a maximum size (capacity).
Definition: fc_queue.h:95
Class to represent a fixed-capacity queue.
Definition: fc_queue.h:69
bool contains(const value_type &value) const
Checks whether the queue contains a specific element.
Definition: fc_queue.h:275
size_type capacity() const noexcept
Gets the maximum number of allowed elements in the queue.
Definition: fc_queue.h:174
void swap(fc_queue< _Tp, _Alloc > &lhs, fc_queue< _Tp, _Alloc > &rhs)
Exchanges the elements of two queues.
Definition: fc_queue.h:383
~fc_queue()
Destructor.
Definition: fc_queue.h:120
bool full() const noexcept
Checks whether the queue is full (containing the maximum allowed elements).
Definition: fc_queue.h:164
const_reference front() const
Gets the first element in the queue.
Definition: fc_queue.h:208
reference front()
Gets the first element in the queue.
Definition: fc_queue.h:197
bool empty() const noexcept
Checks whether the queue is empty (containing no elements).
Definition: fc_queue.h:153
size_type size() const noexcept
Gets the number of existing elements in the queue.
Definition: fc_queue.h:184
fc_queue & operator=(const fc_queue &rhs)
Assignment operator that copies all elements from another queue.
Definition: fc_queue.h:141
C++11 feature detection macros and workarounds.
void pop()
Discards the first element in the queue.
Definition: fc_queue.h:261
const_reference back() const
Gets the last element in the queue.
Definition: fc_queue.h:230
allocator_type get_allocator() const
Gets the allocator of the queue.
Definition: fc_queue.h:314
reference back()
Gets the last element in the queue.
Definition: fc_queue.h:219
Common definitions for preprocessing.
void push(const value_type &value)
Inserts a new element at the end of the queue.
Definition: fc_queue.h:246