Suppose you attempt to do the following:
template</* args */>
typename std::enable_if< /*conditional*/ , /*type*/ >::type
static auto hope( /*args*/) -> decltype( /*return expr*/ )
{
}
Is it possible to combine conditional inclusion/overloading (std::enable_if
) with trailing-return-type (auto ... -> decltype()
)?
I would not be interesting in solutions using the preprocessor. I can always do things like
#define RET(t) --> decltype(t) { return t; }
and extend it to take also the whole conditional. Instead I am interested if the language supports it without using another trait for the return type, i.e. ReturnType<A,B>::type_t
or whatever is used in the function body.
The trailing-return-type isn't much different from the normal return type, except that it's specified after the parameter list and cv-/ref-qualifiers. Also, it doesn't necessarily need
decltype
, a normal type is fine too:So by now you should see what the answer to your question is:
Though I personally prefer using just
decltype
and expression SFINAE, as long as the condition can be expressed as an expression (e.g., can you invoke a function on an object of a certain type):