Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename A>
- class Lazy {
- private:
- A thing;
- bool haveThing;
- std::function<A> getTheA;
- template<typename FunctionReturningA>
- public:
- Lazy(FunctionReturningA f) : getTheA(f), haveThing(false) {}
- A *get() {
- if (haveThing) {
- return &thing;
- } else {
- thing = getTheA();
- haveThing = true;
- return &thing;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement