blob: ed250e52b0698d0a25c0652dddf45a3e6728e284 (
plain)
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
|
#include <iostream>
#include <vector>
constexpr auto less_than = [](int value) {
return [=](auto x) { return x < value;};
};
constexpr auto in = [](auto min, auto max) {
return [=](auto x) {
return min <= x && x <= max;
};
};
constexpr auto empty = [](auto&& x){
return std::empty(x);
};
main: () -> int = {
i := 15;
std::cout << inspect i -> std::string {
is (less_than(10)) = "i less than 10";
is (in(11,20)) = "i is between 11 and 20";
is _ = "i is out of our interest";
} << std::endl;
if i is (less_than(20)) {
std::cout << "less than 20" << std::endl;
}
if i is (in(10,30)) {
std::cout << "i is between 10 and 30" << std::endl;
}
v : std::vector<int> = ();
if empty(v) {
std::cout << "v is empty" << std::endl;
}
if v is (empty) {
std::cout << "v is empty" << std::endl;
}
}
|