Thanks to C++14, we'll soon be able to curtail verbose trailing return types; such as the generic min
example from David Abrahams 2011 post:
template <typename T, typename U>
auto min(T x, U y)
-> typename std::remove_reference< decltype(x < y ? x : y) >::type
{ return x < y ? x : y; }
Under C++14 the return type can be omitted, and min
can be written as:
template <typename T, typename U>
auto min(T x, U y)
{ return x < y ? x : y; }
This is a simple example, however return type deduction is very useful for generic code, and can avoid much replication. My question is, for functions such as this, how do we integrate SFINAE techniques? For example, how can I use std::enable_if
to restrict our min
function to return types which are integral?