Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@SelcukAydi

Description

@SelcukAydi

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 <typename... Types>
  struct apply;

  template <typename Type, typename... Types>
  struct apply<Type, Types...> : public apply<Types...> {};

  template <typename ErrorTag, typename... ErrorParams, typename... Types>
  struct apply<Error<ErrorTag, ErrorParams...>, Types...> {
    using type = Error<ErrorTag, ErrorParams...>;
  };
};

Suggestion code

struct ExtractFirstError
{
    template <typename... Types>
    struct apply;

    template <typename Type>
    struct apply<Type>
    {
        using type = None;
    };

    template <typename Type1, typename Type2, typename... Types>
    struct apply<Type1, Type2, Types...> : public apply<Type2, Types...>
    {
    };

    template <typename ErrorTag, typename... ErrorParams>
    struct apply<Error<ErrorTag, ErrorParams...>>
    {
        using type = Error<ErrorTag, ErrorParams...>;
    };
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions