#pragma once #include "utils/iterator/composable.hpp" #include "utils/iterator/iterator_base.hpp" namespace iter { // Class which wraps iterator and hides it's type. It actualy does this by // dynamicly allocating iterator on heap. // T - type of return value template class Virtual : public Composable> { public: Virtual() = delete; // Virtual operation is designed to be used in chained calls which operate // on a // iterator. Virtual will in that usecase receive other iterator by value // and // std::move is a optimization for it. template Virtual(I &&iter) : it(std::make_unique(std::move(iter))) { } Virtual(Virtual &&m) : it(std::move(m.it)) {} ~Virtual() {} Option next() { return it.get()->next(); } Count count() { return it.get()->count(); } private: std::unique_ptr> it; }; template auto make_virtual(I &&iter) { // Compiler cant deduce type T. decltype is here to help with it. return Virtual(std::move(iter)); } }