Introduction

Getting Started

Programming Guides

API Reference

Additional Resources

lazy.h
1 #pragma once
2 
3 #include <functional>
4 
5 template <typename T>
6 class Lazy {
7  Lazy(Lazy const &);
8  void operator= (Lazy const &);
9 
10 public:
11  explicit Lazy(std::function<T()> const & lazyExpr)
12  : lazyExpr(lazyExpr)
13  , boundExpr()
14  , bound(false)
15  {}
16 
17  Lazy(Lazy && other)
18  : lazyExpr(std::move(other.lazyExpr))
19  , boundExpr(std::move(other.boundExpr))
20  , bound(std::move(other.bound))
21  {}
22 
23  void operator= (Lazy && other)
24  {
25  lazyExpr = std::move(other.lazyExpr);
26  boundExpr = std::move(other.boundExpr);
27  bound = std::move(other.bound);
28  }
29 
30  T const & Get() {
31  if (!bound) {
32  boundExpr = lazyExpr();
33  bound = true;
34  }
35  return boundExpr;
36  }
37 
38 private:
39  std::function<T()> lazyExpr;
40  T boundExpr;
41  bool bound;
42 };
43 
44 
Definition: lazy.h:6