Skip to content

Commit b006578

Browse files
committed
remove cvref from the macros
1 parent 2702fff commit b006578

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
22
cmake_policy(SET CMP0097 NEW)
33

4-
project(GeodeResult VERSION 1.3.0 LANGUAGES C CXX)
4+
project(GeodeResult VERSION 1.3.1 LANGUAGES C CXX)
55

66
add_library(GeodeResult INTERFACE)
77

include/Geode/Result.hpp

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <stdexcept>
99
#include <string>
1010
#include <tuple>
11+
#include <type_traits>
1112
#include <utility>
1213
#include <variant>
1314

@@ -42,43 +43,49 @@
4243
#endif
4344

4445
#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() && \
4952
(variable = std::move(GEODE_CONCAT(res, __LINE__)).unwrap(), true)
5053
#endif
5154

5255
#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() && \
5762
(variable = std::move(GEODE_CONCAT(res, __LINE__)).unwrapErr(), true)
5863
#endif
5964

6065
#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() && \
6572
(variable = std::move(GEODE_CONCAT(res, __LINE__)).value(), true)
6673
#endif
6774

6875
#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(); \
7481
else
7582
#endif
7683

7784
#if !defined(GEODE_UNWRAP_EITHER)
7885
#define GEODE_UNWRAP_EITHER(okVariable, errVariable, ...) \
7986
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__)>>{}, \
8289
(__VA_ARGS__) \
8390
); \
8491
GEODE_CONCAT(res, __LINE__).isOk() && \

0 commit comments

Comments
 (0)