逆にvectorをiterableに変換します。
template<typename T> class cIter : public cIterable<T> { const vector<T> v; typename vector<T>::const_iterator current; bool first; public: cIter(const vector<T>& w) : v(w), first(true) { } bool exists_next() { if(first) { current = v.begin(); first = false; } else ++current; return current != v.end(); } T value() const { return *current; } }; template<typename T> shared_ptr<cIterable<T>> iter(const vector<T>& v) { return shared_ptr<cIterable<T>>(new cIter<T>(v)); } int main() { int a[] = { 1, 2, 3 }; vector<int> v(a, a + 3); auto g = iter(v); while(g->exists_next()) cout << g->value(); }
123