Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2020
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. using namespace std;
  5.  
  6. template<class T>
  7. struct lazy
  8. {
  9.     lazy() = default;
  10.     using ntype = function<T()> ;
  11.     ntype number;
  12.    
  13.     lazy(T num) {
  14.         number = [=] ( ) -> T {
  15.            return num;
  16.         };
  17.     }
  18.    
  19.     lazy operator +(lazy one){
  20.         lazy result;
  21.         result.number = [=] () -> T {
  22.             return one.number() + number();
  23.         };
  24.         return result;
  25.     }
  26.    
  27.     operator T(){
  28.         return number ();
  29.     }
  30. };
  31.  
  32. using lazy_int = lazy<int>;
  33. int main(int argc, char *argv[])
  34. {
  35.     lazy_int a = 7;
  36.     lazy_int b = 3;
  37.     cout << a + b << endl;
  38.     a = a + b;
  39.     cout << a << endl;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement