|
| 1 | + |
| 2 | +#define CPP2_IMPORT_STD Yes |
| 3 | + |
| 4 | +//=== Cpp2 type declarations ==================================================== |
| 5 | + |
| 6 | + |
| 7 | +#include "cpp2util.h" |
| 8 | + |
| 9 | +#line 1 "pure2-is-with-variable-and-value.cpp2" |
| 10 | + |
| 11 | +#line 26 "pure2-is-with-variable-and-value.cpp2" |
| 12 | +class WithOp; |
| 13 | + |
| 14 | + |
| 15 | +#line 30 "pure2-is-with-variable-and-value.cpp2" |
| 16 | +class WithGenOp; |
| 17 | + |
| 18 | + |
| 19 | +#line 39 "pure2-is-with-variable-and-value.cpp2" |
| 20 | +class Cmp; |
| 21 | + |
| 22 | + |
| 23 | +//=== Cpp2 type definitions and function declarations =========================== |
| 24 | + |
| 25 | +#line 1 "pure2-is-with-variable-and-value.cpp2" |
| 26 | +auto fun(auto const& name, auto const& v) -> void; |
| 27 | + |
| 28 | +#line 14 "pure2-is-with-variable-and-value.cpp2" |
| 29 | +[[nodiscard]] auto main() -> int; |
| 30 | + |
| 31 | +#line 26 "pure2-is-with-variable-and-value.cpp2" |
| 32 | +class WithOp { |
| 33 | + public: [[nodiscard]] auto op_is(cpp2::impl::in<int> x) const& -> auto; |
| 34 | + public: WithOp() = default; |
| 35 | + public: WithOp(WithOp const&) = delete; /* No 'that' constructor, suppress copy */ |
| 36 | + public: auto operator=(WithOp const&) -> void = delete; |
| 37 | + |
| 38 | +#line 28 "pure2-is-with-variable-and-value.cpp2" |
| 39 | +}; |
| 40 | + |
| 41 | +class WithGenOp { |
| 42 | + public: [[nodiscard]] auto op_is(auto const& x) const& -> bool; |
| 43 | + public: WithGenOp() = default; |
| 44 | + public: WithGenOp(WithGenOp const&) = delete; /* No 'that' constructor, suppress copy */ |
| 45 | + public: auto operator=(WithGenOp const&) -> void = delete; |
| 46 | + |
| 47 | + |
| 48 | +#line 37 "pure2-is-with-variable-and-value.cpp2" |
| 49 | +}; |
| 50 | + |
| 51 | +class Cmp { |
| 52 | + public: [[nodiscard]] auto operator==(cpp2::impl::in<int> x) const& -> bool; |
| 53 | + public: Cmp() = default; |
| 54 | + public: Cmp(Cmp const&) = delete; /* No 'that' constructor, suppress copy */ |
| 55 | + public: auto operator=(Cmp const&) -> void = delete; |
| 56 | + |
| 57 | +#line 41 "pure2-is-with-variable-and-value.cpp2" |
| 58 | +}; |
| 59 | + |
| 60 | + |
| 61 | +//=== Cpp2 function definitions ================================================= |
| 62 | + |
| 63 | +#line 1 "pure2-is-with-variable-and-value.cpp2" |
| 64 | +auto fun(auto const& name, auto const& v) -> void{ |
| 65 | +#line 2 "pure2-is-with-variable-and-value.cpp2" |
| 66 | + std::cout << name << ": " << |
| 67 | + [&] () -> std::string { auto&& _expr = v; |
| 68 | + if (cpp2::impl::is(_expr, (42))) { if constexpr( requires{"42";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("42")),std::string> ) return "42"; else return std::string{}; else return std::string{}; } |
| 69 | + else if (cpp2::impl::is(_expr, 123)) { if constexpr( requires{"op_is";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("op_is")),std::string> ) return "op_is"; else return std::string{}; else return std::string{}; } |
| 70 | + else if (cpp2::impl::is(_expr, -123)) { if constexpr( requires{"generic op_is";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("generic op_is")),std::string> ) return "generic op_is"; else return std::string{}; else return std::string{}; } |
| 71 | + else if (cpp2::impl::is(_expr, 4321)) { if constexpr( requires{"comperable";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("comperable")),std::string> ) return "comperable"; else return std::string{}; else return std::string{}; } |
| 72 | + else if (cpp2::impl::is(_expr, "text")) { if constexpr( requires{"text";} ) if constexpr( std::is_convertible_v<CPP2_TYPEOF(("text")),std::string> ) return "text"; else return std::string{}; else return std::string{}; } |
| 73 | + else return "unknown"; } |
| 74 | + () |
| 75 | + << std::endl; |
| 76 | +} |
| 77 | + |
| 78 | +#line 14 "pure2-is-with-variable-and-value.cpp2" |
| 79 | +[[nodiscard]] auto main() -> int{ |
| 80 | + fun("3.14", 3.14); |
| 81 | + fun("42", 42); |
| 82 | + fun("WithOp()", WithOp()); |
| 83 | + fun("WithGenOp()", WithGenOp()); |
| 84 | + fun("Cmp()", Cmp()); |
| 85 | + fun("std::string(\"text\")", std::string("text")); |
| 86 | + fun("\"text\"", "text"); |
| 87 | + fun("std::string_view(\"text\")", std::string_view("text")); |
| 88 | + fun(":std::vector = ('t','e','x','t','\\0')", std::vector{'t', 'e', 'x', 't', '\0'}); |
| 89 | +} |
| 90 | + |
| 91 | +#line 27 "pure2-is-with-variable-and-value.cpp2" |
| 92 | + [[nodiscard]] auto WithOp::op_is(cpp2::impl::in<int> x) const& -> auto { return x == 123; } |
| 93 | + |
| 94 | +#line 31 "pure2-is-with-variable-and-value.cpp2" |
| 95 | + [[nodiscard]] auto WithGenOp::op_is(auto const& x) const& -> bool{ |
| 96 | + if constexpr (std::convertible_to<decltype(x),int>) { |
| 97 | + return x == -123; |
| 98 | + } |
| 99 | + return false; |
| 100 | + } |
| 101 | + |
| 102 | +#line 40 "pure2-is-with-variable-and-value.cpp2" |
| 103 | + [[nodiscard]] auto Cmp::operator==(cpp2::impl::in<int> x) const& -> bool { return x == 4321; } |
| 104 | + |
0 commit comments