关于函数模板的问题,有点点没有看懂。

在cppreference.com中解释decltype关键字时,有这样的一段代码:

 #include <iostream>

struct A { double x; };
const A* a = new A{ 0 };

decltype(a->x) y;       // type of y is double (declared type)
decltype((a->x)) z = y; // type of z is const double& (lvalue expression)

template<typename T, typename U>
auto add(T t, U u) -> decltype(t + u); // return type depends on template parameters

int main()
{
    int i = 33;
    decltype(i) j = i * 2;

    std::cout << "i = " << i << ", "
        << "j = " << j << '\n';

    auto f = [](int a, int b) -> int
    {
        return a * b;
    };

    decltype(f) g = f; // the type of a lambda function is unique and unnamed
    i = f(2, 2);
    j = g(3, 3);

    std::cout << "i = " << i << ", "
        << "j = " << j << '\n';
}

其中

 template<typename T, typename U>
auto add(T t, U u) -> decltype(t + u); // return type depends on template parameters

这段代码是什么意思?
求详解。

template
auto add(T t, U u) -> decltype(t + u){ return t + u; }; // return type depends on template parameters

是这个代码的声明

http://baike.baidu.com/link?url=2ZuntIrXqzgA1PrzUX7ACbz0yuu2YAgSLC3Y16ox7Na_-SObmJicRnWAmJ5r5xWlE6MCegFFYTxbWUR114uFAq
主要是lambda表达式本身的返回类型取决于模板参数,所以无法直接给出。