daily pastebin goal
89%
SHARE
TWEET

Untitled

a guest Jan 21st, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "test_runner.h"
  2.  
  3. #include <numeric>
  4. #include <iostream>
  5. #include <vector>
  6. #include <string>
  7. using namespace std;
  8.  
  9.  
  10. template<typename Iterator>
  11. class IteratorRange {
  12. private:
  13.     Iterator first, last;
  14. public:
  15.     IteratorRange(Iterator f, Iterator l) :
  16.             first(f), last(l) {
  17.     }
  18.     Iterator begin() const {
  19.         return first;
  20.     }
  21.     Iterator end() const {
  22.         return last;
  23.     }
  24.     size_t size() const{
  25.         return last - first;
  26.     }
  27. };
  28.  
  29. template <typename Iterator>
  30. class Paginator {
  31. private:
  32.     vector<IteratorRange<Iterator>> vector_it;
  33.     Iterator first;
  34.     Iterator last;
  35.     size_t page_size;
  36. public:
  37.     Paginator(Iterator f, Iterator l, size_t page_size_) :
  38.         first(f), last(l), page_size(page_size_) {
  39.         while(first != last) {
  40.             auto pr = first;
  41.             for (size_t i = 0; i < page_size; ++i) {
  42.                 first++;
  43.                 if (first == last) {
  44.                     break;
  45.                 }
  46.             }
  47.             vector_it.push_back({pr, first});
  48.         }
  49.     }
  50.     Iterator begin() const {
  51.         return vector_it.begin();
  52.     }
  53.     Iterator end() const {
  54.         return vector_it.end();
  55.     }
  56.     size_t size() const{
  57.         return vector_it.size();
  58.     }
  59.  
  60. };
  61.  
  62. template <typename C>
  63. auto Paginate(C& c, size_t page_size) {
  64.   return Paginator{c.begin(), c.end(), page_size};
  65. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top