Skip to content

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

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...>;
    };
};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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