c++ - Proper way to use SFINAE struct defintions -
for educative reasons, playing around sfinae behavior of c++ , building own version of std::enable_if
in rather simplified form. noticed different behavior when using different implementation details though:
implementation incomplete type:
template <bool c, typename> struct enable_if; // incomplete type template <typename t> struct enable_if<true, t> { typedef t type; };
implementation empty type:
template <bool c, typename> struct enable_if {}; // empty type template <typename t> struct enable_if<true, t> { typedef t type; };
on g++ (4.8.1 , 4.3.2) both versions compile , behave same way. msvc 2008 seems accept definition empty type.
are both definitions valid c++, , should equivalent in behavior?
from standard, § 14.8.2:
type deduction may fail following reasons: [...] attempting use type in nested-name-specifier of qualified-id when type not contain specified member, or specified member not type type required [...]
both cases handled in same sentence, understanding should not make difference - both implementations should equivalent.
Comments
Post a Comment