11// ----- Cpp2 support -----
2- #define CPP2_USE_MODULES Yes
32#include " cpp2util.h"
43
4+ #line 1 "mixed-inspect-values.cpp2"
5+ auto in (int min, int max) {
6+ return [=](int x){ return min <= x && x <= max; };
7+ }
58
6- #line 1 "pure2-inspect-values.cpp2"
9+ [[nodiscard]] auto in_2_3 (cpp2::in<int > x) -> bool;
10+ #line 7 "mixed-inspect-values.cpp2"
711[[nodiscard]] auto main () -> int;
8- #line 23 "pure2 -inspect-values.cpp2"
12+ #line 31 "mixed -inspect-values.cpp2"
913auto test (auto const & x) -> void;
1014
1115// === Cpp2 definitions ==========================================================
1216
13- #line 1 "pure2-inspect-values.cpp2"
17+ #line 4 "mixed-inspect-values.cpp2"
18+
19+ [[nodiscard]] auto in_2_3 (cpp2::in<int > x) -> bool { return 2 <= x && x <= 3 ; }
20+
1421[[nodiscard]] auto main () -> int{
1522 std::variant<double ,std::string,double > v { };
16- test (v);
1723 v = " rev dodgson" ;
1824 test (std::move (v));
1925
@@ -28,6 +34,9 @@ auto test(auto const& x) -> void;
2834 test (std::move (a));
2935
3036 test (0 );
37+ test (1 );
38+ test (2 );
39+ test (3 );
3140 test (-42 );
3241 test (cpp2::as< std::string>(" xyzzy" ));
3342 test (3.14 );
@@ -37,7 +46,9 @@ auto test(auto const& x) -> void{
3746 auto forty_two { 42 };
3847 std::cout << [&] () -> std::string { auto && __expr = x;
3948 if (cpp2::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{}; }
40- else if (cpp2::is (__expr, (std::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{}; }
49+ else if (cpp2::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{}; }
50+ else if (cpp2::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{}; }
51+ else if (cpp2::is (__expr, std::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{}; }
4152 else if (cpp2::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{}; }
4253 else if (cpp2::is<std::string>(__expr)) { if constexpr ( requires {cpp2::as<std::string>(x);} ) if constexpr ( std::is_convertible_v<CPP2_TYPEOF ((cpp2::as<std::string>(x))),std::string> ) return cpp2::as<std::string>(x); else return std::string{}; else return std::string{}; }
4354 else return " (no match)" ; }
0 commit comments