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
18NEFORCE_BEGIN_NAMESPACE__
19
25
33template <typename T>
34struct list_node {
35 T data;
36 list_node* prev = nullptr;
37 list_node* next = nullptr;
38
46
54 template <typename... Args>
55 explicit list_node(Args&&... args) noexcept(is_nothrow_constructible_v<T, Args...>) :
56 data(_NEFORCE forward<Args>(args)...) {}
57};
58
59
68template <bool IsConst, typename List>
69struct list_iterator : iiterator<list_iterator<IsConst, List>> {
70public:
71 using container_type = List;
72 using value_type = typename container_type::value_type;
73 using size_type = typename container_type::size_type;
74 using difference_type = typename container_type::difference_type;
76 using reference = conditional_t<IsConst, typename container_type::const_reference,
77 typename container_type::reference>;
78 using pointer = conditional_t<IsConst, typename container_type::const_pointer,
79 typename container_type::pointer>;
80
81private:
82 using node_type = list_node<value_type>;
83
84 node_type* current_ = nullptr;
85 const container_type* container_ = nullptr;
86
87public:
88 list_iterator() noexcept = default;
89 ~list_iterator() = default;
90
91 list_iterator(const list_iterator&) noexcept = default;
92 list_iterator& operator=(const list_iterator&) noexcept = default;
93 list_iterator(list_iterator&&) noexcept = default;
94 list_iterator& operator=(list_iterator&&) noexcept = default;
95
101 list_iterator(node_type* ptr, const container_type* list) noexcept :
102 current_(ptr),
103 container_(list) {}
104
109 NEFORCE_NODISCARD reference dereference() const noexcept {
110 NEFORCE_DEBUG_VERIFY(current_ && container_, "Attempting to dereference on a null pointer");
111 NEFORCE_DEBUG_VERIFY(current_ != container_->head_, "Attempting to dereference out of boundary");
112 return current_->data;
113 }
114
118 void increment() noexcept {
119 NEFORCE_DEBUG_VERIFY(current_ && container_, "Attempting to increment a null pointer");
120 NEFORCE_DEBUG_VERIFY(current_ != container_->head_, "Attempting to increment out of boundary");
121 current_ = current_->next;
122 }
123
127 void decrement() noexcept {
128 NEFORCE_DEBUG_VERIFY(current_ && container_, "Attempting to decrement a null pointer");
129 NEFORCE_DEBUG_VERIFY(current_->prev != container_->head_, "Attempting to decrement out of boundary");
130 current_ = current_->prev;
131 }
132
138 NEFORCE_NODISCARD difference_type distance_to(const list_iterator& other) const noexcept {
139 NEFORCE_DEBUG_VERIFY(container_ == other.container_,
140 "Attempting distance_to on iterators from different containers");
141 difference_type dist = 0;
142 const node_type* p = current_;
143 while (p != other.current_) {
144 NEFORCE_DEBUG_VERIFY(p != container_->head_, "Attempting distance_to past end iterator");
145 p = p->next;
146 ++dist;
147 }
148 return dist;
149 }
150
156 NEFORCE_NODISCARD bool equal_to(const list_iterator& rhs) const noexcept {
157 NEFORCE_DEBUG_VERIFY(container_ == rhs.container_, "Attempting to equal to a different container");
158 return current_ == rhs.current_;
159 }
160
165 NEFORCE_NODISCARD node_type* base() const noexcept { return current_; }
166
171 NEFORCE_NODISCARD const container_type* container() const noexcept { return container_; }
172};
173
174
184template <typename T, typename Alloc = allocator<list_node<T>>>
185class list : public icollector<list<T, Alloc>> {
186 static_assert(is_allocator_v<Alloc>, "Alloc type is not a standard allocator type.");
187 static_assert(is_same_v<list_node<T>, typename Alloc::value_type>, "allocator type mismatch.");
188 static_assert(is_object_v<T>, "list only contains object types.");
189
190public:
191 using pointer = T*;
192 using reference = T&;
193 using const_pointer = const T*;
194 using const_reference = const T&;
195 using value_type = T;
198 using iterator = list_iterator<false, list>;
199 using const_iterator = list_iterator<true, list>;
202 using allocator_type = Alloc;
203
204private:
205 using node_type = list_node<T>;
206 using link_type = node_type*;
207
208 link_type head_ = nullptr;
210
211 template <bool, typename>
212 friend struct list_iterator;
213
214private:
223 template <typename... Args>
224 link_type create_node(Args&&... args) {
225 link_type p = pair_.get_base().allocate();
226 try {
227 _NEFORCE construct(&p->data, _NEFORCE forward<Args>(args)...);
228 } catch (...) {
229 pair_.get_base().deallocate(p);
230 throw;
231 }
232 return p;
233 }
234
241 void destroy_node(link_type p) noexcept(is_nothrow_destructible_v<node_type>) {
242 _NEFORCE destroy(p);
243 pair_.get_base().deallocate(p);
244 }
245
251 void init_header() {
252 head_ = pair_.get_base().allocate();
253 try {
254 _NEFORCE construct(head_);
255 } catch (...) {
256 pair_.get_base().deallocate(head_);
257 throw;
258 }
259 head_->prev = head_->next = head_;
260 }
261
262public:
268 list() { list::init_header(); }
269
274 explicit list(size_type n) :
275 list(n, _NEFORCE initialize<T>()) {}
276
282 list(size_type n, const T& value) {
283 list::init_header();
284 try {
285 while ((n--) != 0U) {
286 emplace_back(value);
287 }
288 } catch (...) {
289 clear();
290 throw;
291 }
292 }
293
300 template <typename Iterator, enable_if_t<is_iter_v<Iterator>, int> = 0>
301 list(Iterator first, Iterator last) {
302 list::init_header();
303 try {
304 while (first != last) {
305 emplace_back(*first);
306 ++first;
307 }
308 } catch (...) {
309 clear();
310 throw;
311 }
312 }
313
318 list(std::initializer_list<T> ilist) :
319 list(ilist.begin(), ilist.end()) {}
320
326 list& operator=(std::initializer_list<T> ilist) {
327 clear();
328 list::insert(begin(), ilist.begin(), ilist.end());
329 return *this;
330 }
331
336 list(const list& other) :
337 list(other.begin(), other.end()) {}
338
344 list& operator=(const list& other) {
345 if (_NEFORCE addressof(other) == this) {
346 return *this;
347 }
348 list tmp(other);
349 list::swap(tmp);
350 return *this;
351 }
352
358 init_header();
359 list::swap(other);
360 }
361
369 if (_NEFORCE addressof(other) == this) {
370 return *this;
371 }
372 clear();
373 list::swap(other);
374 return *this;
375 }
376
383 link_type p = head_->next;
384 while (p != head_) {
385 link_type q = p;
386 p = p->next;
387 list::destroy_node(q);
388 }
389 list::destroy_node(head_);
390 }
391
396 NEFORCE_NODISCARD iterator begin() noexcept { return iterator{head_->next, this}; }
397
402 NEFORCE_NODISCARD iterator end() noexcept { return iterator{head_, this}; }
403
408 NEFORCE_NODISCARD const_iterator begin() const noexcept { return cbegin(); }
409
414 NEFORCE_NODISCARD const_iterator end() const noexcept { return cend(); }
415
420 NEFORCE_NODISCARD reverse_iterator rbegin() noexcept { return reverse_iterator(end()); }
421
426 NEFORCE_NODISCARD reverse_iterator rend() noexcept { return reverse_iterator(begin()); }
427
432 NEFORCE_NODISCARD const_reverse_iterator rbegin() const noexcept { return crbegin(); }
433
438 NEFORCE_NODISCARD const_reverse_iterator rend() const noexcept { return crend(); }
439
444 NEFORCE_NODISCARD const_iterator cbegin() const noexcept { return const_iterator{head_->next, this}; }
445
450 NEFORCE_NODISCARD const_iterator cend() const noexcept { return const_iterator{head_, this}; }
451
456 NEFORCE_NODISCARD const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(cend()); }
457
462 NEFORCE_NODISCARD const_reverse_iterator crend() const noexcept { return const_reverse_iterator(cbegin()); }
463
468 NEFORCE_NODISCARD size_type size() const noexcept { return pair_.value; }
469
474 NEFORCE_NODISCARD size_type max_size() const noexcept { return static_cast<size_type>(-1); }
475
480 NEFORCE_NODISCARD bool empty() const noexcept { return head_->next == head_; }
481
486 NEFORCE_NODISCARD reference front() noexcept {
487 NEFORCE_DEBUG_VERIFY(!empty(), "front called on empty list");
488 return head_->next->data;
489 }
490
495 NEFORCE_NODISCARD const_reference front() const noexcept {
496 NEFORCE_DEBUG_VERIFY(!empty(), "front called on empty list");
497 return head_->next->data;
498 }
499
504 NEFORCE_NODISCARD reference back() noexcept {
505 NEFORCE_DEBUG_VERIFY(!empty(), "back called on empty list");
506 return head_->prev->data;
507 }
508
513 NEFORCE_NODISCARD const_reference back() const noexcept {
514 NEFORCE_DEBUG_VERIFY(!empty(), "back called on empty list");
515 return head_->prev->data;
516 }
517
525 template <typename... Args>
526 iterator emplace(iterator position, Args&&... args) {
527 link_type temp = list::create_node(_NEFORCE forward<Args>(args)...);
528 temp->next = position.base();
529 temp->prev = position.base()->prev;
530 position.base()->prev->next = temp;
531 position.base()->prev = temp;
532 ++pair_.value;
533 return {temp, this};
534 }
535
542 template <typename... Args>
543 iterator emplace_back(Args&&... args) {
544 return list::emplace(end(), _NEFORCE forward<Args>(args)...);
545 }
546
553 template <typename... Args>
554 iterator emplace_front(Args&&... args) {
555 return list::emplace(begin(), _NEFORCE forward<Args>(args)...);
556 }
557
562 void push_front(const T& value) { list::insert(begin(), value); }
563
568 void push_front(T&& value) { list::insert(begin(), _NEFORCE forward<T>(value)); }
569
574 void push_back(const T& value) { list::insert(end(), value); }
575
580 void push_back(T&& value) { list::insert(end(), _NEFORCE forward<T>(value)); }
581
585 void pop_front() noexcept { list::erase(begin()); }
586
590 void pop_back() noexcept { list::erase({head_->prev, this}); }
591
597 void assign(const size_type n, const T& value) {
598 clear();
599 list::insert(begin(), n, value);
600 }
601
608 template <typename Iterator, enable_if_t<is_iter_v<Iterator>, int> = 0>
609 void assign(Iterator first, Iterator last) {
610 clear();
611 list::insert(begin(), first, last);
612 }
613
618 void assign(std::initializer_list<T> ilist) { list::assign(ilist.begin(), ilist.end()); }
619
626 iterator insert(iterator position, const T& value) { return list::emplace(position, value); }
627
634 iterator insert(iterator position, T&& value) { return list::emplace(position, _NEFORCE move(value)); }
635
646 template <typename Iterator, enable_if_t<is_iter_v<Iterator>, int> = 0>
647 void insert(iterator position, Iterator first, Iterator last) {
648 if (first == last) {
649 return;
650 }
651
652 link_type original_prev = position.base()->prev;
653 link_type current_prev = original_prev;
654 link_type first_inserted = nullptr;
655
656 try {
657 while (first != last) {
658 link_type temp = list::create_node(*first);
659 temp->prev = current_prev;
660 temp->next = position.base();
661 current_prev->next = temp;
662 position.base()->prev = temp;
663 if (first_inserted == nullptr) {
664 first_inserted = temp;
665 }
666 current_prev = temp;
667 ++pair_.value;
668 ++first;
669 }
670 } catch (...) {
671 if (first_inserted != nullptr) {
672 link_type to_delete = first_inserted;
673 while (to_delete != position.base()) {
674 link_type next = to_delete->next;
675 list::destroy_node(to_delete);
676 --pair_.value;
677 to_delete = next;
678 }
679 original_prev->next = position.base();
680 position.base()->prev = original_prev;
681 }
682 throw;
683 }
684 }
685
691 void insert(iterator position, std::initializer_list<T> ilist) {
692 list::insert(position, ilist.begin(), ilist.end());
693 }
694
703 void insert(iterator position, size_type n, const T& value) {
704 if (n == 0) {
705 return;
706 }
707
708 link_type original_prev = position.base()->prev;
709 link_type current_prev = original_prev;
710 link_type first_inserted = nullptr;
711
712 try {
713 while ((n--) != 0U) {
714 link_type temp = list::create_node(value);
715 temp->prev = current_prev;
716 temp->next = position.base();
717 current_prev->next = temp;
718 position.base()->prev = temp;
719 if (first_inserted == nullptr) {
720 first_inserted = temp;
721 }
722 current_prev = temp;
723 ++pair_.value;
724 }
725 } catch (...) {
726 if (first_inserted != nullptr) {
727 link_type to_delete = first_inserted;
728 while (to_delete != position.base()) {
729 link_type next = to_delete->next;
730 list::destroy_node(to_delete);
731 --pair_.value;
732 to_delete = next;
733 }
734 original_prev->next = position.base();
735 position.base()->prev = original_prev;
736 }
737 throw;
738 }
739 }
740
747 if (empty()) {
748 return end();
749 }
750 link_type ret = position.base()->next;
751 position.base()->prev->next = position.base()->next;
752 position.base()->next->prev = position.base()->prev;
753 list::destroy_node(position.base());
754 --pair_.value;
755 return iterator{ret, this};
756 }
757
765 while (first != last) {
766 first = list::erase(first);
767 }
768 return first;
769 }
770
776 void clear() noexcept(is_nothrow_destructible_v<node_type>) {
777 link_type cur = head_->next;
778 while (cur != head_) {
779 link_type temp = cur;
780 cur = cur->next;
781 list::destroy_node(temp);
782 --pair_.value;
783 }
784 head_->prev = head_;
785 head_->next = head_;
786 }
787
793 _NEFORCE swap(head_, other.head_);
794 _NEFORCE swap(pair_, other.pair_);
795 }
796
806 void transfer(iterator position, iterator first, iterator last) {
807 if (position.base() == last.base()) {
808 return;
809 }
810 last.base()->prev->next = position.base();
811 first.base()->prev->next = last.base();
812 position.base()->prev->next = first.base();
813 link_type tmp = position.base()->prev;
814 position.base()->prev = last.base()->prev;
815 last.base()->prev = first.base()->prev;
816 first.base()->prev = tmp;
817 }
818
824 template <typename Pred>
825 void remove_if(Pred pred) {
826 iterator iter = begin(), last = end();
827 while (iter != last) {
828 if (pred(*iter)) {
829 iter = list::erase(iter);
830 } else {
831 ++iter;
832 }
833 }
834 }
835
840 void remove(const T& value) {
841 return list::remove_if([&](const T& other) -> bool { return other == value; });
842 }
843
851 void splice(iterator position, list& other) {
852 if (!other.empty()) {
853 size_type n = other.pair_.value;
854 list::transfer(position, other.begin(), other.end());
855 pair_.value += n;
856 other.pair_.value = 0;
857 }
858 }
859
868 void splice(iterator position, list& other, iterator iter) {
869 iterator j = iter;
870 ++j;
871 if (iter.base() == position.base() || j.base() == position.base()) {
872 return;
873 }
874 list::transfer(position, iter, j);
875 ++pair_.value;
876 --other.pair_.value;
877 }
878
888 void splice(iterator position, list& other, iterator first, iterator last) {
889 if (first == last) {
890 return;
891 }
892 size_type n = 0;
893 for (iterator it = first; it != last; ++it) {
894 ++n;
895 }
896 list::transfer(position, first, last);
897 pair_.value += n;
898 other.pair_.value -= n;
899 }
900
910 template <typename Pred>
911 void merge_if(list& other, Pred pred) {
912 iterator first1 = begin(), first2 = other.begin();
913 iterator last1 = end(), last2 = other.end();
914
915 while (first1 != last1 && first2 != last2) {
916 if (!pred(*first2, *first1)) {
917 ++first1;
918 } else {
919 iterator temp = first2;
920 ++temp;
921 list::transfer(first1, first2, temp);
922 first2 = temp;
923 ++pair_.value;
924 --other.pair_.value;
925 }
926 }
927
928 if (first2 != last2) {
929 size_type n = other.pair_.value;
930 list::transfer(last1, first2, last2);
931 pair_.value += n;
932 other.pair_.value = 0;
933 }
934 }
935
940 void merge(list& other) { list::merge_if(other, _NEFORCE less<T>()); }
941
945 void reverse() noexcept {
946 if (empty()) {
947 return;
948 }
949 link_type current = head_;
950 do {
951 _NEFORCE swap(current->prev, current->next);
952 current = current->prev;
953 } while (current != head_);
954 }
955
963 template <typename Pred>
964 void unique_if(Pred pred) noexcept {
965 if (empty()) {
966 return;
967 }
968 iterator current = begin();
969 iterator next = current;
970 while (++next != end()) {
971 if (pred(*current, *next)) {
973 next = current;
974 } else {
975 current = next;
976 }
977 }
978 }
979
983 void unique() noexcept { list::unique_if(_NEFORCE equal_to<T>()); }
984
992 template <typename Pred>
993 void sort_if(Pred pred) {
994 if (empty()) {
995 return;
996 }
997 link_type p = head_->next->next;
998 while (p != head_) {
999 T temp = p->data;
1000 link_type prev = p->prev;
1001 while (prev != head_ && pred(temp, prev->data)) {
1002 prev->next->data = prev->data;
1003 prev = prev->prev;
1004 }
1005 prev->next->data = temp;
1006 p = p->next;
1007 }
1008 }
1009
1013 void sort() { list::sort_if(_NEFORCE less<T>()); }
1014
1020 NEFORCE_NODISCARD const_reference at(size_type position) const {
1021 const_iterator iter = cbegin();
1022 while ((position--) != 0U) {
1023 ++iter;
1024 }
1025 return iter.base()->data;
1026 }
1027
1033 NEFORCE_NODISCARD reference at(size_type position) {
1034 const_iterator iter = cbegin();
1035 while ((position--) != 0U) {
1036 ++iter;
1037 }
1038 return iter.base()->data;
1039 }
1040
1046 NEFORCE_NODISCARD const_reference operator[](const size_type position) const { return at(position); }
1047
1053 NEFORCE_NODISCARD reference operator[](const size_type position) { return at(position); }
1054
1060 NEFORCE_NODISCARD bool equal_to(const list& rhs) const
1061 noexcept(noexcept(_NEFORCE equal(cbegin(), cend(), rhs.cbegin()))) {
1062 return size() == rhs.size() && _NEFORCE equal(cbegin(), cend(), rhs.cbegin());
1063 }
1064
1070 NEFORCE_NODISCARD bool less_than(const list& rhs) const
1071 noexcept(noexcept(_NEFORCE lexicographical_compare(cbegin(), cend(), rhs.cbegin(), rhs.cend()))) {
1072 return _NEFORCE lexicographical_compare(cbegin(), cend(), rhs.cbegin(), rhs.cend());
1073 }
1074};
1075
1076#ifdef NEFORCE_STANDARD_17
1077template <typename Iterator, typename Alloc>
1078list(Iterator, Iterator, Alloc = Alloc()) -> list<iter_value_t<Iterator>, Alloc>;
1079#endif
1080 // Container
1082
1083NEFORCE_END_NAMESPACE__
1084#endif // NEFORCE_CORE_CONTAINER_LIST_HPP__
双向链表容器
const_iterator cbegin() const noexcept
获取常量起始迭代器
const_reference operator[](const size_type position) const
常量下标访问操作符
void assign(Iterator first, Iterator last)
范围赋值
bool empty() const noexcept
检查是否为空
const_reference back() 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)
在指定位置移动插入元素
const_iterator cend() const noexcept
获取常量结束迭代器
const_reverse_iterator rbegin() 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)
初始化列表构造函数
iterator begin() noexcept
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)
传输元素
iterator emplace_front(Args &&... args)
在开头构造元素
iterator end() noexcept
list()
默认构造函数
const_iterator begin() const noexcept
获取常量起始迭代器
iterator emplace_back(Args &&... args)
在末尾构造元素
reverse_iterator rend() noexcept
获取反向结束迭代器
void push_front(const T &value)
在开头拷贝插入元素
void sort()
对链表进行排序(默认使用小于比较)
void merge(list &other)
合并两个有序链表(默认使用小于比较)
const_iterator end() const noexcept
获取常量结束迭代器
void unique_if(Pred pred) noexcept
移除连续的重复元素
void sort_if(Pred pred)
对链表进行排序
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)
在末尾移动插入元素
size_type max_size() const noexcept
获取最大可能大小
void pop_back() noexcept
移除末尾元素
void insert(iterator position, std::initializer_list< T > ilist)
初始化列表插入
void unique() noexcept
移除连续的重复元素(默认使用等于比较)
list(Iterator first, Iterator last)
范围构造函数
void push_back(const T &value)
在末尾拷贝插入元素
const_reverse_iterator rend() const noexcept
获取常量反向结束迭代器
bool less_than(const list &rhs) const noexcept(noexcept(_NEFORCE lexicographical_compare(cbegin(), cend(), rhs.cbegin(), rhs.cend())))
小于比较操作符
list(size_type n, const T &value)
构造包含n个指定值元素的链表
void assign(std::initializer_list< T > ilist)
初始化列表赋值
reference operator[](const size_type position)
下标访问操作符
reference at(size_type position)
索引访问
list & operator=(const list &other)
拷贝赋值运算符
void remove_if(Pred pred)
根据谓词移除元素
reference front() noexcept
访问第一个元素
list_iterator< true, list > const_iterator
常量迭代器类型
size_t size_type
大小类型
reverse_iterator rbegin() noexcept
获取反向起始迭代器
const_reference front() 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 >)
删除指定范围内的元素
Alloc allocator_type
分配器类型
reference back() noexcept
访问最后一个元素
T value_type
值类型
void splice(iterator position, list &other, iterator iter)
拼接单个元素
void splice(iterator position, list &other)
拼接整个链表
const T * const_pointer
常量指针类型
list_iterator< false, list > iterator
迭代器类型
T * pointer
指针类型
void remove(const T &value)
移除指定值的元素
iterator erase(iterator position) noexcept(is_nothrow_destructible_v< node_type >)
删除指定位置的元素
void assign(const size_type n, const T &value)
赋值n个指定值的元素
const_reverse_iterator crend() const noexcept
获取常量反向结束迭代器
const_reverse_iterator crbegin() const noexcept
获取常量反向起始迭代器
iterator emplace(iterator position, Args &&... args)
在指定位置构造元素
const T & const_reference
常量引用类型
bool equal_to(const list &rhs) const noexcept(noexcept(_NEFORCE equal(cbegin(), cend(), rhs.cbegin())))
_NEFORCE reverse_iterator< iterator > reverse_iterator
反向迭代器类型
void merge_if(list &other, Pred pred)
合并两个有序链表
const_reference at(size_type position) const
常量索引访问
size_type size() const noexcept
获取当前元素数量
void clear() noexcept(is_nothrow_destructible_v< node_type >)
清空链表
list(size_type n)
构造包含n个默认构造元素的链表
比较算法
压缩对实现
内存构造和销毁函数
constexpr T && forward(remove_reference_t< T > &x) noexcept
完美转发左值
constexpr T * addressof(T &x) noexcept
获取对象的地址
constexpr bool is_object_v
is_object的便捷变量模板
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))
字典序比较两个范围
constexpr bool equal(Iterator1 first1, Iterator1 last1, Iterator2 first2, BinaryPredicate binary_pred) noexcept(noexcept(++first1) &&noexcept(++first2) &&noexcept(binary_pred(*first1, *first2)))
比较两个范围是否相等
constexpr void destroy(T *pointer) noexcept(is_nothrow_destructible_v< T >)
销毁单个对象
constexpr T * construct(T *ptr, Args &&... args) noexcept(is_nothrow_constructible_v< T, Args... >)
在指定内存位置构造对象
constexpr Iterator next(Iterator iter, iter_difference_t< Iterator > n=1)
获取迭代器的后一个位置
constexpr Iterator prev(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重载
constexpr bool is_nothrow_swappable_v
is_nothrow_swappable的便捷变量模板
constexpr bool is_allocator_v
is_allocator的便捷变量模板
constexpr T initialize() noexcept(is_nothrow_default_constructible< T >::value)
返回类型T的默认初始化值
constexpr bool is_nothrow_default_constructible_v
is_nothrow_default_constructible的便捷变量模板
constexpr bool is_nothrow_constructible_v
is_nothrow_constructible的便捷变量模板
constexpr bool is_nothrow_destructible_v
is_nothrow_destructible的便捷变量模板
typename conditional< Test, T1, T2 >::type conditional_t
conditional的便捷别名
constexpr bool is_same_v
is_same的便捷变量模板
集合器接口
迭代器接口
标准分配器
双向迭代器标签
压缩对主模板,使用EBCO优化
constexpr compressed_pair & get_base() &noexcept
获取基类引用
默认构造标签
集合器接口模板
迭代器接口模板
小于比较仿函数
链表迭代器
void decrement() noexcept
递减操作
reference dereference() const noexcept
解引用操作实现
void increment() noexcept
递增操作
node_type * base() 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
引用类型
typename container_type::value_type value_type
值类型
bidirectional_iterator_tag iterator_category
迭代器类别
typename container_type::difference_type difference_type
差值类型
bool equal_to(const list_iterator &rhs) const noexcept
相等比较
typename container_type::size_type size_type
大小类型
const container_type * container() const noexcept
获取关联容器
difference_type distance_to(const list_iterator &other) const noexcept
计算当前迭代器到另一个迭代器的距离
链表节点结构
list_node() noexcept(is_nothrow_default_constructible_v< T >)
默认构造函数
list_node(Args &&... args) noexcept(is_nothrow_constructible_v< T, Args... >)
参数构造