CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
lazy.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Util
4
5Author: Romain Brenguier, romain.brenguier@diffblue.com
6
7\*******************************************************************/
8
9#ifndef CPROVER_UTIL_LAZY_H
10#define CPROVER_UTIL_LAZY_H
11
12#include <functional>
13#include <optional>
14
15template <typename valuet>
16class lazyt
17{
18public:
21 static lazyt from_fun(std::function<valuet()> fun)
22 {
23 return lazyt{std::move(fun)};
24 }
25
28 valuet force()
29 {
30 if(value)
31 return *value;
33 return *value;
34 }
35
36private:
37 std::optional<valuet> value;
38 std::function<valuet()> evaluation_function;
39
40 explicit lazyt(std::function<valuet()> fun)
42 {
43 }
44};
45
48template <typename funt>
49auto 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
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
Definition lazy.h:17
std::optional< valuet > value
Definition lazy.h:37
static lazyt from_fun(std::function< valuet()> fun)
Delay the computation of fun to the next time the force method is called.
Definition lazy.h:21
std::function< valuet()> evaluation_function
Definition lazy.h:38
valuet force()
Force the computation of the value.
Definition lazy.h:28
lazyt(std::function< valuet()> fun)
Definition lazy.h:40
auto lazy(funt fun) -> lazyt< decltype(fun())>
Delay the computation of fun to the next time the force method is called.
Definition lazy.h:49
STL namespace.