eclipse-iceoryx / eclipse-iceoryx/iceoryx

Extend cxx::expected to easily convert error types for error forwarding

Open
#1,012 0 comments 0 reactions 1 assignee Claimed by @elBoberido View on GitHub
enhancement
Dominant language
C++
Stars
2.2k
Forks
492
Avg merge
18h 57m
Merged PRs (30d)
1

Description

## Brief feature description

Currently it is quite cumbersome to convert from one error type to another error type. One way is by `return cxx::error(cxx::into(result.get_error()));` which means one has to repeat the error type.

## Detailed information

It would be better to have automatic error type conversion or at least a way to not repeat oneself, e.g.

```cpp
return cxx::error::from(result.get_error());
```
or
```cpp
return cxx::error::from(result);
```
or
```cpp
return result; // result is of type cxx::expected and the return value is of type cxx::expected
```
The last one can also be used when the inner type is a value instead of an error. This makes forwarding an `cxx::expected` trivial.

To implement this, the feature with the `from`/`into` free functions from #993 can be used

```cpp
template
static error from(F e)
{
return error(cxx::from(e));
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.