有没有办法遍历不完整的结构

时间:2019-06-18 16:06:52

标签: c++ c++11 incomplete-type

我有这样的代码:

#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_;
};

通过在CPP文件中执行所有特定操作,我能够使其运行。

我的问题是-还有更多“标准”方式来执行此迭代器吗?

更新

我的代码可以编译并运行。

我很想知道std中是否有某些东西可以自动完成所有这些工作,而无需进行太多编码。

1 个答案:

答案 0 :(得分:0)

IMO,此代码有点脱离主题,将错误的事情抽象出来。

您应该宁愿对解复用器引擎接口进行多种实现,一种使用epoll,另一种用于kevent,等等。解复用器引擎接口是允许您为文件描述符注册回调的一种实现。事件,计时器,信号,跨线程等。

在Linux上,除了epoll之外,几乎没有其他用途。

相关问题