-
-
Save rightfold/cf4cbf3e7b2cfc322716 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename F> | |
class lazy { | |
public: | |
explicit lazy(F f) : f(std::move(f)) { } | |
auto const& force() const { | |
if (!x) { | |
x.reset(f()); | |
} | |
return *x; | |
} | |
private: | |
F f; | |
mutable boost::optional<decltype(f())> x; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment