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 39 list_(std::move(rhs.list_)) {
40 beg1_ = end1_ = beg2_ = end2_ = 0;
47 list_ = std::move(rhs.list_);
48 beg1_ = end1_ = beg2_ = end2_ = 0;
57 beg1_ = end1_ = beg2_ = end2_ = 0;
65 beg1_ = end1_ = beg2_ = end2_ = 0;
72 #ifdef __cpp_rvalue_references 77 return this->pop_front_swap(&tmp);
80 T* tmp = this->push_back();
81 if (!tmp || !v)
return false;
97 template<
class T,
class AL>
99 if (end1_ != beg2_ && beg2_ != end2_) {
101 swap(list_[end1_++], list_[beg2_++]);
102 if (beg2_ != end2_) {
103 swap(list_[end1_++], list_[beg2_++]);
105 if (beg2_ == end2_) {
111 if (list_.size() == end2_) {
112 T* tmp = list_.push_back();
116 return &list_[end2_++];
120 #ifdef __cpp_rvalue_references 121 template<
class T,
class AL>
123 if (end1_ != beg2_ && beg2_ != end2_) {
125 swap(list_[end1_++], list_[beg2_++]);
126 if (beg2_ != end2_) {
127 swap(list_[end1_++], list_[beg2_++]);
129 if (beg2_ == end2_) {
135 if (list_.size() == end2_) {
136 #ifdef NLIB_HAS_NATIVE_TYPETRAITS 139 T* tmp = list_.push_back(std::move(rhs));
143 #ifdef NLIB_HAS_NATIVE_TYPETRAITS 146 list_[end2_] = std::move(rhs);
147 return &list_[end2_++];
152 template<
class T,
class AL>
154 if (!v)
return false;
156 if (beg1_ != end1_) {
157 swap(*v, list_[beg1_++]);
158 if (beg1_ == end1_) {
160 }
else if ((end1_ - beg1_) * 8 < end1_) {
161 uint32_t cnt =
static_cast<uint32_t
>(end1_ - beg1_);
162 for (uint32_t i = 0; i < cnt; ++i) {
163 swap(list_[i], list_[beg1_ + i]);
168 }
else if (beg2_ != end2_) {
169 NLIB_ASSERT(beg1_ + end1_ == 0);
170 swap(*v, list_[beg2_++]);
171 if (beg2_ == end2_) beg2_ = end2_ = 0;
180 NLIB_DEFINE_STD_SWAP_T_BEGIN2(
nn, nlib)
181 NLIB_DEFINE_STD_SWAP_T2(T, AL, NLIB_NS::Nqueue)
182 NLIB_DEFINE_STD_SWAP_T_END2(
nn, nlib)
184 #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).
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
Returns true if the number of stored elements is 0, or returns false otherwise.
#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.