16 #ifndef INCLUDE_NN_NLIB_NQUEUE_H_ 17 #define INCLUDE_NN_NLIB_NQUEUE_H_ 21 #include "nn/nlib/Swap.h" 27 extern void* nqueue_enabler;
29 template <
class T,
class AL = std::allocator<
char> >
34 #ifdef __cpp_rvalue_references 36 : beg1_(rhs.beg1_), end1_(rhs.end1_), beg2_(rhs.beg2_), end2_(rhs.end2_),
37 list_(std::move(rhs.list_)) {
38 beg1_ = end1_ = beg2_ = end2_ = 0;
45 list_ = std::move(rhs.list_);
46 beg1_ = end1_ = beg2_ = end2_ = 0;
51 : beg1_(rhs.beg1_), end1_(rhs.end1_), beg2_(rhs.beg2_), end2_(rhs.end2_),
53 beg1_ = end1_ = beg2_ = end2_ = 0;
61 beg1_ = end1_ = beg2_ = end2_ = 0;
68 #ifdef __cpp_rvalue_references 73 return this->pop_front_swap(&tmp);
76 T* tmp = this->push_back();
77 if (!tmp || !v)
return false;
85 swap(beg1_, rhs.beg1_);
86 swap(end1_, rhs.end1_);
87 swap(beg2_, rhs.beg2_);
88 swap(end2_, rhs.end2_);
89 swap(list_, rhs.list_);
101 template <
class T,
class AL>
103 if (end1_ != beg2_ && beg2_ != end2_) {
105 swap(list_[end1_++], list_[beg2_++]);
106 if (beg2_ != end2_) {
107 swap(list_[end1_++], list_[beg2_++]);
109 if (beg2_ == end2_) {
115 if (list_.size() == end2_) {
116 T* tmp = list_.push_back();
120 return &list_[end2_++];
124 #ifdef __cpp_rvalue_references 125 template <
class T,
class AL>
127 if (end1_ != beg2_ && beg2_ != end2_) {
129 swap(list_[end1_++], list_[beg2_++]);
130 if (beg2_ != end2_) {
131 swap(list_[end1_++], list_[beg2_++]);
133 if (beg2_ == end2_) {
139 if (list_.size() == end2_) {
140 #ifdef NLIB_HAS_NATIVE_TYPETRAITS 143 T* tmp = list_.push_back(std::move(rhs));
147 #ifdef NLIB_HAS_NATIVE_TYPETRAITS 150 list_[end2_] = std::move(rhs);
151 return &list_[end2_++];
156 template <
class T,
class AL>
158 if (!v)
return false;
160 if (beg1_ != end1_) {
161 swap(*v, list_[beg1_++]);
162 if (beg1_ == end1_) {
164 }
else if ((end1_ - beg1_) * 8 < end1_) {
165 uint32_t cnt =
static_cast<uint32_t
>(end1_ - beg1_);
166 for (uint32_t i = 0; i < cnt; ++i) {
167 swap(list_[i], list_[beg1_ + i]);
172 }
else if (beg2_ != end2_) {
173 NLIB_ASSERT(beg1_ + end1_ == 0);
174 swap(*v, list_[beg2_++]);
175 if (beg2_ == end2_) beg2_ = end2_ = 0;
184 NLIB_DEFINE_STD_SWAP_T_BEGIN2(
nn, nlib)
185 NLIB_DEFINE_STD_SWAP_T2(T, AL, NLIB_NS::Nqueue)
186 NLIB_DEFINE_STD_SWAP_T_END2(
nn, nlib)
188 #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 & assign(Nqueue &rhs, move_tag) noexcept
Corresponds to a move assignment operator.
constexpr Nqueue() noexcept
Instantiates the object with default parameters (default constructor). Creates an empty queue...
Nqueue(Nqueue &&rhs) noexcept
Instantiates the object (move constructor). This function is useful when using C++11.
void swap(Nqueue &rhs) noexcept
Swaps the container.
Nqueue(Nqueue &rhs, move_tag) noexcept
Corresponds to a move constructor.
size_t size() const noexcept
Returns the number of stored elements.
Defines the class that resembles std::vector but can store objects that cannot be copied...
An empty structure indicating that an argument to a function needs to be moved.
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.
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
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.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
#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.
Nqueue & operator=(Nqueue &&rhs) noexcept
Move assignment operator. This function is useful when using C++11.