fgerlits commented on code in PR #1926:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1926#discussion_r1995279651
##########
utils/include/utils/expected.h:
##########
@@ -176,11 +177,26 @@ auto operator|(Expected&& object,
transform_error_wrapper<F> f) {
static_assert(valid_unexpected_type<transformed_error_type>, "transformError
expects a function returning a valid unexpected type");
using transformed_expected_type = nonstd::expected<value_type,
transformed_error_type>;
if (object.has_value()) {
- return transformed_expected_type{std::forward<Expected>(object)};
+ return transformed_expected_type{std::forward<Expected>(object).value()};
}
return transformed_expected_type{nonstd::unexpect,
std::invoke(std::forward<F>(f.function),
std::forward<Expected>(object).error())};
}
+template<expected Expected>
+std::optional<typename std::remove_cvref_t<Expected>::value_type>
operator|(Expected&& object, to_optional_wrapper) {
+ if (object) {
+ return std::move(*object);
+ }
+ return std::nullopt;
+}
+
+template<expected Expected>
+typename std::remove_cvref_t<Expected>::value_type operator|(Expected&&
object, expect_wrapper e) {
+ if (object) {
+ return std::move(*object);
+ }
+ throw std::runtime_error(e.reason);
Review Comment:
thanks, that's even better
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]