开发者

Most important const & rvalue refs

开发者 https://www.devze.com 2023-03-17 04:06 出处:网络
In C++03 you can use the const& trick (or \"most important const\") to extend the lifetime of a tempor开发者_JAVA技巧ary to the lifetime of the reference. My question is, in C++0x, does this behav

In C++03 you can use the const& trick (or "most important const") to extend the lifetime of a tempor开发者_JAVA技巧ary to the lifetime of the reference. My question is, in C++0x, does this behaviour extend to rvalue references? I.e auto&& x = someFunction();


According to [class.temporary], if that compiles then yes, the lifetime of the temporary is extended.


It compiles perfectly on VC10 SP1:

int && Get()
{
    return 10;
}

const auto&& y=Get();
0

精彩评论

暂无评论...
验证码 换一张
取 消