#pragma once #include #include template class IteratorRange { public: IteratorRange(It b, It e) : begin_(b), end_(e), size_(std::distance(b, e)) {} It begin() const { return begin_; } It end() const { return end_; } size_t size() const { return size_; } private: It begin_, end_; size_t size_; }; template class Slicer { public: Slicer(It begin, It end, int page_size) { It my_it = begin; while (my_it < end) { IteratorRange *new_IR; if (my_it + page_size <= end) { new_IR = new IteratorRange(my_it, my_it + page_size); } else { new_IR = new IteratorRange(my_it, end); } pages_.push_back(*new_IR); my_it += page_size; } } size_t size() const { return pages_.size(); } typename std::vector>::const_iterator begin() const { return pages_.begin(); } typename std::vector>::const_iterator end() const { return pages_.end(); } private: std::vector> pages_; }; template auto Slice(C& c, size_t page_size) { auto* new_slicer = new Slicer(c.begin(), c.end(), page_size); return *new_slicer; }