|
8 | 8 | #include <stdexcept> |
9 | 9 | #include <string> |
10 | 10 | #include <tuple> |
| 11 | + #include <type_traits> |
11 | 12 | #include <utility> |
12 | 13 | #include <variant> |
13 | 14 |
|
|
42 | 43 | #endif |
43 | 44 |
|
44 | 45 | #if !defined(GEODE_UNWRAP_IF_OK) |
45 | | - #define GEODE_UNWRAP_IF_OK(variable, ...) \ |
46 | | - auto [variable, GEODE_CONCAT(res, __LINE__)] = \ |
47 | | - std::make_pair(geode::impl::ResultOkType<decltype(__VA_ARGS__)>{}, (__VA_ARGS__)); \ |
48 | | - GEODE_CONCAT(res, __LINE__).isOk() && \ |
| 46 | + #define GEODE_UNWRAP_IF_OK(variable, ...) \ |
| 47 | + auto [variable, GEODE_CONCAT(res, __LINE__)] = std::make_pair( \ |
| 48 | + geode::impl::ResultOkType<std::remove_cvref_t<decltype(__VA_ARGS__)>>{}, \ |
| 49 | + (__VA_ARGS__) \ |
| 50 | + ); \ |
| 51 | + GEODE_CONCAT(res, __LINE__).isOk() && \ |
49 | 52 | (variable = std::move(GEODE_CONCAT(res, __LINE__)).unwrap(), true) |
50 | 53 | #endif |
51 | 54 |
|
52 | 55 | #if !defined(GEODE_UNWRAP_IF_ERR) |
53 | | - #define GEODE_UNWRAP_IF_ERR(variable, ...) \ |
54 | | - auto [variable, GEODE_CONCAT(res, __LINE__)] = \ |
55 | | - std::make_pair(geode::impl::ResultErrType<decltype(__VA_ARGS__)>{}, (__VA_ARGS__)); \ |
56 | | - GEODE_CONCAT(res, __LINE__).isErr() && \ |
| 56 | + #define GEODE_UNWRAP_IF_ERR(variable, ...) \ |
| 57 | + auto [variable, GEODE_CONCAT(res, __LINE__)] = std::make_pair( \ |
| 58 | + geode::impl::ResultErrType<std::remove_cvref_t<decltype(__VA_ARGS__)>>{}, \ |
| 59 | + (__VA_ARGS__) \ |
| 60 | + ); \ |
| 61 | + GEODE_CONCAT(res, __LINE__).isErr() && \ |
57 | 62 | (variable = std::move(GEODE_CONCAT(res, __LINE__)).unwrapErr(), true) |
58 | 63 | #endif |
59 | 64 |
|
60 | 65 | #if !defined(GEODE_UNWRAP_IF_SOME) |
61 | | - #define GEODE_UNWRAP_IF_SOME(variable, ...) \ |
62 | | - auto [variable, GEODE_CONCAT(res, __LINE__)] = \ |
63 | | - std::make_pair(geode::impl::OptionalType<decltype(__VA_ARGS__)>{}, (__VA_ARGS__)); \ |
64 | | - GEODE_CONCAT(res, __LINE__).has_value() && \ |
| 66 | + #define GEODE_UNWRAP_IF_SOME(variable, ...) \ |
| 67 | + auto [variable, GEODE_CONCAT(res, __LINE__)] = std::make_pair( \ |
| 68 | + geode::impl::OptionalType<std::remove_cvref_t<decltype(__VA_ARGS__)>>{}, \ |
| 69 | + (__VA_ARGS__) \ |
| 70 | + ); \ |
| 71 | + GEODE_CONCAT(res, __LINE__).has_value() && \ |
65 | 72 | (variable = std::move(GEODE_CONCAT(res, __LINE__)).value(), true) |
66 | 73 | #endif |
67 | 74 |
|
68 | 75 | #if !defined(GEODE_UNWRAP_OR_ELSE) |
69 | | - #define GEODE_UNWRAP_OR_ELSE(variable, ...) \ |
70 | | - geode::impl::ResultOkType<decltype(__VA_ARGS__)> variable; \ |
71 | | - auto GEODE_CONCAT(res, __LINE__) = __VA_ARGS__; \ |
72 | | - if (GEODE_CONCAT(res, __LINE__).isOk()) \ |
73 | | - variable = std::move(GEODE_CONCAT(res, __LINE__)).unwrap(); \ |
| 76 | + #define GEODE_UNWRAP_OR_ELSE(variable, ...) \ |
| 77 | + geode::impl::ResultOkType<std::remove_cvref_t<decltype(__VA_ARGS__)>> variable; \ |
| 78 | + auto GEODE_CONCAT(res, __LINE__) = __VA_ARGS__; \ |
| 79 | + if (GEODE_CONCAT(res, __LINE__).isOk()) \ |
| 80 | + variable = std::move(GEODE_CONCAT(res, __LINE__)).unwrap(); \ |
74 | 81 | else |
75 | 82 | #endif |
76 | 83 |
|
77 | 84 | #if !defined(GEODE_UNWRAP_EITHER) |
78 | 85 | #define GEODE_UNWRAP_EITHER(okVariable, errVariable, ...) \ |
79 | 86 | auto [okVariable, errVariable, GEODE_CONCAT(res, __LINE__)] = std::make_tuple( \ |
80 | | - geode::impl::ResultOkType<decltype(__VA_ARGS__)>{}, \ |
81 | | - geode::impl::ResultErrType<decltype(__VA_ARGS__)>{}, \ |
| 87 | + geode::impl::ResultOkType<std::remove_cvref_t<decltype(__VA_ARGS__)>>{}, \ |
| 88 | + geode::impl::ResultErrType<std::remove_cvref_t<decltype(__VA_ARGS__)>>{}, \ |
82 | 89 | (__VA_ARGS__) \ |
83 | 90 | ); \ |
84 | 91 | GEODE_CONCAT(res, __LINE__).isOk() && \ |
|
0 commit comments