Function Templates vs. Auto Keyword

In a nutshell, auto cannot be used in an effort to omit the actual types of function arguments, so stick with function templates and/or overloads. auto is legally used to automatically deduce the types of variables:

auto i=5;

Be very careful to understand the difference between the following, however:

auto x=...
auto &x=...
const auto &x=...
auto *px=...; // vs auto px=... (They are equivalent assuming what is being 
              //                 assigned can be deduced to an actual pointer.)
// etc...

It is also used for suffix return types:

template <typename T, typename U>
auto sum(const T &t, const U &u) -> decltype(t+u)
{
  return t+u;
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)