#pragma once #include "utils/iterator/range_iterator.hpp" #include "utils/option.hpp" namespace iter { // Class which turns ranged iterator with next() into accessor. // T - type of return value // I - iterator type template class OneTimeAccessor { public: OneTimeAccessor() : it(Option>()) {} OneTimeAccessor(I &&it) : it(RangeIterator(std::move(it))) {} RangeIterator begin() { return it.take(); } RangeIterator end() { return RangeIterator(); } private: Option> it; }; template auto make_one_time_accessor(I &&iter) { // Because function isn't receving or in any way using type T from // OneTimeAccessor compiler can't deduce it thats way there is decltype in // construction of OneTimeAccessor. Resoulting type of iter.next().take() is // T. return OneTimeAccessor(std::move(iter)); } }