CBMC
lazy.h
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: Util
4
5
Author: 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 <
util/optional.h
>
14
15
template
<
typename
valuet>
16
class
lazyt
17
{
18
public
:
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
;
32
value
=
evaluation_function
();
33
return
*
value
;
34
}
35
36
private
:
37
optionalt<valuet>
value
;
38
std::function<valuet()>
evaluation_function
;
39
40
explicit
lazyt
(std::function<valuet()> fun)
41
:
evaluation_function
(std::move(fun))
42
{
43
}
44
};
45
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
optional.h
lazyt::from_fun
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
lazyt::evaluation_function
std::function< valuet()> evaluation_function
Definition:
lazy.h:38
lazyt::lazyt
lazyt(std::function< valuet()> fun)
Definition:
lazy.h:40
lazy
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
lazyt::force
valuet force()
Force the computation of the value.
Definition:
lazy.h:28
optionalt
nonstd::optional< T > optionalt
Definition:
optional.h:35
lazyt
Definition:
lazy.h:16
lazyt::value
optionalt< valuet > value
Definition:
lazy.h:37
src
util
lazy.h
Generated by
1.8.17