Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intrusive_slist is not implemented #499

Open
Woazboat opened this issue Dec 13, 2022 · 1 comment
Open

intrusive_slist is not implemented #499

Woazboat opened this issue Dec 13, 2022 · 1 comment

Comments

@Woazboat
Copy link

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
Copy link


#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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants