3 #ifndef INCLUDE_NN_NLIB_NQUEUE_H_ 4 #define INCLUDE_NN_NLIB_NQUEUE_H_ 7 #include "nn/nlib/Swap.h" 13 extern void* nqueue_enabler;
15 template <
class T,
class AL = std::allocator<
char> >
20 NLIB_MOVE_MEMBER_HELPER_5(
Nqueue, beg1_, end1_, beg2_, end2_, list_)
21 size_t size() const
NLIB_NOEXCEPT {
return (end1_ - beg1_) + (end2_ - beg2_); }
25 #ifdef NLIB_CXX11_RVALUE_REFERENCES 30 return this->pop_front_swap(&tmp);
33 T* tmp = this->push_back();
34 if (!tmp || !v)
return false;
42 swap(beg1_, rhs.beg1_);
43 swap(end1_, rhs.end1_);
44 swap(beg2_, rhs.beg2_);
45 swap(end2_, rhs.end2_);
46 swap(list_, rhs.list_);
58 template <
class T,
class AL>
60 if (end1_ != beg2_ && beg2_ != end2_) {
62 swap(list_[end1_++], list_[beg2_++]);
64 swap(list_[end1_++], list_[beg2_++]);
72 if (list_.
size() == end2_) {
77 return &list_[end2_++];
81 #ifdef NLIB_CXX11_RVALUE_REFERENCES 82 template <
class T,
class AL>
84 if (end1_ != beg2_ && beg2_ != end2_) {
86 swap(list_[end1_++], list_[beg2_++]);
88 swap(list_[end1_++], list_[beg2_++]);
96 if (list_.
size() == end2_) {
97 #ifdef NLIB_HAS_NATIVE_TYPETRAITS 100 T* tmp = list_.
push_back(std::move(rhs));
104 #ifdef NLIB_HAS_NATIVE_TYPETRAITS 107 list_[end2_] = std::move(rhs);
108 return &list_[end2_++];
113 template <
class T,
class AL>
115 if (!v)
return false;
117 if (beg1_ != end1_) {
118 swap(*v, list_[beg1_++]);
119 if (beg1_ == end1_) {
121 }
else if ((end1_ - beg1_) * 8 < end1_) {
122 uint32_t cnt =
static_cast<uint32_t
>(end1_ - beg1_);
123 for (uint32_t i = 0; i < cnt; ++i) {
124 swap(list_[i], list_[beg1_ + i]);
129 }
else if (beg2_ != end2_) {
130 NLIB_ASSERT(beg1_ + end1_ == 0);
131 swap(*v, list_[beg2_++]);
132 if (beg2_ == end2_) beg2_ = end2_ = 0;
141 #ifndef NLIB_STD_SWAP_WORKAROUND 144 NLIB_DEFINE_STD_SWAP_T_BEGIN1(
std)
147 NLIB_DEFINE_STD_SWAP_T1(AL, NLIB_NS::Nqueue)
149 #ifndef NLIB_STD_SWAP_WORKAROUND 152 NLIB_DEFINE_STD_SWAP_T_END1(
std)
155 #endif // INCLUDE_NN_NLIB_NQUEUE_H_ ~Nqueue() noexcept
Destructor.
bool push_back_swap(T *v) noexcept
Adds an element to the queue, and then swaps that element with v using std:: swap.
Substitute definitions for the C++11 standard header type_traits. These substitute definitions are us...
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
A container-like class similar to std::queue that can store objects that do not have copy constructor...
Nqueue() noexcept
Instantiates the object with default parameters (default constructor). Creates an empty queue...
void swap(Nqueue &rhs) noexcept
Swaps the container.
pointer push_back()
Adds an element to the end and initializes it with the default constructor.
Defines the class that resembles std::vector but can store objects that cannot be copied...
bool pop_front() noexcept
Removes the first element from the front of the queue.
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
A container-like class similar to std::vector that can store objects that do not have copy constructo...
bool empty() const noexcept
Checks whether the container is empty.
size_type size() const noexcept
Returns the number of stored elements.
#define NLIB_STATIC_ASSERT(exp)
Defines a static assertion. Uses static_assert if it is available for use.
size_t capacity() const noexcept
Returns the number of allocated elements.