-
Notifications
You must be signed in to change notification settings - Fork 202
Open
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 <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
Labels
No labels