ARB
Main Page
Namespaces
Classes
Files
File List
File Members
TEMPLATES
lazy.h
Go to the documentation of this file.
1
// ============================================================ //
2
// //
3
// File : lazy.h //
4
// Purpose : helpers for lazy evaluation //
5
// //
6
// Coded by Ralf Westram (coder@reallysoft.de) in July 2017 //
7
// http://www.arb-home.de/ //
8
// //
9
// ============================================================ //
10
11
#ifndef LAZY_H
12
#define LAZY_H
13
14
#ifndef ARB_ASSERT_H
15
#include <
arb_assert.h
>
16
#endif
17
#ifndef _GLIBCXX_CMATH
18
#include <cmath>
19
#endif
20
#ifndef ARBTOOLS_H
21
#include "
arbtools.h
"
22
#endif
23
24
25
template
<
typename
T, T UNDEFINED>
26
class
Lazy
{
32
T
val;
33
public
:
34
Lazy
() : val(UNDEFINED) {}
35
explicit
Lazy
(
T
init
) : val(init) {
arb_assert
(
has_value
()); }
// use to assign new value
36
37
bool
needs_eval
()
const
{
return
val == UNDEFINED; }
38
bool
has_value
()
const
{
return
!
needs_eval
(); }
39
40
operator
T
()
const
{
// @@@ return const&?
41
arb_assert
(
has_value
());
// no value assigned
42
return
val;
43
}
44
const
Lazy
&
operator =
(
const
T
& newval) {
45
val = newval;
46
arb_assert
(
has_value
());
47
return
*
this
;
48
}
49
};
50
51
template
<
typename
T>
52
class
LazyFloat
{
55
T
val;
56
57
public
:
58
LazyFloat
() : val(NAN) {}
59
explicit
LazyFloat
(
T
init
) : val(init) {
arb_assert
(
has_value
()); }
// use to assign new value
60
61
bool
needs_eval
()
const
{
return
is_nan
(val); }
62
bool
has_value
()
const
{
return
!
needs_eval
(); }
63
64
operator
T
()
const
{
// @@@ return const&?
65
arb_assert
(
has_value
());
// no value assigned
66
return
val;
67
}
68
const
LazyFloat
&
operator =
(
const
T
& newval) {
69
val = newval;
70
arb_assert
(
has_value
());
71
return
*
this
;
72
}
73
};
74
75
#else
76
#error lazy.h included twice
77
#endif // LAZY_H
arb_assert
#define arb_assert(cond)
Definition:
arb_assert.h:245
is_nan
CONSTEXPR_INLINE bool is_nan(const T &n)
Definition:
arbtools.h:177
LazyFloat::LazyFloat
LazyFloat(T init)
Definition:
lazy.h:59
LazyFloat::needs_eval
bool needs_eval() const
Definition:
lazy.h:61
LazyFloat::operator=
const LazyFloat & operator=(const T &newval)
Definition:
lazy.h:68
Lazy::Lazy
Lazy(T init)
Definition:
lazy.h:35
Lazy
Definition:
lazy.h:26
Lazy::has_value
bool has_value() const
Definition:
lazy.h:38
LazyFloat::LazyFloat
LazyFloat()
Definition:
lazy.h:58
arbtools.h
Lazy::operator=
const Lazy & operator=(const T &newval)
Definition:
lazy.h:44
Lazy::needs_eval
bool needs_eval() const
Definition:
lazy.h:37
arb_assert.h
init
static ARB_init_perl_interface init
Definition:
ARB_ext.c:101
LazyFloat::has_value
bool has_value() const
Definition:
lazy.h:62
Lazy::Lazy
Lazy()
Definition:
lazy.h:34
T
Definition:
trnsprob.h:20
LazyFloat
Definition:
lazy.h:52
Generated by
1.8.8