16 #ifndef INCLUDE_NN_NLIB_NLIST_H_ 17 #define INCLUDE_NN_NLIB_NLIST_H_ 26 #include "nn/nlib/Swap.h" 31 template<
class T,
class AL>
48 #ifdef __cpp_rvalue_references 49 NlistBase(NlistBase&& rhs)
NLIB_NOEXCEPT : curblk_(rhs.curblk_),
50 curlevel_(rhs.curlevel_),
52 firstblk_(rhs.firstblk_) {
53 rhs.curblk_ =
nullptr;
56 rhs.firstblk_ =
nullptr;
59 curblk_ = rhs.curblk_;
60 curlevel_ = rhs.curlevel_;
61 curidx_ = rhs.curidx_;
62 firstblk_ = rhs.firstblk_;
63 rhs.curblk_ =
nullptr;
66 rhs.firstblk_ =
nullptr;
70 NlistBase(NlistBase& rhs, move_tag)
NLIB_NOEXCEPT : curblk_(rhs.curblk_),
71 curlevel_(rhs.curlevel_),
73 firstblk_(rhs.firstblk_) {
74 rhs.curblk_ =
nullptr;
77 rhs.firstblk_ =
nullptr;
80 curblk_ = rhs.curblk_;
81 curlevel_ = rhs.curlevel_;
82 curidx_ = rhs.curidx_;
83 firstblk_ = rhs.firstblk_;
84 rhs.curblk_ =
nullptr;
87 rhs.firstblk_ =
nullptr;
90 static size_t BlkBaseIdx(
size_t level)
NLIB_NOEXCEPT {
return 8 * ((1 << level) - 1); }
91 static size_t BlkSize(
size_t level)
NLIB_NOEXCEPT {
return 8 * (1 << level); }
102 mutable Blk* curblk_;
103 mutable size_t curlevel_;
104 mutable size_t curidx_;
105 mutable Blk* firstblk_;
112 class NlistConstIterator;
117 class NlistBaseT :
public NlistBase {
119 typedef T& reference;
120 typedef const T& const_reference;
121 typedef NlistIterator<T> iterator;
122 typedef NlistConstIterator<T> const_iterator;
123 typedef size_t size_type;
124 typedef T value_type;
126 typedef const T* const_pointer;
127 typedef ptrdiff_t difference_type;
131 #ifdef __cpp_rvalue_references 132 #ifdef NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS 133 NlistBaseT(NlistBaseT&& rhs) =
default;
134 NlistBaseT& operator=(NlistBaseT&& rhs) =
default;
136 NlistBaseT(NlistBaseT&& rhs)
NLIB_NOEXCEPT : NlistBase(std::move(rhs)) {}
138 NlistBase::operator=(std::move(rhs));
143 NlistBaseT(NlistBaseT& rhs, move_tag)
NLIB_NOEXCEPT : NlistBase(rhs, move_tag()) {}
144 NlistBaseT& assign(NlistBaseT& rhs, move_tag)
NLIB_NOEXCEPT {
145 NlistBase::assign(rhs, move_tag());
149 static T* GetItem(Blk* blk)
NLIB_NOEXCEPT {
return static_cast<T*
>(blk->item); }
151 return static_cast<const T*
>(blk->item);
155 const Blk* p = this->AtSub(n, &base);
156 return p ?
const_cast<T*
>(&(GetItem(p)[n - base])) : nullptr;
158 iterator Begin()
NLIB_NOEXCEPT {
return iterator(
this, TrueType()); }
159 iterator End()
NLIB_NOEXCEPT {
return iterator(
this, FalseType()); }
160 const_iterator Begin() const
NLIB_NOEXCEPT {
return const_iterator(
this, TrueType()); }
161 const_iterator End() const
NLIB_NOEXCEPT {
return const_iterator(
this, FalseType()); }
165 friend class NlistConstIterator<T>;
166 friend class NlistIterator<T>;
170 class NlistConstIterator :
public std::iterator<std::forward_iterator_tag, T> {
172 typedef NlistBaseT<T> ContainerType;
173 typedef typename ContainerType::Blk Blk;
176 typedef typename std::iterator<std::forward_iterator_tag, T> BaseType;
177 typedef typename BaseType::iterator_category iterator_category;
178 typedef typename BaseType::value_type value_type;
179 typedef typename BaseType::difference_type difference_type;
180 typedef typename BaseType::pointer pointer;
181 typedef typename BaseType::reference reference;
190 NlistConstIterator(
const ContainerType* p, TrueType)
NLIB_NOEXCEPT {
191 ContainerType* rhs =
const_cast<ContainerType*
>(p);
193 blk_ = rhs->firstblk_;
194 elemptr_ = GetItem(blk_);
195 blkend_ = elemptr_ + 8;
197 NlistConstIterator(
const ContainerType* p, FalseType)
NLIB_NOEXCEPT {
198 ContainerType* rhs =
const_cast<ContainerType*
>(p);
199 idx_ = rhs->BlkBaseIdx(rhs->curlevel_) + rhs->curidx_;
201 elemptr_ = &(GetItem(blk_)[rhs->curidx_]);
202 blkend_ = GetItem(blk_) + rhs->BlkSize(rhs->curlevel_);
203 if (elemptr_ == blkend_) this->Normalize();
208 const T* operator->() const
NLIB_NOEXCEPT {
return elemptr_; }
210 NLIB_ASSERT(elemptr_ != blkend_);
212 if (++elemptr_ == blkend_) this->Normalize();
216 NlistConstIterator rval(*
this);
221 return idx_ == rhs.idx_ && elemptr_ == rhs.elemptr_;
225 difference_type Distance(NlistConstIterator to)
const NLIB_NOEXCEPT {
return to.idx_ - idx_; }
228 static T* GetItem(Blk* blk)
NLIB_NOEXCEPT {
return static_cast<T*
>(blk->item); }
230 return reinterpret_cast<const T*
>(blk->item);
239 friend class NlistBaseT<T>;
244 if (blk_ && blk_->next) {
245 Blk* next = blk_->next;
246 size_t next_size = 2 *
static_cast<size_t>(blkend_ - GetItem(blk_));
247 T* next_elemptr = GetItem(next);
248 T* next_end = next_elemptr + next_size;
250 elemptr_ = next_elemptr;
258 void NlistConstIterator<T>::Advance(difference_type n)
NLIB_NOEXCEPT {
259 while (elemptr_ + n >= blkend_) {
260 n -= blkend_ - elemptr_;
261 idx_ += blkend_ - elemptr_;
263 if (!this->Normalize())
return;
270 class NlistIterator :
public NlistConstIterator<T> {
272 typedef NlistBaseT<T> ContainerType;
273 typedef typename ContainerType::Blk Blk;
274 typedef NlistConstIterator<T> MyBase;
277 typedef typename NlistConstIterator<T>::BaseType BaseType;
278 typedef typename BaseType::iterator_category iterator_category;
279 typedef typename BaseType::value_type value_type;
280 typedef typename BaseType::difference_type difference_type;
281 typedef typename BaseType::pointer pointer;
282 typedef typename BaseType::reference reference;
288 NlistIterator(
const ContainerType* p, TrueType)
NLIB_NOEXCEPT : MyBase(p, TrueType()) {}
289 NlistIterator(
const ContainerType* p, FalseType)
NLIB_NOEXCEPT : MyBase(p, FalseType()) {}
293 const MyBase* tmp =
static_cast<const MyBase*
>(
this);
294 return const_cast<T&
>(**tmp);
297 const MyBase* tmp =
static_cast<const MyBase*
>(
this);
298 return const_cast<T*
>(tmp->operator->());
301 MyBase* tmp =
static_cast<MyBase*
>(
this);
306 NlistIterator rval(*
this);
311 const MyBase* tmp =
static_cast<const MyBase*
>(
this);
312 const MyBase* tmp2 =
static_cast<const MyBase*
>(&rhs);
313 return *tmp == *tmp2;
316 difference_type Distance(NlistIterator to)
const NLIB_NOEXCEPT {
317 const MyBase* tmp =
static_cast<const MyBase*
>(
this);
318 const MyBase* tmp2 =
static_cast<const MyBase*
>(&to);
319 return tmp->Distance(*tmp2);
323 friend class NlistBaseT<T>;
326 template<
bool is_empty,
class AL>
330 explicit NlistAlloc(
const AL& al)
NLIB_NOEXCEPT : alloc_(al) {}
333 AL& _GetNlistAlloc() const
NLIB_NOEXCEPT {
return const_cast<AL&
>(alloc_); }
336 swap(alloc_, rhs.alloc_);
338 #ifdef __cpp_rvalue_references 339 #ifdef NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS 340 NlistAlloc(NlistAlloc&& rhs) =
default;
341 NlistAlloc& operator=(NlistAlloc&& rhs) =
default;
343 NlistAlloc(NlistAlloc&& rhs)
NLIB_NOEXCEPT : alloc_(std::move(rhs.alloc_)) {}
345 alloc_ = std::move(rhs.alloc_);
350 NlistAlloc(NlistAlloc& rhs, move_tag)
NLIB_NOEXCEPT : alloc_() {
352 swap(alloc_, rhs.alloc_);
354 NlistAlloc& assign(NlistAlloc& rhs, move_tag)
NLIB_NOEXCEPT {
356 AL x(*
this, move_tag());
357 swap(alloc_, rhs.alloc_);
366 class NlistAlloc<true, AL> {
369 explicit NlistAlloc(
const AL& al)
NLIB_NOEXCEPT { NLIB_UNUSED(al); }
373 void _SwapNlistAlloc(NlistAlloc& rhs)
NLIB_NOEXCEPT { NLIB_UNUSED(rhs); }
374 #ifdef __cpp_rvalue_references 376 NlistAlloc& operator=(NlistAlloc&&)
NLIB_NOEXCEPT {
return *
this; }
379 NlistAlloc& assign(NlistAlloc&, move_tag)
NLIB_NOEXCEPT {
return *
this; }
384 template<
class T,
class AL = std::allocator<
char> >
385 class Nlist
NLIB_FINAL :
public nlist::NlistBaseT<T>,
386 public nlist::NlistAlloc<IsEmpty<AL>::value, AL> {
411 typedef typename nlist::NlistBaseT<T> BaseType;
412 typedef typename nlist::NlistAlloc<IsEmpty<AL>::value, AL> AllocType;
413 using BaseType::curblk_;
414 using BaseType::curidx_;
415 using BaseType::curlevel_;
416 using BaseType::firstblk_;
417 using BaseType::ConfirmBack;
418 using BaseType::ClearSimple;
419 using BaseType::BlkBaseIdx;
420 using BaseType::BlkSize;
421 using BaseType::GetItem;
422 using BaseType::Begin;
424 typedef typename BaseType::Blk Blk;
442 #ifdef __cpp_rvalue_references 443 #ifdef NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS 450 this->DeallocBlkList(firstblk_, 0);
451 BaseType::operator =(std::move(rhs));
452 AllocType::operator=(std::move(rhs));
460 this->DeallocBlkList(firstblk_, 0);
468 return (
nullptr != this->LastBlock(&lv)) ? BlkBaseIdx(lv + 1) : 0;
472 return Resize(n,
typename IsTriviallyDefaultConstructible<T>::type());
476 void* p = this->PushBack();
477 if (!p)
return nullptr;
478 pointer ptr = MyCtor(p,
typename IsTriviallyDefaultConstructible<T>::type());
482 #ifdef __cpp_rvalue_references 484 #if defined(NLIB_HAS_NATIVE_TYPETRAITS) && !defined(NLIB_HAS_TR1_TYPETRAITS) && \ 485 (!defined(_MSC_VER) || _MSC_VER > 1800) 486 #ifdef __cpp_exceptions 491 void* p = this->PushBack();
492 if (!p)
return nullptr;
493 pointer ptr =
new (p) T(std::forward<T>(rhs));
499 void* p = this->PushBack();
500 if (!p)
return nullptr;
501 pointer ptr =
new (p) T(rhs);
506 return this->pop_back_(
typename IsTriviallyDestructible<T>::type());
512 NLIB_ASSERT(!this->empty());
513 if (curidx_ == 0) ConfirmBack();
514 return GetItem(curblk_)[curidx_ - 1];
517 NLIB_ASSERT(!this->empty());
518 if (curidx_ == 0) ConfirmBack();
519 return GetItem(curblk_)[curidx_ - 1];
522 NLIB_ASSERT(!this->empty());
523 return GetItem(firstblk_)[0];
526 NLIB_ASSERT(!this->empty());
527 return GetItem(firstblk_)[0];
530 NLIB_ASSERT(n < this->size());
534 NLIB_ASSERT(n < this->size());
538 if (!firstblk_ && !ConfirmFirstBlk())
return iterator();
542 if (!firstblk_ && !ConfirmFirstBlk())
return const_iterator();
546 if (!firstblk_ && !ConfirmFirstBlk())
return const_iterator();
551 if (!firstblk_ && !ConfirmFirstBlk())
return iterator();
555 if (!firstblk_ && !ConfirmFirstBlk())
return const_iterator();
559 if (!firstblk_ && !ConfirmFirstBlk())
return const_iterator();
564 if (!curblk_)
return;
565 Blk* p = curblk_->next;
566 curblk_->next =
nullptr;
567 DeallocBlkList(p, static_cast<int>(curlevel_ + 1));
569 #if defined(__cpp_rvalue_references) && defined(__cpp_variadic_templates) 570 template<
class... Args>
572 void* p = this->PushBack();
573 if (!p)
return nullptr;
574 pointer ptr =
new (p) T(std::forward<Args>(args)...);
580 pointer EmplaceBack(
const A1& a1) {
581 void* p = this->PushBack();
582 if (!p)
return nullptr;
583 pointer ptr =
new (p) T(
const_cast<typename RemoveConst<A1>::type&
>(a1));
587 template<
class A1,
class A2>
588 pointer EmplaceBack(
const A1& a1,
const A2& a2) {
589 void* p = this->PushBack();
590 if (!p)
return nullptr;
591 pointer ptr =
new (p) T(
const_cast<typename RemoveConst<A1>::type&
>(a1),
592 const_cast<typename RemoveConst<A2>::type&
>(a2));
596 template<
class A1,
class A2,
class A3>
597 pointer EmplaceBack(
const A1& a1,
const A2& a2,
const A3& a3) {
598 void* p = this->PushBack();
599 if (!p)
return nullptr;
600 pointer ptr =
new (p) T(
const_cast<typename RemoveConst<A1>::type&
>(a1),
601 const_cast<typename RemoveConst<A2>::type&
>(a2),
602 const_cast<typename RemoveConst<A3>::type&
>(a3));
606 template<
class A1,
class A2,
class A3,
class A4>
607 pointer EmplaceBack(
const A1& a1,
const A2& a2,
const A3& a3,
const A4& a4) {
608 void* p = this->PushBack();
609 if (!p)
return nullptr;
610 pointer ptr =
new (p) T(
const_cast<typename RemoveConst<A1>::type&
>(a1),
611 const_cast<typename RemoveConst<A2>::type&
>(a2),
612 const_cast<typename RemoveConst<A3>::type&
>(a3),
613 const_cast<typename RemoveConst<A4>::type&
>(a4));
617 template<
class A1,
class A2,
class A3,
class A4,
class A5>
618 pointer EmplaceBack(
const A1& a1,
const A2& a2,
const A3& a3,
const A4& a4,
const A5& a5) {
619 void* p = this->PushBack();
620 if (!p)
return nullptr;
621 pointer ptr =
new (p) T(
const_cast<typename RemoveConst<A1>::type&
>(a1),
622 const_cast<typename RemoveConst<A2>::type&
>(a2),
623 const_cast<typename RemoveConst<A3>::type&
>(a3),
624 const_cast<typename RemoveConst<A4>::type&
>(a4),
625 const_cast<typename RemoveConst<A5>::type&
>(a5));
641 void DestroyBlk(Blk*,
size_t, TrueType)
const NLIB_NOEXCEPT {}
642 void DestroyBlk(Blk* p,
size_t n, FalseType)
const NLIB_NOEXCEPT;
644 DestroyBlk(p, n,
typename IsTriviallyDestructible<T>::type());
654 return static_cast<T*
>(p);
656 T* MyCtor(
void* p, FalseType) {
662 if (!ConfirmBack())
return false;
664 reference item = GetItem(curblk_)[--curidx_];
671 if (!ConfirmBack())
return false;
681 template<
class T,
class AL>
684 this->DeallocBlkList(firstblk_, 0);
689 template<
class T,
class AL>
690 class ResizeRewinder {
693 void PushBack(
size_t n) {
694 for (; count_ < n; ++count_) {
700 for (; count_ > 0; --count_) {
713 template<
class T,
class AL>
714 bool Nlist<T, AL>::Resize(
size_t n, FalseType)
NLIB_NOEXCEPT {
716 size_t sz = this->size();
717 if (n == sz)
return true;
719 for (
size_t i = sz; i > n; --i) {
723 if (!this->reserve(n))
return false;
724 nlist::ResizeRewinder<T, AL> rewinder(*
this);
725 rewinder.PushBack(n);
730 template<
class T,
class AL>
731 bool Nlist<T, AL>::Resize(
size_t n, TrueType)
NLIB_NOEXCEPT {
732 size_type sz = this->size();
733 if (n == sz)
return true;
735 for (size_type i = sz; i > n; --i) {
739 if (!this->reserve(n))
return false;
743 size_t lower = this->BlkBaseIdx(curlevel_);
744 size_t upper = this->BlkBaseIdx(curlevel_ + 1);
746 size_t curmax_idx = BlkSize(curlevel_);
747 void* buf =
reinterpret_cast<nlib_byte_t*
>(curblk_->item) + curidx_ *
sizeof(T);
748 size_t fill_size = (curmax_idx - curidx_) *
sizeof(T);
752 curblk_ = curblk_->next;
754 upper = this->BlkBaseIdx(curlevel_ + 1);
756 size_t old_curidx = curidx_;
757 curidx_ =
static_cast<size_t>(n - lower);
758 void* buf =
reinterpret_cast<nlib_byte_t*
>(curblk_->item) + old_curidx *
sizeof(T);
759 size_t fill_size = (curidx_ - old_curidx) *
sizeof(T);
765 template<
class T,
class AL>
768 if (!firstblk_ && !this->ConfirmFirstBlk())
return false;
769 if (n < BlkBaseIdx(curlevel_ + 1))
return true;
771 Blk* blk = this->LastBlock(&lv);
773 if (n < BlkBaseIdx(lv + 1))
return true;
775 Blk* p = this->AllocBlk(BlkSize(lv));
776 if (!p)
return false;
782 template<
class T,
class AL>
787 size_t sz =
sizeof(Blk) + n *
sizeof(T);
790 pp = AllocType::_GetNlistAlloc().allocate(sz);
792 #ifdef __cpp_exceptions 793 NLIB_CATCH(
const std::bad_alloc&) {
return nullptr; }
795 if (!pp)
return nullptr;
796 Blk* p =
static_cast<Blk*
>(pp);
798 p->item =
reinterpret_cast<T*
>(p + 1);
802 template<
class T,
class AL>
803 void Nlist<T, AL>::DeallocBlkList(Blk* p,
int lv)
const NLIB_NOEXCEPT {
805 size_t n = BlkSize(lv);
810 AllocType::_GetNlistAlloc().deallocate(reinterpret_cast<char*>(pp),
811 sizeof(Blk) + n *
sizeof(T));
816 template<
class T,
class AL>
817 void Nlist<T, AL>::DestroyBlk(Blk* p,
size_t n, FalseType)
const NLIB_NOEXCEPT {
821 T* base =
static_cast<T*
>(p->item);
823 for (
size_t i = 0; i < n; ++i) {
828 template<
class T,
class AL>
830 Blk* p = AllocBlk(BlkSize(0));
831 if (!p)
return false;
839 template<
class T,
class AL>
841 if (!firstblk_ && !ConfirmFirstBlk())
return nullptr;
842 if (curidx_ == BlkSize(curlevel_)) {
843 if (!curblk_->next) {
844 Blk* p = AllocBlk(BlkSize(curlevel_ + 1));
845 if (!p)
return nullptr;
849 curblk_ = curblk_->next;
856 T& item = GetItem(curblk_)[curidx_];
860 template<
class T,
class AL>
865 while (p != curblk_) {
866 size_t cnt = BlkSize(lv);
872 DestroyBlk(p, curidx_);
877 template<
class T,
class AL1,
class AL2>
879 return lhs.size() == rhs.size() && std::equal(lhs.begin(), lhs.end(), rhs.begin());
882 template<
class T,
class AL1,
class AL2>
884 return !(lhs == rhs);
887 template<
class T,
class AL1,
class AL2>
889 return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
892 template<
class T,
class AL1,
class AL2>
897 template<
class T,
class AL1,
class AL2>
899 return (!(rhs < lhs));
902 template<
class T,
class AL1,
class AL2>
904 return (!(lhs < rhs));
907 template<
class AL = std::allocator<
char> >
909 typedef Nlist<char*, AL> ContainerType;
912 typedef AL allocator_type;
913 typedef typename ContainerType::iterator iterator;
914 typedef typename ContainerType::const_iterator const_iterator;
919 size_t capacity() const
NLIB_NOEXCEPT {
return list_.capacity(); }
921 bool reserve(
size_t n) {
return list_.reserve(n); }
922 bool resize(
size_t n) {
return list_.resize(n); }
924 char** push_back(
const char* str);
925 template<
class Iterator>
926 char** push_back(Iterator first, Iterator last);
930 allocator_type get_allocator()
const {
return list_.get_allocator(); }
932 const char* back()
const {
return list_.back(); }
933 char* back() {
return list_.back(); }
934 const char* front()
const {
return list_.front(); }
935 char* front() {
return list_.front(); }
936 const char* operator[](
size_t idx)
const {
return list_[idx]; }
937 char* operator[](
size_t idx) {
return list_[idx]; }
939 const_iterator begin() const
NLIB_NOEXCEPT {
return list_.begin(); }
940 const_iterator cbegin()
NLIB_NOEXCEPT {
return list_.cbegin(); }
943 const_iterator end() const
NLIB_NOEXCEPT {
return list_.end(); }
946 void shrink_to_fit() { list_.shrink_to_fit(); }
949 char** Replace(iterator it,
const char* str);
950 char** Replace(
size_t idx,
const char* str) {
951 if (idx >= list_.size())
return nullptr;
952 iterator it = list_.begin();
954 return this->Replace(it, str);
958 void Dealloc(
const char* ptr)
const {
961 this->get_allocator().deallocate(const_cast<char*>(ptr), 0);
964 char* StrDup(
const char* ptr)
const;
965 char* Alloc(
size_t nbytes)
const {
return this->get_allocator().allocate(nbytes); }
973 char* StringList<AL>::StrDup(
const char* ptr)
const {
975 void* p = this->Alloc(nbytes);
976 if (!p)
return nullptr;
977 nlib_memcpy(p, nbytes, ptr, nbytes);
978 return reinterpret_cast<char*
>(p);
983 const_iterator it = this->cbegin();
984 const_iterator it_end = this->cend();
985 while (it != it_end) {
992 char** StringList<AL>::push_back(
const char* str) {
995 dup = this->StrDup(str);
996 if (!dup)
return nullptr;
1000 char** ptr_str = list_.push_back(dup);
1001 if (!ptr_str) this->Dealloc(dup);
1006 template<
class Iterator>
1007 char** StringList<AL>::push_back(Iterator first, Iterator last) {
1008 typename std::iterator_traits<Iterator>::difference_type n = std::distance(first, last);
1009 char* str = this->Alloc(n + 1);
1010 if (!str)
return nullptr;
1011 std::copy(first, last, str);
1013 char** rval = list_.push_back(str);
1014 if (!rval) this->Dealloc(str);
1020 if (list_.empty())
return false;
1021 Dealloc(list_.back());
1022 return list_.pop_back();
1026 char** StringList<AL>::Replace(iterator it,
const char* str) {
1029 dup = this->StrDup(str);
1030 if (!dup)
return nullptr;
1040 bool AppendString(Nlist<char, AL>* obj,
const char* str) {
1042 if (!obj->reserve(obj->size() + n))
return false;
1044 obj->push_back(*str);
1054 template<
class T,
class Distance>
1055 inline void advance(::nlib_ns::nlist::NlistIterator<T>& pos, Distance n) {
1056 pos.Advance(static_cast<size_t>(n));
1060 inline std::ptrdiff_t distance(const ::nlib_ns::nlist::NlistIterator<T>& first,
1061 const ::nlib_ns::nlist::NlistIterator<T>& last) {
1062 return first.Distance(last);
1067 NLIB_DEFINE_STD_SWAP_T_BEGIN2(
nn, nlib)
1068 NLIB_DEFINE_STD_SWAP_T2(T, AL, NLIB_NS::Nlist)
1069 NLIB_DEFINE_STD_SWAP_T1(AL, NLIB_NS::StringList)
1070 NLIB_DEFINE_STD_SWAP_T_END2(
nn, nlib)
1072 #endif // INCLUDE_NN_NLIB_NLIST_H_ Nlist(const AL &al) noexcept
Specifies an allocator. Creates an empty container.
reference operator[](size_type n)
Gets the nth element. n must be less than the number of stored elements.
BaseType::const_pointer const_pointer
Read-only pointer to an element.
pointer EmplaceBack(Args &&... args)
Adds elements in-place.
reference back()
Gets a reference to the last element.
BaseType::pointer pointer
Pointer to the element.
Substitute definitions for the C++11 standard header type_traits. These substitute definitions are us...
Nlist() noexcept
Instantiates the object with default parameters (default constructor). Creates an empty container...
BaseType::reference reference
A reference to an element.
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
bool operator>=(const Nlist< T, AL1 > &lhs, const Nlist< T, AL2 > &rhs) noexcept
Compares two lists in dictionary order.
const_iterator begin() const noexcept
Gets the read-only iterator pointing to the first element.
BaseType::size_type size_type
Unsigned integer type (size_t).
bool operator>(const Nlist< T, AL1 > &lhs, const Nlist< T, AL2 > &rhs) noexcept
Compares two lists in dictionary order.
iterator begin() noexcept
Gets the iterator pointing to the first element.
void shrink_to_fit() noexcept
Returns allocated memory, if possible.
allocator_type get_allocator() const noexcept
Gets the allocator.
const_reference back() const
The const decoration version of the above function.
const_iterator end() const noexcept
Gets the read-only iterator pointing beyond the last element.
bool operator==(const HeapHash &rhs, const HeapHash &lhs)
Returns true if the two compared summaries are equal.
bool operator!=(const HeapHash &rhs, const HeapHash &lhs)
Returns true if the two compared summaries are not equal.
pointer push_back(T &&rhs) noexcept
Moves a temporary object rhs and adds it to the end.
BaseType::const_iterator const_iterator
Read-only forward iterator.
Nlist & operator=(Nlist &&rhs) noexcept
Move assignment operator.
Object created when MessagePack or JSON is read.
size_type capacity() const noexcept
Returns the number of allocated elements.
bool resize(size_type n) noexcept
Resizes the container.
pointer push_back()
Adds an element to the end and initializes it with the default constructor.
Nlist(Nlist &rhs, move_tag) noexcept
Corresponds to a move constructor.
An empty structure indicating that an argument to a function needs to be moved.
void clear() noexcept
Clears the container.
#define NLIB_CATCH(x)
Defines catch(x) if exceptions are enabled. If not, defines if (true).
#define NLIB_TRY
Defines try if exceptions are enabled. If not, defines if (true).
Nlist & assign(Nlist &rhs, move_tag) noexcept
Corresponds to a move assignment operator.
reference front()
Gets a reference to the first element.
BaseType::iterator iterator
A forward iterator.
const_reference operator[](size_type n) const
The const decoration version of the above function.
BaseType::difference_type difference_type
Signed integer type (ptrdiff_t).
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
BaseType::value_type value_type
Element type T.
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
A file that contains the configuration information for each development environment.
TimeSpan operator*(int i, const TimeSpan &rhs) noexcept
Increases rhs by a factor of i.
pointer push_back(const T &rhs)
Adds rhs to the end.
void Clobber() noexcept
Returns the container empty without calling the element destructor and without releasing the memory f...
A container-like class similar to std::vector that can store objects that do not have copy constructo...
const_reference front() const
The const decoration version of the above function.
const_iterator cend() const noexcept
Gets the read-only iterator pointing beyond the last element.
size_type size() const noexcept
Returns the number of stored elements.
#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.
bool empty() const noexcept
Returns true if the number of stored elements is 0, or returns false otherwise.
#define NLIB_ALIGNOF(tp)
Defines alignof(tp) or the equivalent.
AL allocator_type
Allocator type AL.
BaseType::reference const_reference
Read-only reference to an element.
const_iterator cbegin() const noexcept
Gets the read-only iterator pointing to the first element.
iterator end() noexcept
Gets the iterator pointing beyond the last element.
bool pop_back() noexcept
Deletes the last element.