intrusive_list: explicitly default relevant constructors

This commit is contained in:
Lioncash 2016-08-16 23:50:17 -04:00 committed by MerryMage
parent cbd99e4367
commit 9690d1423d

View file

@ -23,7 +23,6 @@ template <typename T> class IntrusiveListConstIterator;
template <typename T> template <typename T>
class IntrusiveListNode { class IntrusiveListNode {
public: public:
IntrusiveListNode() : next(this), prev(this) {}
void UnlinkFromList() { void UnlinkFromList() {
prev->next = next; prev->next = next;
next->prev = prev; next->prev = prev;
@ -31,12 +30,13 @@ public:
next = prev = nullptr; next = prev = nullptr;
#endif #endif
} }
private: private:
friend class IntrusiveList<T>; friend class IntrusiveList<T>;
friend class IntrusiveListIterator<T>; friend class IntrusiveListIterator<T>;
friend class IntrusiveListConstIterator<T>; friend class IntrusiveListConstIterator<T>;
IntrusiveListNode<T>* next; IntrusiveListNode* next = this;
IntrusiveListNode<T>* prev; IntrusiveListNode* prev = this;
}; };
template <typename T> template <typename T>
@ -125,13 +125,11 @@ private:
template <typename T> template <typename T>
class IntrusiveListIterator { class IntrusiveListIterator {
public: public:
IntrusiveListIterator() : root(nullptr), node(nullptr) {} IntrusiveListIterator() = default;
IntrusiveListIterator(IntrusiveList<T>* list, IntrusiveListNode<T>* node) : root(list->root.get()), node(node) {} IntrusiveListIterator(const IntrusiveListIterator& other) = default;
IntrusiveListIterator(const IntrusiveListIterator& other) : root(other.root), node(other.node) {} IntrusiveListIterator& operator=(const IntrusiveListIterator& other) = default;
IntrusiveListIterator& operator=(IntrusiveListIterator other) {
std::swap(root, other.root); IntrusiveListIterator(IntrusiveList<T>* list, IntrusiveListNode<T>* node) : root(list->root.get()), node(node) {
std::swap(node, other.node);
return *this;
} }
IntrusiveListIterator& operator++() { IntrusiveListIterator& operator++() {
@ -180,20 +178,18 @@ public:
private: private:
friend class IntrusiveList<T>; friend class IntrusiveList<T>;
IntrusiveListNode<T>* root; IntrusiveListNode<T>* root = nullptr;
IntrusiveListNode<T>* node; IntrusiveListNode<T>* node = nullptr;
}; };
template <typename T> template <typename T>
class IntrusiveListConstIterator { class IntrusiveListConstIterator {
public: public:
IntrusiveListConstIterator() : root(nullptr), node(nullptr) {} IntrusiveListConstIterator() = default;
IntrusiveListConstIterator(const IntrusiveList<T>* list, IntrusiveListNode<T>* node) : root(list->root.get()), node(node) {} IntrusiveListConstIterator(const IntrusiveListConstIterator& other) = default;
IntrusiveListConstIterator(const IntrusiveListConstIterator& other) : root(other.root), node(other.node) {} IntrusiveListConstIterator& operator=(const IntrusiveListConstIterator& other) = default;
IntrusiveListConstIterator& operator=(IntrusiveListConstIterator other) {
std::swap(root, other.root); IntrusiveListConstIterator(const IntrusiveList<T>* list, IntrusiveListNode<T>* node) : root(list->root.get()), node(node) {
std::swap(node, other.node);
return *this;
} }
IntrusiveListConstIterator& operator++() { IntrusiveListConstIterator& operator++() {
@ -234,8 +230,8 @@ public:
private: private:
friend class IntrusiveList<T>; friend class IntrusiveList<T>;
IntrusiveListNode<T>* root; IntrusiveListNode<T>* root = nullptr;
IntrusiveListNode<T>* node; IntrusiveListNode<T>* node = nullptr;
}; };
template <typename T> template <typename T>