Advertisement
Guest User

Untitled

a guest
Apr 17th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. template<typename A>
  2. class Lazy {
  3.     private:
  4.         A thing;
  5.         bool haveThing;
  6.         std::function<A> getTheA;
  7.     template<typename FunctionReturningA>
  8.     public:
  9.         Lazy(FunctionReturningA f) : getTheA(f), haveThing(false) {}
  10.         A *get() {
  11.             if (haveThing) {
  12.                 return &thing;
  13.             } else {
  14.                 thing = getTheA();
  15.                 haveThing = true;
  16.                 return &thing;
  17.             }
  18.         }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement