FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[Original HTTPS Page]
cppfront/regression-tests/pure2-type-safety-1.cpp2 at main · hsutter/cppfront · GitHub
hsutter
/
cppfront
Public
Notifications
You must be signed in to change notification settings
Fork
269
Star
6k
Code
Issues
190
Pull requests
12
Discussions
Actions
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
cppfront
/
regression-tests
/
pure2-type-safety-1.cpp2
Copy path
More file actions
More file actions
Latest commit
History
History
History
69 lines (59 loc) · 1.51 KB
Breadcrumbs
cppfront
/
regression-tests
/
pure2-type-safety-1.cpp2
Copy path
File metadata and controls
69 lines (59 loc) · 1.51 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
main: () -> int =
{
v: std::variant<int, int, double> = 42.0;
a: std::any = "xyzzy";
o: std::optional<int> = ();
test_generic(3.14, "double");
test_generic(v, "variant<int, int, double>");
test_generic(a, "any");
test_generic(o, "optional<int>");
std::cout << "\n";
_ = v.emplace<1>(1);
a = 2;
o = 3;
test_generic(42, "int");
test_generic(v, "variant<int, int, double>");
test_generic(a, "any");
test_generic(o, "optional<int>");
oi: std::optional<int> = 5;
std::cout << "optional<int> is: ";
test_1365(oi);
od: std::optional<*D> = nullptr;
std::cout << "\noptional<*D> is: ";
test_1365(od);
std::cout << "\n";
}
test_generic: ( x, msg ) = {
msgx: std::string = msg;
// Full qualification is necessary to avoid ambiguity in C++23
// C++23 defines std::print, which would be picked up here by ADL
::print( msgx + " is int? ", x is int );
}
B: type = { }
D: type = { this: B; }
test_1365: (o) = {
if o is int {
std::cout << "int ";
}
if o is bool {
std::cout << "bool ";
}
if o is float {
std::cout << "float ";
}
if o is *B {
std::cout << "*B ";
}
if o is *D {
std::cout << "*D ";
}
if o is std::string {
std::cout << "std::string ";
}
}
print: ( msg: std::string, b: bool ) = {
bmsg: * const char;
if b { bmsg = "true"; }
else { bmsg = "false"; }
std::cout << std::setw(40) << msg << bmsg << "\n";
}
Back
|
FazBrowse Home
|
New Git URL