标签: reference-collapsing

什么时候会有 && + && -> && 与 c++ 引用崩溃?

我对理解引用崩溃有一些疑问,所以我在以下代码中做了实验:

template<typename T>
void func(T&& t) {}


int main() {
    // There is no reference collapse here, only binding left or right values to
    // references with universal reference:
    int a = 10;
    func(a); // this equals func<int>(a)
    func(10); // what does this equal to?
    func(std::move(a)); // what does this equal to?

    // The following is not case of universal reference, they are reference
    // collapse, only that the type is template type:
    int& b1 = a;
    int&& b2 = …
Run Code Online (Sandbox Code Playgroud)

c++ reference language-lawyer reference-collapsing

5
推荐指数
1
解决办法
99
查看次数