Into the Future!
1 2 3 4 5 6 | // In this example, the thread isn't launched at once... future<int> x(&my_calculating_function, futures::lazy_evaluation); // ... but only when the future is actually used. int y = 3.1415 * x; |
Lazy evaluation can be useful if you’re not too sure whether or not you’ll use the value after all.
Finally, using a future may result in an exception being thrown.
1 2 3 4 5 6 7 | // If the background thread throws an exception, that's // caught, and (if possible) wrapped into a new // futures::exception. future<int> x(&throwing_function); // The new futures::exception would be thrown here. int y = 3.1415 * x; |
And that’s all there is to it. Hope you enjoy the future!
Pages: 1 2

