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
デストラクタです。
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
ムーブコンストラクタです。
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
格納されている要素数が0ならばtrue、それ以外ならfalseを返します。
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
#define NLIB_STATIC_ASSERT(exp)
静的アサートが定義されます。利用可能であればstatic_assertを利用します。
size_t capacity() const noexcept
アロケート済みの要素の個数を返します。
Nqueue & operator=(Nqueue &&rhs) noexcept
ムーブ代入演算子です。