In Java I can declare a Supplier<Foo> parameter, get the value using s.get(), and create the supplier using () -> someExpression(), so the expression is only evaluated if needed:
static void doSomething(Supplier<Foo> s) {
if (gonnaNeedThatObject) {
Foo foo = s.get();
// do stuff with foo
}
}
...
doSomething(() -> someExpression());
How can I accomplish this in C++? There seems to be a few different ways, but I can't quite figure out the syntax or the benefits and drawbacks of each way.