forked from hsutter/cppfront
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpure2-inspect-fallback-with-variant-any-optional.cpp
More file actions
52 lines (35 loc) · 2.77 KB
/
pure2-inspect-fallback-with-variant-any-optional.cpp
File metadata and controls
52 lines (35 loc) · 2.77 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
#define CPP2_INCLUDE_STD Yes
//=== Cpp2 type declarations ====================================================
#include "cpp2util.h"
#line 1 "pure2-inspect-fallback-with-variant-any-optional.cpp2"
//=== Cpp2 type definitions and function declarations ===========================
#line 1 "pure2-inspect-fallback-with-variant-any-optional.cpp2"
#line 2 "pure2-inspect-fallback-with-variant-any-optional.cpp2"
[[nodiscard]] auto main() -> int;
#line 14 "pure2-inspect-fallback-with-variant-any-optional.cpp2"
auto test_generic(auto const& x, auto const& msg) -> void;
//=== Cpp2 function definitions =================================================
#line 1 "pure2-inspect-fallback-with-variant-any-optional.cpp2"
#line 2 "pure2-inspect-fallback-with-variant-any-optional.cpp2"
[[nodiscard]] auto main() -> int{
std::variant<int,int,std::string> v {cpp2::impl::as_<std::string>("xyzzy")};
std::any a {cpp2::impl::as_<std::string>("xyzzy")};
std::optional<std::string> o {cpp2::impl::as_<std::string>("xyzzy")};
std::cout << "\nAll these cases satisfy \"matches std::string\"\n";
test_generic(cpp2::move(v), "variant<int, int, string>");
test_generic(cpp2::move(a), "string");
test_generic(cpp2::move(o), "optional<string>");
}
#line 14 "pure2-inspect-fallback-with-variant-any-optional.cpp2"
auto test_generic(auto const& x, auto const& msg) -> void{
std::cout
<< "\n" << msg << "\n ..."
<< [&] () -> std::string { auto&& _expr = x;
if (cpp2::impl::is<std::string>(_expr)) { if constexpr( requires{" matches std::string";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF((" matches std::string")),std::string> ) return " matches std::string"; else return std::string{}; else return std::string{}; }
else if (cpp2::impl::is<std::variant<int,std::string>>(_expr)) { if constexpr( requires{" matches std::variant<int, std::string>";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF((" matches std::variant<int, std::string>")),std::string> ) return " matches std::variant<int, std::string>"; else return std::string{}; else return std::string{}; }
else if (cpp2::impl::is<std::any>(_expr)) { if constexpr( requires{" matches std::any";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF((" matches std::any")),std::string> ) return " matches std::any"; else return std::string{}; else return std::string{}; }
else if (cpp2::impl::is<std::optional<std::string>>(_expr)) { if constexpr( requires{" matches std::optional<std::string>";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF((" matches std::optional<std::string>")),std::string> ) return " matches std::optional<std::string>"; else return std::string{}; else return std::string{}; }
else return " no match"; }
()
<< "\n";
}