首页 > “clobber the lvalue”什么意思?

“clobber the lvalue”什么意思?

《c++ primer》讲到右值引用绑定到左值的时候,用了clobber the lvalue这个词,这是什么意思?书中翻译为截断左值(我还是不懂),网上将clobber翻译为连续打击。

Binding an rvalue reference to an lvalue gives code that operates on the rvalue reference permission to clobber the lvalue. There are times, such as in our StrVec reallocate function in § 13.6.1 (p. 533), when we know it is safe to clobber an lvalue. By letting us do the cast, the language allows this usage. By forcing us to use a cast, the language tries to prevent us from doing so accidentally.


就是字面意思啊…
我的理解是这个左值不再用了,expire了,就通过右值截断,接管它。它这个名字对应的内存中的值或其他资源就不归它管理了。
感觉不太好说啊,表达能力捉鸡…


常规情况下是不允许右值绑定到左值的(在函数调用中)。
当一个模板函数的形参是右值引用时,而此时如果我们用一个左值实例化它,为了应对这种情况,c++引入了一个例外规则,所以遇到这种情况的时候,编译器会把模板类型参数推导为实参的左值引用。

【热门文章】
【热门文章】