forked from hsutter/cppfront
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpure2-inspect-expression-with-as-in-generic-function.cpp
More file actions
41 lines (28 loc) · 1.45 KB
/
pure2-inspect-expression-with-as-in-generic-function.cpp
File metadata and controls
41 lines (28 loc) · 1.45 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
#define CPP2_INCLUDE_STD Yes
//=== Cpp2 type declarations ====================================================
#include "cpp2util.h"
#line 1 "pure2-inspect-expression-with-as-in-generic-function.cpp2"
//=== Cpp2 type definitions and function declarations ===========================
#line 1 "pure2-inspect-expression-with-as-in-generic-function.cpp2"
[[nodiscard]] auto main() -> int;
#line 7 "pure2-inspect-expression-with-as-in-generic-function.cpp2"
auto print_an_int(auto const& x) -> void;
//=== Cpp2 function definitions =================================================
#line 1 "pure2-inspect-expression-with-as-in-generic-function.cpp2"
[[nodiscard]] auto main() -> int{
#line 2 "pure2-inspect-expression-with-as-in-generic-function.cpp2"
print_an_int("syzygy");
print_an_int(1);
print_an_int(1.1);
}
#line 7 "pure2-inspect-expression-with-as-in-generic-function.cpp2"
auto print_an_int(auto const& x) -> void{
std::cout
<< std::setw(30) << cpp2::to_string(x)
<< " value is "
<< [&] () -> std::string { auto&& _expr = x;
if (cpp2::impl::is<int>(_expr)) { if constexpr( requires{std::to_string(cpp2::impl::as<int>(x));} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF((std::to_string(cpp2::impl::as<int>(x)))),std::string> ) return std::to_string(cpp2::impl::as<int>(x)); else return std::string{}; else return std::string{}; }
else return "not an int"; }
()
<< "\n";
}