Skip to content

Instantly share code, notes, and snippets.

@picanumber
Last active March 20, 2016 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save picanumber/a9bf71975d6d4098b2c2 to your computer and use it in GitHub Desktop.
Save picanumber/a9bf71975d6d4098b2c2 to your computer and use it in GitHub Desktop.
class iterator
{ // Publicly define the standard typedefs
reference _state;
std::size_t _pos;
std::tuple<Ts...>& _nodes;
public:
iterator(reference state, std::size_t pos,
std::tuple<Ts...>& nodes)
: _state(state), _pos(pos), _nodes(nodes)
{}
iterator(const iterator& other)
: _state(other._state)
, _pos(other._pos)
, _nodes(other._nodes)
{}
iterator& operator=(const iterator& other) {
_state = other._state;
_pos = other._pos;
_nodes = other._nodes;
return *this;
}
bool operator==(const iterator& other) const { return _pos == other._pos; }
bool operator<(const iterator& other) const { return _pos < other._pos; }
iterator& operator++() {
++_pos;
_state = vtu::call_with_tuple_element_first(F{}, _nodes,
_pos, _state);
return *this;
}
reference operator*() const { return _state; }
pointer operator->() const { return &_state; }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment