Date
2011-05-03.22:13:16
Message id
1264

Content

I'm just reflecting on the now SFINAE-constrained constructors and assignment operators of error_code and error_condition:

These are the only library components that are pro-actively announcing that they are using std::enable_if as constraining tool, which has IMO several disadvantages:

  1. With the availability of template default arguments and decltype, using enable_if in the C++0x standard library, seems unnecessary restricting implementation freedom. E.g. there should be no need for a useless specification of a dummy default function argument, which only confuses the reader. A more reasonable implementation could e.g. be

    template <class ErrorCodeEnum
     class = typename enable_if<is_error_code_enum<ErrorCodeEnum>::value>::type>
    error_code(ErrorCodeEnum e);
    

    As currently specified, the function signatures are so unreadable, that errors quite easily happen, see e.g. 1229.

  2. We have a lot of constrained functions in other places, that now have a standard phrase that is easily understandable:

    Remarks: This constructor/function shall participate in overload resolution if and only if X.

    where X describes the condition. Why should these components deviate?

  3. If enable_if would not be explicitly specified, the standard library is much better prepared for the future. It would also be possible, that libraries with partial support for not-yet-standard-concepts could provide a much better diagnostic as is possible with enable_if. This again would allow for experimental concept implementations in the wild, which as a result would make concept standardization a much more natural thing, similar to the way as templates were standardized in C++.

    In summary: I consider it as a library defect that error_code and error_condition explicitly require a dependency to enable_if and do limit implementation freedom and I volunteer to prepare a corresponding resolution.