We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
lazy
1 parent 1b4de42 commit 0ac36d2Copy full SHA for 0ac36d2
src/util/lazy.h
@@ -43,4 +43,12 @@ class lazyt
43
}
44
};
45
46
+/// Delay the computation of \p fun to the next time the \c force method
47
+/// is called.
48
+template <typename funt>
49
+auto lazy(funt fun) -> lazyt<decltype(fun())>
50
+{
51
+ return lazyt<decltype(fun())>::from_fun(std::move(fun));
52
+}
53
+
54
#endif // CPROVER_UTIL_LAZY_H
unit/util/lazy.cpp
@@ -16,8 +16,8 @@ SCENARIO("lazy test", "[core][util][lazy]")
16
++call_counter;
17
return s.length();
18
19
- auto lazy_length =
20
- lazyt<int>::from_fun([&]() { return length_with_counter("foo"); });
+ lazyt<std::size_t> lazy_length =
+ lazy([&] { return length_with_counter("foo"); });
21
22
REQUIRE(call_counter == 0);
23
auto result = lazy_length.force();
0 commit comments