mardi 18 juin 2019

Is there a way to iterate over incomplete structs

I have code like this:

#include <vector>

struct pollfd; // incomplete struct, since i did not included <poll>

struct Status{
   // abstract representation of pollfd, epoll_event, kevent
   int fd;
   int status; // my own status representation
};

class iterator{
public:
    hidden_pointer_iterator(const pollfd *pos) : pos(pos){}

    bool operator !=(iterator const &other) const{
        return ! ( *this == other);
    }

    bool operator ==(iterator const &other) const;
    iterator &operator ++();
    Status operator *() const;

private:
    const pollfd *pos;
};

class PollSelector{
public:
    // ...
    iterator begin() const; // pull pointer to fds_.data()
    iterator end() const;   // pull pointer to fds_.data() + fds_.size()

private:
    std::vector<pollfd> fds_;
};

I was able to make it run, by implementing all specific operations in the CPP file.

My question is - is there more "standard" way to do this iterator?

Aucun commentaire:

Enregistrer un commentaire