-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshort_circuit_evaluation.cpp
More file actions
128 lines (105 loc) · 3.73 KB
/
Copy pathshort_circuit_evaluation.cpp
File metadata and controls
128 lines (105 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Logicwise
// Copyright (c) 2026 Frog Singing (@frog-singing)
// SPDX-License-Identifier: MIT
#include <logicwise.h>
#include <iostream> // std::cout, std::endl
// If this file compiles successfully, then all logical assertions have passed.
namespace logicwise::test
{
struct CoffeePot { static consteval bool I_can_brew_coffee() { return true; } };
struct CoffeeMachine { static consteval bool I_can_brew_coffee() { return true; } };
struct BrokenCoffeePot { static consteval bool I_can_brew_coffee() { return false; } };
struct Teapot
{
// cannot be called at compile time
static bool I_can_brew_coffee()
{
std::cout << "I'm a teapot" << std::endl;
return false;
}
};
}
int main()
{
using namespace logicwise;
using namespace logicwise::quantifier; // check this out in logicwise/mode.h
using namespace logicwise::arrangement;
using namespace logicwise::wrapper;
using namespace logicwise::test;
//--------------------------------------------------------------------------------
// Normally, predicates are verified in reverse order.
// In case of elementwise arrangement, predicates are always verified in reverse order.
static_assert(
rangewise<always_true, element>
::in<type_list<Teapot, Teapot, Teapot>>()
.satisfies([] <typename SomePot> { return SomePot::I_can_brew_coffee(); }),
"short-circuit evaluation: always_true"
);
static_assert(
not
rangewise<always_false, element>
::in<type_list<Teapot, Teapot, Teapot>>()
.satisfies([] <typename SomePot> { return SomePot::I_can_brew_coffee(); }),
"short-circuit evaluation: always_false"
);
static_assert(
not
rangewise<all_of, element>
::in<type_list<Teapot, BrokenCoffeePot, CoffeePot>>()
.satisfies([] <typename SomePot> { return SomePot::I_can_brew_coffee(); }),
"short-circuit evaluation: all_of"
);
static_assert(
rangewise<any_of, element>
::in<type_list<Teapot, CoffeePot, BrokenCoffeePot>>()
.satisfies([] <typename SomePot> { return SomePot::I_can_brew_coffee(); }),
"short-circuit evaluation: any_of"
);
static_assert(
not
rangewise<none_of, element>
::in<type_list<Teapot, CoffeePot, BrokenCoffeePot>>()
.satisfies([] <typename SomePot> { return SomePot::I_can_brew_coffee(); }),
"short-circuit evaluation: none_of"
);
static_assert(
rangewise<not_every, element>
::in<type_list<Teapot, BrokenCoffeePot, CoffeePot>>()
.satisfies([] <typename SomePot> { return SomePot::I_can_brew_coffee(); }),
"short-circuit evaluation: not_every"
);
static_assert(
not
rangewise<exactly<1>, element>
::in<type_list<Teapot, CoffeeMachine, BrokenCoffeePot, CoffeePot>>()
.satisfies([] <typename SomePot> { return SomePot::I_can_brew_coffee(); }),
"short-circuit evaluation: exactly<N>"
);
static_assert(
rangewise<at_least<2>, element>
::in<type_list<Teapot, CoffeeMachine, BrokenCoffeePot, CoffeePot>>()
.satisfies([] <typename SomePot> { return SomePot::I_can_brew_coffee(); }),
"short-circuit evaluation: at_least<N>"
);
static_assert(
not
rangewise<at_most<1>, element>
::in<type_list<Teapot, CoffeeMachine, BrokenCoffeePot, CoffeePot>>()
.satisfies([] <typename SomePot> { return SomePot::I_can_brew_coffee(); }),
"short-circuit evaluation: at_most<N>"
);
static_assert(
rangewise<more_than<1>, element>
::in<type_list<Teapot, CoffeeMachine, BrokenCoffeePot, CoffeePot>>()
.satisfies([] <typename SomePot> { return SomePot::I_can_brew_coffee(); }),
"short-circuit evaluation: more_than<N>"
);
static_assert(
not
rangewise<less_than<2>, element>
::in<type_list<Teapot, CoffeeMachine, BrokenCoffeePot, CoffeePot>>()
.satisfies([] <typename SomePot> { return SomePot::I_can_brew_coffee(); }),
"short-circuit evaluation: less_than<N>"
);
std::cout << std::endl << "Hello Logic!" << std::endl;
}