Advertisement
tinyevil

Untitled

Jan 3rd, 2019
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. template<class T>
  2. struct output_span_impl{
  3.     void* ud;
  4.     void (*init)(void*, T** beg, T** mid, T** end);
  5.     void (*write_back)(void*, T* mid);
  6.     void (*grow)(void*, T** beg, T** mid, T** end);
  7. };
  8.  
  9.  
  10. template<class T>
  11. struct output_span{
  12.     output_span(output_span_impl<T> impl):
  13.         impl(impl){
  14.         impl(impl.ud, &beg, &mid, &end);
  15.     }
  16.    
  17.     ~output_span(){
  18.         impl.write_back(impl, mid);
  19.     }
  20.  
  21.     void push_back(T val){
  22.         if (mid == end){
  23.             impl.grow(impl.ud, &beg, &mid, &end);
  24.         }
  25.         *mid = val;
  26.         mid++;
  27.     }
  28.    
  29.     ...
  30.    
  31.     output_span_impl<T> impl;
  32.     T* beg;
  33.     T* mid;
  34.     T* end;
  35. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement