The easiest way would be using the trailing-return-type, which allows you to access the function parameters, together with decltype
, which allows you to get the type of an expression.
template<typename T>
auto f(const T& x) -> decltype(x[0])
{
return x[0];
}