Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Lazy(T) {
- bool forced = false;
- // Ideally thunk and value would be part of a union
- // but I don't know if that would work with D's GC.
- T function() thunk;
- T value;
- this(T t) { thunk = T function() { return t; }; }
- @property T force() {
- if (!forced) {
- value = thunk();
- // thunk should now be garbage
- thunk = null;
- }
- return value;
- }
- alias force this;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement