/* */ #ifndef _D_SEQUENCE_H_ #define _D_SEQUENCE_H_ #include namespace aria2 { template class Sequence { public: // Generates value in [_first, _last). _last is not included. class Value { private: T _first; T _last; public: Value(const T& first, const T& last):_first(first), _last(last) {} T next() { return _first++; } bool hasNext() const { return _first != _last; } }; typedef std::vector Values; private: Values _values; typename Values::iterator _cur; public: Sequence(const Values& values): _values(values), _cur(_values.begin()) {} Sequence() {} T next() { if(_cur == _values.end()) { return T(); } T t = (*_cur).next(); if(!(*_cur).hasNext()) { ++_cur; } return t; } bool hasNext() { return _cur != _values.end(); } std::vector flush() { std::vector r; while(hasNext()) { r.push_back(next()); } return r; } }; } // namespace aria2 #endif // _D_SEQUENCE_H_