decltype auto

六月 12, 2022 [c++] #c++

decltype auto

decltype

decltype(auto) foo(auto t1, auto t2) {
    return t1+t2;
}
int x = 1;
int main() {
    int xx = 11;
    decltype(x) xr = x;
    decltype(xx) xxr = xx;
    decltype(x) xr = x;
    decltype(xx) xxr = xx;
    xr = 2;
    xxr = 12;
    cout << "x:" << x << "\txr:" << xr << "\n";
    cout << "xx:" << xx << "\txxr:" << xxr << "\n";

    decltype((x)) qxr = x;
    decltype((xx)) qxxr = xx;
    qxr = 10001;
    qxxr  = 10011;
    cout << "x:" << x << "\tqxr:" << qxr << "\n";
    cout << "xx:" << xx << "\tqxxr:" << qxxr << "\n";
    return 0;
}