Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <functional>
- using namespace std;
- template<class T>
- struct lazy
- {
- lazy() = default;
- using ntype = function<T()> ;
- ntype number;
- lazy(T num) {
- number = [=] ( ) -> T {
- return num;
- };
- }
- lazy operator +(lazy one){
- lazy result;
- result.number = [=] () -> T {
- return one.number() + number();
- };
- return result;
- }
- operator T(){
- return number ();
- }
- };
- using lazy_int = lazy<int>;
- int main(int argc, char *argv[])
- {
- lazy_int a = 7;
- lazy_int b = 3;
- cout << a + b << endl;
- a = a + b;
- cout << a << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement