SHARE
TWEET

Untitled

a guest Jun 26th, 2019 62 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. template <typename Iter >
  10. class Page {
  11. private:
  12.     Iter first , last;
  13. public:
  14.     Page(Iter f, Iter l) : first(f) , last(l) { }
  15.     Iter begin() const { return first;}
  16.     Iter end() const {return last;}
  17.     size_t size() {return last-first;}
  18. };
  19.  
  20.  
  21. // Реализуйте шаблон класса Paginator
  22.  
  23. template <typename Iterator>
  24. class Paginator {
  25. public:
  26.     Paginator(Iterator begin,Iterator end,size_t page_size){
  27.         if(begin==end){
  28.             _page_count=0;
  29.             _pages.push_back({begin, end});
  30.         }else{
  31.             _page_count=0;
  32.             size_t pagen = end - begin;
  33.             auto begin_p = begin;
  34.             while((end-begin_p)>pagen){
  35.                 _pages.push_back({begin_p,begin_p+4});
  36.                 begin_p+=4;
  37.                 _page_count++;
  38.             }
  39.             _pages.push_back({begin_p,end});
  40.  
  41.         }
  42.     }
  43.  
  44.     size_t size() const{return _page_count;}
  45.  
  46.     auto begin() const { return _pages.begin();}
  47.     auto end() const { return _pages.end();}
  48. private:
  49.     vector<Page<Iterator>> _pages;
  50.     size_t _page_count;
  51.  
  52. };
  53.  
  54. template <typename C>
  55. auto Paginate(C& c, size_t page_size) { return Paginator(c.begin(),c.end(), page_size);}
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