google / google/fruit

[Suggestion] ExtractFirstError meta function SHOULD be non-error safe

Open
#155 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
1.9k
Forks
202
PR merge metrics
No merged PRs in 30d

Description

I believe that a meta function should be safe to instantiate its internal type. For example, `ExtractFirstError ` has a `type` member type alias only in the case of an error propagated. This forces the user to be sure that this meta function should be used in the case of an error to get its type member. However, when there is no error at all then this meta function's apply struct's recursive instantiation will be ill-formed. So a suggestion may be as the following:

**Current code**
```
struct ExtractFirstError {
template
struct apply;

template
struct apply : public apply {};

template
struct apply, Types...> {
using type = Error;
};
};
```
**Suggestion code**
```
struct ExtractFirstError
{
template
struct apply;

template
struct apply
{
using type = None;
};

template
struct apply : public apply
{
};

template
struct apply>
{
using type = Error;
};
};
```

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.