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
デストラクタです。
bool push_back_swap(T *v) noexcept
キューに要素を追加してから、その要素とvをstd::swapによって交換します。
C++11の標準ヘッダとなるtype_traitsの代用定義です。 コンパイラや標準ライブラリによってサポートされてい...
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
std::queueに似た、コピーコンストラクタを持たないオブジェクトを格納可能なコンテナ類似クラスです。 ...
Nqueue & assign(Nqueue &rhs, move_tag) noexcept
ムーブ代入演算子に相当します。
constexpr Nqueue() noexcept
デフォルトコンストラクタです。空のキューを作成します。
Nqueue(Nqueue &&rhs) noexcept
ムーブコンストラクタです。C++11の利用時に有効です。
void swap(Nqueue &rhs) noexcept
コンテナをスワップします。
Nqueue(Nqueue &rhs, move_tag) noexcept
ムーブコンストラクタに相当します。
size_t size() const noexcept
格納されている要素の個数を返します。
std::vectorに似ていますが、コピーできないオブジェクトを格納可能なクラスが定義されています。 ...
空の構造体で、関数の引数をムーブすべきことを示すために利用されます。
bool pop_front() noexcept
先頭の要素をキューから取り出します。
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
std::vectorに似た、コピーコンストラクタを持たないオブジェクトを格納可能なコンテナ類似クラスです。 ...
bool empty() const noexcept
コンテナが空かどうかを調べます。
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
#define NLIB_STATIC_ASSERT(exp)
静的アサートが定義されます。利用可能であればstatic_assertを利用します。
size_t capacity() const noexcept
アロケート済みの要素の個数を返します。
Nqueue & operator=(Nqueue &&rhs) noexcept
ムーブ代入演算子です。C++11の利用時に有効です。