FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cppfront/mixed-inspect-values.cpp at main · jnorthrup/cppfront · GitHub
jnorthrup
/
cppfront
Public
forked from
hsutter/cppfront
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
8
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cppfront
/
mixed-inspect-values.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
71 lines (51 loc) · 3.15 KB
Breadcrumbs
cppfront
/
mixed-inspect-values.cpp
Copy path
File metadata and controls
71 lines (51 loc) · 3.15 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
69
70
//
=== Cpp2 type declarations ====================================================
#
include
"
cpp2util.h
"
#
line
1 "regression-tests/mixed-inspect-values.cpp2"
//
=== Cpp2 type definitions and function declarations ===========================
#
line
1 "regression-tests/mixed-inspect-values.cpp2"
auto
in
(
int
min,
int
max) {
return
[=](
int
x){
return
min <= x && x <= max; };
}
#
line
5 "regression-tests/mixed-inspect-values.cpp2"
[[nodiscard]]
auto
in_2_3
(cpp2::impl::in<
int
> x) -> bool;
[[nodiscard]]
auto
main
() -> int;
#
line
31 "regression-tests/mixed-inspect-values.cpp2"
auto
test
(
auto
const
& x) -> void;
//
=== Cpp2 function definitions =================================================
#
line
1 "regression-tests/mixed-inspect-values.cpp2"
#
line
5 "regression-tests/mixed-inspect-values.cpp2"
[[nodiscard]]
auto
in_2_3
(cpp2::impl::in<
int
> x) -> bool {
return
cpp2::impl::cmp_less_eq
(
2
,x) &&
cpp2::impl::cmp_less_eq
(x,
3
); }
#
line
7 "regression-tests/mixed-inspect-values.cpp2"
[[nodiscard]]
auto
main
() -> int{
std::variant<
double
,std::string,
double
> v {};
v =
"
rev dodgson
"
;
test
(
cpp2::move
(v));
std::optional<
int
> o {};
test
(o);
o =
42
;
test
(
cpp2::move
(o));
std::any a {
0
};
test
(a);
a = cpp2::impl::as_<std::string>(
"
plugh
"
);
test
(
cpp2::move
(a));
test
(
0
);
test
(
1
);
test
(
2
);
test
(
3
);
test
(-
42
);
test
(cpp2::impl::as_<std::string>(
"
xyzzy
"
));
test
(
3.14
);
}
#
line
31 "regression-tests/mixed-inspect-values.cpp2"
auto
test
(
auto
const
& x) -> void{
auto
forty_two {
42
};
std::cout << [&] () -> std::string {
auto
&& _expr = x;
if
(
cpp2::impl::is
(_expr,
0
)) {
if
constexpr
(
requires
{
"
zero
"
;} )
if
constexpr
( std::is_convertible_v<
CPP2_TYPEOF
((
"
zero
"
)),std::string> )
return
"
zero
"
;
else
return
std::string{};
else
return
std::string{}; }
else
if
(
cpp2::impl::is
(_expr, (
in
(
1
,
2
)))) {
if
constexpr
(
requires
{
"
1 or 2
"
;} )
if
constexpr
( std::is_convertible_v<
CPP2_TYPEOF
((
"
1 or 2
"
)),std::string> )
return
"
1 or 2
"
;
else
return
std::string{};
else
return
std::string{}; }
else
if
(
cpp2::impl::is
(_expr, in_2_3)) {
if
constexpr
(
requires
{
"
3
"
;} )
if
constexpr
( std::is_convertible_v<
CPP2_TYPEOF
((
"
3
"
)),std::string> )
return
"
3
"
;
else
return
std::string{};
else
return
std::string{}; }
else
if
(
cpp2::impl::is
(_expr,
cpp2::move
(forty_two))) {
if
constexpr
(
requires
{
"
the answer
"
;} )
if
constexpr
( std::is_convertible_v<
CPP2_TYPEOF
((
"
the answer
"
)),std::string> )
return
"
the answer
"
;
else
return
std::string{};
else
return
std::string{}; }
else
if
(cpp2::impl::is<
int
>(_expr)) {
if
constexpr
(
requires
{
"
integer
"
+
cpp2::to_string
(x);} )
if
constexpr
( std::is_convertible_v<
CPP2_TYPEOF
((
"
integer
"
+
cpp2::to_string
(x))),std::string> )
return
"
integer
"
+
cpp2::to_string
(x);
else
return
std::string{};
else
return
std::string{}; }
else
if
(cpp2::impl::is<std::string>(_expr)) {
if
constexpr
(
requires
{cpp2::impl::as<std::string>(x);} )
if
constexpr
( std::is_convertible_v<
CPP2_TYPEOF
((cpp2::impl::as<std::string>(x))),std::string> )
return
cpp2::impl::as<std::string>(x);
else
return
std::string{};
else
return
std::string{}; }
else
return
"
(no match)
"
; }
() <<
"
\n
"
;
}
Back
|
FazBrowse Home
|
New Git URL