electronicarts / EASTL

EASTL stands for Electronic Arts Standard Template Library. It is an extensive and robust implementation that has an emphasis on high performance.
BSD 3-Clause "New" or "Revised" License
8.25k stars 941 forks source link

intrusive_slist is not implemented #499

Open Woazboat opened 1 year ago

Woazboat commented 1 year ago

Documentation and header files for intrusive_slist exist, but the implementation is missing. This isn't documented anywhere except in a comment in the (empty) test file for intrusive_slist. Should either be implemented or disabled to prevent it from being used.

ljluestc commented 2 weeks ago

#ifndef EASTL_INTRUSIVE_SLIST_H
#define EASTL_INTRUSIVE_SLIST_H

namespace eastl {

template <typename T>
class intrusive_slist_node {
public:
    T* next = nullptr;
};

template <typename T>
class intrusive_slist {
public:
    using node_type = intrusive_slist_node<T>;
    using value_type = T;

    intrusive_slist() : head_(nullptr) {}

    bool empty() const {
        return head_ == nullptr;
    }

    void push_front(value_type* node) {
        node->next = head_;
        head_ = node;
    }

    value_type* pop_front() {
        if (!head_) return nullptr;
        value_type* node = head_;
        head_ = head_->next;
        return node;
    }

    class iterator {
    public:
        explicit iterator(value_type* node) : node_(node) {}

        iterator& operator++() {
            node_ = node_->next;
            return *this;
        }

        value_type& operator*() const {
            return *node_;
        }

        bool operator!=(const iterator& other) const {
            return node_ != other.node_;
        }

    private:
        value_type* node_;
    };

    iterator begin() { return iterator(head_); }
    iterator end() { return iterator(nullptr); }

private:
    value_type* head_;
};

} // namespace eastl

#endif // EASTL_INTRUSIVE_SLIST_H