C++Spec
1.0.0
BDD testing for C++
Toggle main menu visibility
Main Page
Related Pages
Concepts
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
a
d
e
f
g
h
i
l
n
p
r
s
t
v
Functions
a
d
e
f
g
h
i
l
n
p
r
s
t
v
Variables
Files
File List
•
All
Classes
Files
Functions
Variables
Pages
Concepts
Loading...
Searching...
No Matches
let.hpp
Go to the documentation of this file.
1
2
#pragma once
3
4
#include <functional>
5
#include <optional>
6
7
namespace
CppSpec {
8
16
class
LetBase {
17
protected
:
18
bool
delivered{
false
};
19
20
public
:
21
constexpr
LetBase()
noexcept
=
default
;
22
LetBase(
const
LetBase& copy) =
default
;
23
void
reset()
noexcept
{ delivered =
false
; }
24
[[nodiscard]]
constexpr
bool
has_result()
const
noexcept
{
return
this->delivered; }
25
};
16
class
LetBase {
…
};
26
33
template
<
typename
T>
34
class
Let :
public
LetBase {
35
using
block_t = std::function<T()>;
36
std::optional<T> result;
37
38
block_t body;
39
40
void
exec();
41
42
public
:
43
explicit
Let(block_t body) noexcept : LetBase(), body(body) {}
44
45
T* operator->() {
46
value
();
47
return
result.operator->();
48
}
49
50
T& operator*() & {
return
value
(); }
51
T&
value
() &;
52
};
34
class
Let :
public
LetBase {
…
};
53
55
template
<
typename
T>
56
void
Let<T>::exec() {
57
if
(!delivered) {
58
result = body();
59
delivered =
true
;
60
}
61
}
62
67
template
<
typename
T>
68
T&
Let<T>::value
() & {
69
exec();
70
return
result.value();
71
}
68
T&
Let<T>::value
() & {
…
}
72
73
}
// namespace CppSpec
CppSpec::Let::value
T & value() &
Get the value contained in the Let.
Definition
let.hpp:68
include
let.hpp
Generated by
1.13.2