NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
list.hpp
浏览该文件的文档.
1#ifndef NEFORCE_CORE_CONTAINER_LIST_HPP__
2#define NEFORCE_CORE_CONTAINER_LIST_HPP__
3
11
17NEFORCE_BEGIN_NAMESPACE__
18
24
32template <typename T>
33struct list_node {
34 T data;
35 list_node* prev = nullptr;
36 list_node* next = nullptr;
37
45
53 template <typename... Args>
54 explicit list_node(Args&&... args) noexcept(is_nothrow_constructible_v<T, Args...>) :
55 data(_NEFORCE forward<Args>(args)...) {}
56};
57
58
67template <bool IsConst, typename List>
68struct list_iterator : iiterator<list_iterator<IsConst, List>> {
69public:
70 using container_type = List;
71 using value_type = typename container_type::value_type;
72 using size_type = typename container_type::size_type;
73 using difference_type = typename container_type::difference_type;
75 using reference = conditional_t<IsConst, typename container_type::const_reference,
76 typename container_type::reference>;
77 using pointer = conditional_t<IsConst, typename container_type::const_pointer,
78 typename container_type::pointer>;
79
80private:
81 using node_type = list_node<value_type>;
82
83 node_type* current_ = nullptr;
84 const container_type* container_ = nullptr;
85
86public:
87 list_iterator() noexcept = default;
88 ~list_iterator() = default;
89
90 list_iterator(const list_iterator&) noexcept = default;
91 list_iterator& operator=(const list_iterator&) noexcept = default;
92 list_iterator(list_iterator&&) noexcept = default;
93 list_iterator& operator=(list_iterator&&) noexcept = default;
94
100 list_iterator(node_type* ptr, const container_type* list) noexcept :
101 current_(ptr),
102 container_(list) {}
103
108 NEFORCE_NODISCARD reference dereference() const noexcept {
109 NEFORCE_DEBUG_VERIFY(current_ && container_, "Attempting to dereference on a null pointer");
110 NEFORCE_DEBUG_VERIFY(current_ != container_->head_, "Attempting to dereference out of boundary");
111 return current_->data;
112 }
113
117 void increment() noexcept {
118 NEFORCE_DEBUG_VERIFY(current_ && container_, "Attempting to increment a null pointer");
119 NEFORCE_DEBUG_VERIFY(current_ != container_->head_, "Attempting to increment out of boundary");
120 current_ = current_->next;
121 }
122
126 void decrement() noexcept {
127 NEFORCE_DEBUG_VERIFY(current_ && container_, "Attempting to decrement a null pointer");
128 NEFORCE_DEBUG_VERIFY(current_->prev != container_->head_, "Attempting to decrement out of boundary");
129 current_ = current_->prev;
130 }
131
137 NEFORCE_NODISCARD bool equal(const list_iterator& rhs) const noexcept {
138 NEFORCE_DEBUG_VERIFY(container_ == rhs.container_, "Attempting to equal to a different container");
139 return current_ == rhs.current_;
140 }
141
146 NEFORCE_NODISCARD node_type* base() const noexcept { return current_; }
147
152 NEFORCE_NODISCARD const container_type* container() const noexcept { return container_; }
153};
154
155
165template <typename T, typename Alloc = allocator<list_node<T>>>
166class list : public icollector<list<T, Alloc>> {
167 static_assert(is_allocator_v<Alloc>, "Alloc type is not a standard allocator type.");
168 static_assert(is_same_v<list_node<T>, typename Alloc::value_type>, "allocator type mismatch.");
169 static_assert(is_object_v<T>, "list only contains object types.");
170
171public:
172 using pointer = T*;
173 using reference = T&;
174 using const_pointer = const T*;
175 using const_reference = const T&;
176 using value_type = T;
179 using iterator = list_iterator<false, list>;
180 using const_iterator = list_iterator<true, list>;
183 using allocator_type = Alloc;
184
185private:
186 using node_type = list_node<T>;
187 using link_type = node_type*;
188
189 link_type head_ = nullptr;
191
192 template <bool, typename>
193 friend struct list_iterator;
194
195private:
204 template <typename... Args>
205 link_type create_node(Args&&... args) {
206 link_type p = pair_.get_base().allocate();
207 try {
208 _NEFORCE construct(&p->data, _NEFORCE forward<Args>(args)...);
209 } catch (...) {
210 pair_.get_base().deallocate(p);
211 throw;
212 }
213 return p;
214 }
215
222 void destroy_node(link_type p) noexcept(is_nothrow_destructible_v<node_type>) {
223 _NEFORCE destroy(p);
224 pair_.get_base().deallocate(p);
225 }
226
232 void init_header() {
233 head_ = pair_.get_base().allocate();
234 try {
235 _NEFORCE construct(head_);
236 } catch (...) {
237 pair_.get_base().deallocate(head_);
238 throw;
239 }
240 head_->prev = head_->next = head_;
241 }
242
243public:
249 list() { list::init_header(); }
250
255 explicit list(size_type n) :
256 list(n, _NEFORCE initialize<T>()) {}
257
263 list(size_type n, T&& value) {
264 list::init_header();
265 iterator pos = end();
266 try {
267 while (n--) {
268 pos = list::emplace(pos, _NEFORCE forward<T>(value));
269 }
270 } catch (...) {
271 clear();
272 throw;
273 }
274 }
275
282 template <typename Iterator, enable_if_t<is_iter_v<Iterator>, int> = 0>
283 list(Iterator first, Iterator last) {
284 list::init_header();
285 iterator pos = end();
286 try {
287 while (first != last) {
288 pos = list::emplace(pos, *first);
289 ++first;
290 }
291 } catch (...) {
292 clear();
293 throw;
294 }
295 }
296
301 list(std::initializer_list<T> ilist) :
302 list(ilist.begin(), ilist.end()) {}
303
309 list& operator=(std::initializer_list<T> ilist) {
310 clear();
311 list::insert(begin(), ilist.begin(), ilist.end());
312 return *this;
313 }
314
319 list(const list& other) :
320 list(other.begin(), other.end()) {}
321
327 list& operator=(const list& other) {
328 if (_NEFORCE addressof(other) == this) {
329 return *this;
330 }
331 list tmp(other);
332 list::swap(tmp);
333 return *this;
334 }
335
341 init_header();
342 list::swap(other);
343 }
344
352 if (_NEFORCE addressof(other) == this) {
353 return *this;
354 }
355 clear();
356 list::swap(other);
357 return *this;
358 }
359
366 link_type p = head_->next;
367 while (p != head_) {
368 link_type q = p;
369 p = p->next;
370 list::destroy_node(q);
371 }
372 list::destroy_node(head_);
373 }
374
379 NEFORCE_NODISCARD iterator begin() noexcept { return iterator{head_->next, this}; }
380
385 NEFORCE_NODISCARD iterator end() noexcept { return iterator{head_, this}; }
386
391 NEFORCE_NODISCARD const_iterator begin() const noexcept { return cbegin(); }
392
397 NEFORCE_NODISCARD const_iterator end() const noexcept { return cend(); }
398
403 NEFORCE_NODISCARD reverse_iterator rbegin() noexcept { return reverse_iterator(end()); }
404
409 NEFORCE_NODISCARD reverse_iterator rend() noexcept { return reverse_iterator(begin()); }
410
415 NEFORCE_NODISCARD const_reverse_iterator rbegin() const noexcept { return crbegin(); }
416
421 NEFORCE_NODISCARD const_reverse_iterator rend() const noexcept { return crend(); }
422
427 NEFORCE_NODISCARD const_iterator cbegin() const noexcept { return const_iterator{head_->next, this}; }
428
433 NEFORCE_NODISCARD const_iterator cend() const noexcept { return const_iterator{head_, this}; }
434
439 NEFORCE_NODISCARD const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(cend()); }
440
445 NEFORCE_NODISCARD const_reverse_iterator crend() const noexcept { return const_reverse_iterator(cbegin()); }
446
451 NEFORCE_NODISCARD size_type size() const noexcept { return pair_.value; }
452
457 NEFORCE_NODISCARD size_type max_size() const noexcept { return static_cast<size_type>(-1); }
458
463 NEFORCE_NODISCARD bool empty() const noexcept { return head_->next == head_; }
464
469 NEFORCE_NODISCARD reference front() noexcept {
470 NEFORCE_DEBUG_VERIFY(!empty(), "front called on empty list");
471 return head_->next->data;
472 }
473
478 NEFORCE_NODISCARD const_reference front() const noexcept {
479 NEFORCE_DEBUG_VERIFY(!empty(), "front called on empty list");
480 return head_->next->data;
481 }
482
487 NEFORCE_NODISCARD reference back() noexcept {
488 NEFORCE_DEBUG_VERIFY(!empty(), "back called on empty list");
489 return head_->prev->data;
490 }
491
496 NEFORCE_NODISCARD const_reference back() const noexcept {
497 NEFORCE_DEBUG_VERIFY(!empty(), "back called on empty list");
498 return head_->prev->data;
499 }
500
508 template <typename... Args>
509 iterator emplace(iterator position, Args&&... args) {
510 link_type temp = list::create_node(_NEFORCE forward<Args>(args)...);
511 temp->next = position.base();
512 temp->prev = position.base()->prev;
513 position.base()->prev->next = temp;
514 position.base()->prev = temp;
515 ++pair_.value;
516 return {temp, this};
517 }
518
525 template <typename... Args>
526 iterator emplace_back(Args&&... args) {
527 return list::emplace(end(), _NEFORCE forward<Args>(args)...);
528 }
529
536 template <typename... Args>
537 iterator emplace_front(Args&&... args) {
538 return list::emplace(begin(), _NEFORCE forward<Args>(args)...);
539 }
540
545 void push_front(const T& value) { list::insert(begin(), value); }
546
551 void push_front(T&& value) { list::insert(begin(), _NEFORCE forward<T>(value)); }
552
557 void push_back(const T& value) { list::insert(end(), value); }
558
563 void push_back(T&& value) { list::insert(end(), _NEFORCE forward<T>(value)); }
564
568 void pop_front() noexcept { list::erase(begin()); }
569
573 void pop_back() noexcept { list::erase({head_->prev, this}); }
574
580 void assign(const size_type n, const T& value) {
581 clear();
582 list::insert(begin(), n, value);
583 }
584
591 template <typename Iterator, enable_if_t<is_iter_v<Iterator>, int> = 0>
592 void assign(Iterator first, Iterator last) {
593 clear();
594 list::insert(begin(), first, last);
595 }
596
601 void assign(std::initializer_list<T> ilist) { list::assign(ilist.begin(), ilist.end()); }
602
609 iterator insert(iterator position, const T& value) { return list::emplace(position, value); }
610
617 iterator insert(iterator position, T&& value) { return list::emplace(position, _NEFORCE move(value)); }
618
629 template <typename Iterator, enable_if_t<is_iter_v<Iterator>, int> = 0>
630 void insert(iterator position, Iterator first, Iterator last) {
631 if (first == last) {
632 return;
633 }
634
635 link_type original_prev = position.base()->prev;
636 link_type current_prev = original_prev;
637 link_type first_inserted = nullptr;
638
639 try {
640 while (first != last) {
641 link_type temp = list::create_node(*first);
642 temp->prev = current_prev;
643 temp->next = position.base();
644 current_prev->next = temp;
645 position.base()->prev = temp;
646 if (first_inserted == nullptr) {
647 first_inserted = temp;
648 }
649 current_prev = temp;
650 ++pair_.value;
651 ++first;
652 }
653 } catch (...) {
654 if (first_inserted != nullptr) {
655 link_type to_delete = first_inserted;
656 while (to_delete != position.base()) {
657 link_type next = to_delete->next;
658 list::destroy_node(to_delete);
659 --pair_.value;
660 to_delete = next;
661 }
662 original_prev->next = position.base();
663 position.base()->prev = original_prev;
664 }
665 throw;
666 }
667 }
668
674 void insert(iterator position, std::initializer_list<T> ilist) {
675 list::insert(position, ilist.begin(), ilist.end());
676 }
677
686 void insert(iterator position, size_type n, const T& value) {
687 if (n == 0) {
688 return;
689 }
690
691 link_type original_prev = position.base()->prev;
692 link_type current_prev = original_prev;
693 link_type first_inserted = nullptr;
694
695 try {
696 while (n--) {
697 link_type temp = list::create_node(value);
698 temp->prev = current_prev;
699 temp->next = position.base();
700 current_prev->next = temp;
701 position.base()->prev = temp;
702 if (first_inserted == nullptr) {
703 first_inserted = temp;
704 }
705 current_prev = temp;
706 ++pair_.value;
707 }
708 } catch (...) {
709 if (first_inserted != nullptr) {
710 link_type to_delete = first_inserted;
711 while (to_delete != position.base()) {
712 link_type next = to_delete->next;
713 list::destroy_node(to_delete);
714 --pair_.value;
715 to_delete = next;
716 }
717 original_prev->next = position.base();
718 position.base()->prev = original_prev;
719 }
720 throw;
721 }
722 }
723
730 if (empty()) {
731 return end();
732 }
733 link_type ret = position.base()->next;
734 position.base()->prev->next = position.base()->next;
735 position.base()->next->prev = position.base()->prev;
736 list::destroy_node(position.base());
737 --pair_.value;
738 return iterator{ret, this};
739 }
740
748 while (first != last) {
749 first = list::erase(first);
750 }
751 return first;
752 }
753
759 void clear() noexcept(is_nothrow_destructible_v<node_type>) {
760 link_type cur = head_->next;
761 while (cur != head_) {
762 link_type temp = cur;
763 cur = cur->next;
764 list::destroy_node(temp);
765 --pair_.value;
766 }
767 head_->prev = head_;
768 head_->next = head_;
769 }
770
776 _NEFORCE swap(head_, other.head_);
777 _NEFORCE swap(pair_, other.pair_);
778 }
779
789 void transfer(iterator position, iterator first, iterator last) {
790 if (position == last) {
791 return;
792 }
793 last.base()->prev->next = position.base();
794 first.base()->prev->next = last.base();
795 position.base()->prev->next = first.base();
796 link_type tmp = position.base()->prev;
797 position.base()->prev = last.base()->prev;
798 last.base()->prev = first.base()->prev;
799 first.base()->prev = tmp;
800 }
801
807 template <typename Pred>
808 void remove_if(Pred pred) {
809 iterator iter = begin(), last = end();
810 while (iter != last) {
811 if (pred(*iter)) {
812 iter = list::erase(iter);
813 } else {
814 ++iter;
815 }
816 }
817 }
818
823 void remove(const T& value) {
824 return list::remove_if([&](const T& other) -> bool { return other == value; });
825 }
826
834 void splice(iterator position, list& other) {
835 if (!other.empty()) {
836 size_type n = other.pair_.value;
837 list::transfer(position, other.begin(), other.end());
838 pair_.value += n;
839 other.pair_.value = 0;
840 }
841 }
842
851 void splice(iterator position, list& other, iterator iter) {
852 iterator j = iter;
853 ++j;
854 if (iter == position || j == position) {
855 return;
856 }
857 list::transfer(position, iter, j);
858 ++pair_.value;
859 --other.pair_.value;
860 }
861
871 void splice(iterator position, list& other, iterator first, iterator last) {
872 if (first == last) {
873 return;
874 }
875 size_type n = 0;
876 for (iterator it = first; it != last; ++it) {
877 ++n;
878 }
879 list::transfer(position, first, last);
880 pair_.value += n;
881 other.pair_.value -= n;
882 }
883
893 template <typename Pred>
894 void merge_if(list& other, Pred pred) {
895 iterator first1 = begin(), first2 = other.begin();
896 iterator last1 = end(), last2 = other.end();
897
898 while (first1 != last1 && first2 != last2) {
899 if (!pred(*first2, *first1)) {
900 ++first1;
901 } else {
902 iterator temp = first2;
903 ++temp;
904 list::transfer(first1, first2, temp);
905 first2 = temp;
906 ++pair_.value;
907 --other.pair_.value;
908 }
909 }
910
911 if (first2 != last2) {
912 size_type n = other.pair_.value;
913 list::transfer(last1, first2, last2);
914 pair_.value += n;
915 other.pair_.value = 0;
916 }
917 }
918
923 void merge(list& other) { list::merge_if(other, _NEFORCE less<T>()); }
924
928 void reverse() noexcept {
929 if (empty()) {
930 return;
931 }
932 link_type current = head_;
933 do {
934 _NEFORCE swap(current->prev, current->next);
935 current = current->prev;
936 } while (current != head_);
937 }
938
946 template <typename Pred>
947 void unique_if(Pred pred) noexcept {
948 if (empty()) {
949 return;
950 }
951 iterator current = begin();
952 iterator next = current;
953 while (++next != end()) {
954 if (pred(*current, *next)) {
956 next = current;
957 } else {
958 current = next;
959 }
960 }
961 }
962
966 void unique() noexcept { list::unique_if(_NEFORCE equal_to<T>()); }
967
975 template <typename Pred>
976 void sort_if(Pred pred) {
977 if (empty()) {
978 return;
979 }
980 link_type p = head_->next->next;
981 while (p != head_) {
982 T temp = p->data;
983 link_type prev = p->prev;
984 while (prev != head_ && pred(temp, prev->data)) {
985 prev->next->data = prev->data;
986 prev = prev->prev;
987 }
988 prev->next->data = temp;
989 p = p->next;
990 }
991 }
992
996 void sort() { list::sort_if(_NEFORCE less<T>()); }
997
1003 NEFORCE_NODISCARD const_reference at(size_type position) const {
1004 const_iterator iter = cbegin();
1005 while (position--) {
1006 ++iter;
1007 }
1008 return iter.base()->data;
1009 }
1010
1016 NEFORCE_NODISCARD reference at(size_type position) {
1017 const_iterator iter = cbegin();
1018 while (position--) {
1019 ++iter;
1020 }
1021 return iter.base()->data;
1022 }
1023
1029 NEFORCE_NODISCARD const_reference operator[](const size_type position) const { return at(position); }
1030
1036 NEFORCE_NODISCARD reference operator[](const size_type position) { return at(position); }
1037
1043 NEFORCE_NODISCARD bool operator==(const list& rhs) const
1044 noexcept(noexcept(_NEFORCE equal(cbegin(), cend(), rhs.cbegin()))) {
1045 return size() == rhs.size() && _NEFORCE equal(cbegin(), cend(), rhs.cbegin());
1046 }
1047
1053 NEFORCE_NODISCARD bool operator<(const list& rhs) const
1054 noexcept(noexcept(_NEFORCE lexicographical_compare(cbegin(), cend(), rhs.cbegin(), rhs.cend()))) {
1055 return _NEFORCE lexicographical_compare(cbegin(), cend(), rhs.cbegin(), rhs.cend());
1056 }
1057};
1058
1059#ifdef NEFORCE_STANDARD_17
1060template <typename Iterator, typename Alloc>
1061list(Iterator, Iterator, Alloc = Alloc()) -> list<iter_value_t<Iterator>, Alloc>;
1062#endif
1063 // Container
1065
1066NEFORCE_END_NAMESPACE__
1067#endif // NEFORCE_CORE_CONTAINER_LIST_HPP__
双向链表容器
void assign(Iterator first, Iterator last)
范围赋值
NEFORCE_NODISCARD const_reverse_iterator crend() const noexcept
获取常量反向结束迭代器
void swap(list &other) noexcept(is_nothrow_swappable_v< allocator_type >)
交换两个链表的内容
void push_front(T &&value)
在开头移动插入元素
list & operator=(std::initializer_list< T > ilist)
初始化列表赋值运算符
iterator insert(iterator position, T &&value)
在指定位置移动插入元素
NEFORCE_NODISCARD const_reverse_iterator rend() const noexcept
获取常量反向结束迭代器
~list()
析构函数
void splice(iterator position, list &other, iterator first, iterator last)
拼接范围内的元素
_NEFORCE reverse_iterator< const_iterator > const_reverse_iterator
常量反向迭代器类型
list(std::initializer_list< T > ilist)
初始化列表构造函数
void pop_front() noexcept
移除开头元素
list & operator=(list &&other) noexcept(is_nothrow_swappable_v< compressed_pair< allocator_type, size_type > > &&is_nothrow_destructible_v< node_type >)
移动赋值运算符
void transfer(iterator position, iterator first, iterator last)
传输元素
NEFORCE_NODISCARD const_reference at(size_type position) const
常量索引访问
iterator emplace_front(Args &&... args)
在开头构造元素
list()
默认构造函数
iterator emplace_back(Args &&... args)
在末尾构造元素
void push_front(const T &value)
在开头拷贝插入元素
NEFORCE_NODISCARD reference at(size_type position)
索引访问
void sort()
对链表进行排序(默认使用小于比较)
void merge(list &other)
合并两个有序链表(默认使用小于比较)
void unique_if(Pred pred) noexcept
移除连续的重复元素
void sort_if(Pred pred)
对链表进行排序
NEFORCE_NODISCARD iterator begin() noexcept
void reverse() noexcept
反转链表
list(const list &other)
拷贝构造函数
ptrdiff_t difference_type
差值类型
void insert(iterator position, size_type n, const T &value)
插入n个指定值的元素
void push_back(T &&value)
在末尾移动插入元素
void pop_back() noexcept
移除末尾元素
void insert(iterator position, std::initializer_list< T > ilist)
初始化列表插入
NEFORCE_NODISCARD const_iterator cbegin() const noexcept
获取常量起始迭代器
void unique() noexcept
移除连续的重复元素(默认使用等于比较)
list(Iterator first, Iterator last)
范围构造函数
void push_back(const T &value)
在末尾拷贝插入元素
void assign(std::initializer_list< T > ilist)
初始化列表赋值
NEFORCE_NODISCARD size_type max_size() const noexcept
获取最大可能大小
list & operator=(const list &other)
拷贝赋值运算符
NEFORCE_NODISCARD bool empty() const noexcept
检查是否为空
void remove_if(Pred pred)
根据谓词移除元素
list_iterator< true, list > const_iterator
常量迭代器类型
NEFORCE_NODISCARD reference operator[](const size_type position)
下标访问操作符
size_t size_type
大小类型
NEFORCE_NODISCARD bool operator<(const list &rhs) const noexcept(noexcept(_NEFORCE lexicographical_compare(cbegin(), cend(), rhs.cbegin(), rhs.cend())))
小于比较操作符
NEFORCE_NODISCARD const_iterator end() const noexcept
获取常量结束迭代器
list(list &&other) noexcept(is_nothrow_swappable_v< compressed_pair< allocator_type, size_type > >)
移动构造函数
iterator insert(iterator position, const T &value)
在指定位置拷贝插入元素
T & reference
引用类型
void insert(iterator position, Iterator first, Iterator last)
范围插入
iterator erase(iterator first, iterator last) noexcept(is_nothrow_destructible_v< node_type >)
删除指定范围内的元素
NEFORCE_NODISCARD bool operator==(const list &rhs) const noexcept(noexcept(_NEFORCE equal(cbegin(), cend(), rhs.cbegin())))
相等比较操作符
Alloc allocator_type
分配器类型
T value_type
值类型
void splice(iterator position, list &other, iterator iter)
拼接单个元素
void splice(iterator position, list &other)
拼接整个链表
NEFORCE_NODISCARD const_iterator begin() const noexcept
获取常量起始迭代器
const T * const_pointer
常量指针类型
NEFORCE_NODISCARD iterator end() noexcept
获取结束迭代器
NEFORCE_NODISCARD reverse_iterator rbegin() noexcept
获取反向起始迭代器
NEFORCE_NODISCARD reference front() noexcept
访问第一个元素
list_iterator< false, list > iterator
迭代器类型
NEFORCE_NODISCARD reverse_iterator rend() noexcept
获取反向结束迭代器
T * pointer
指针类型
void remove(const T &value)
移除指定值的元素
list(size_type n, T &&value)
构造包含n个指定值元素的链表
iterator erase(iterator position) noexcept(is_nothrow_destructible_v< node_type >)
删除指定位置的元素
void assign(const size_type n, const T &value)
赋值n个指定值的元素
NEFORCE_NODISCARD const_reverse_iterator crbegin() const noexcept
获取常量反向起始迭代器
NEFORCE_NODISCARD const_reverse_iterator rbegin() const noexcept
获取常量反向起始迭代器
iterator emplace(iterator position, Args &&... args)
在指定位置构造元素
const T & const_reference
常量引用类型
NEFORCE_NODISCARD const_reference front() const noexcept
访问第一个常量元素
NEFORCE_NODISCARD reference back() noexcept
访问最后一个元素
_NEFORCE reverse_iterator< iterator > reverse_iterator
反向迭代器类型
void merge_if(list &other, Pred pred)
合并两个有序链表
void clear() noexcept(is_nothrow_destructible_v< node_type >)
清空链表
list(size_type n)
构造包含n个默认构造元素的链表
NEFORCE_NODISCARD const_reference back() const noexcept
访问最后一个常量元素
NEFORCE_NODISCARD const_reference operator[](const size_type position) const
常量下标访问操作符
NEFORCE_NODISCARD size_type size() const noexcept
获取当前元素数量
NEFORCE_NODISCARD const_iterator cend() const noexcept
获取常量结束迭代器
比较算法
压缩对实现
NEFORCE_NODISCARD constexpr T * addressof(T &x) noexcept
获取对象的地址
NEFORCE_NODISCARD constexpr T && forward(remove_reference_t< T > &x) noexcept
完美转发左值
NEFORCE_INLINE17 constexpr bool is_object_v
is_object的便捷变量模板
NEFORCE_NODISCARD constexpr bool equal(Iterator1 first1, Iterator1 last1, Iterator2 first2, BinaryPredicate binary_pred) noexcept(noexcept(++first1) &&noexcept(++first2) &&noexcept(binary_pred(*first1, *first2)))
比较两个范围是否相等
NEFORCE_NODISCARD constexpr bool lexicographical_compare(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, Compare comp) noexcept(noexcept(++first1) &&noexcept(++first2) &&noexcept(comp(*first1, *first2)) &&noexcept(first1==last1 &&first2 !=last2))
字典序比较两个范围
#define NEFORCE_DEBUG_VERIFY(CON, MESG)
调试模式断言
NEFORCE_CONSTEXPR20 T * construct(T *ptr, Args &&... args) noexcept(is_nothrow_constructible_v< T, Args... >)
在指定内存位置构造对象
NEFORCE_CONSTEXPR20 void destroy(T *pointer) noexcept(is_nothrow_destructible_v< T >)
销毁单个对象
constexpr Iterator prev(Iterator iter, iter_difference_t< Iterator > n=-1)
获取迭代器的前一个位置
constexpr Iterator next(Iterator iter, iter_difference_t< Iterator > n=1)
获取迭代器的后一个位置
uint64_t size_t
无符号大小类型
int64_t ptrdiff_t
指针差类型
constexpr Iterator2 move(Iterator1 first, Iterator1 last, Iterator2 result) noexcept(noexcept(inner::__move_aux(first, last, result)))
移动范围元素
void swap()=delete
删除无参数的swap重载
NEFORCE_INLINE17 constexpr bool is_nothrow_swappable_v
is_nothrow_swappable的便捷变量模板
NEFORCE_INLINE17 constexpr bool is_allocator_v
is_allocator的便捷变量模板
NEFORCE_ALWAYS_INLINE constexpr T initialize() noexcept(is_nothrow_default_constructible< T >::value)
返回类型T的默认初始化值
NEFORCE_INLINE17 constexpr bool is_nothrow_default_constructible_v
is_nothrow_default_constructible的便捷变量模板
NEFORCE_INLINE17 constexpr bool is_nothrow_constructible_v
is_nothrow_constructible的便捷变量模板
NEFORCE_INLINE17 constexpr bool is_nothrow_destructible_v
is_nothrow_destructible的便捷变量模板
NEFORCE_INLINE17 constexpr bool is_same_v
is_same的便捷变量模板
typename conditional< Test, T1, T2 >::type conditional_t
conditional的便捷别名
集合器接口
迭代器接口
标准分配器
双向迭代器标签
压缩对主模板,使用EBCO优化
constexpr compressed_pair & get_base() noexcept
获取基类引用
默认构造标签
相等比较仿函数
集合器接口模板
迭代器接口模板
小于比较仿函数
链表迭代器
void decrement() noexcept
递减操作
NEFORCE_NODISCARD node_type * base() const noexcept
获取底层节点指针
void increment() noexcept
递增操作
NEFORCE_NODISCARD reference dereference() const noexcept
解引用操作实现
NEFORCE_NODISCARD const container_type * container() const noexcept
获取关联容器
List container_type
容器类型
conditional_t< IsConst, typename container_type::const_pointer, typename container_type::pointer > pointer
指针类型
conditional_t< IsConst, typename container_type::const_reference, typename container_type::reference > reference
引用类型
NEFORCE_NODISCARD bool equal(const list_iterator &rhs) const noexcept
相等比较
typename container_type::value_type value_type
值类型
bidirectional_iterator_tag iterator_category
迭代器类别
typename container_type::difference_type difference_type
差值类型
typename container_type::size_type size_type
大小类型
链表节点结构
list_node() noexcept(is_nothrow_default_constructible_v< T >)
默认构造函数
list_node(Args &&... args) noexcept(is_nothrow_constructible_v< T, Args... >)
参数构造