R.33: Take a unique_ptr<widget>& parameter to express that a function reseats the widget
R.33: 表达函数会重置widget时,使用unique_ptr<widget>&作参数。
Reason(原因)
Using unique_ptr in this way both documents and enforces the function call's reseating semantics.
以这种方式使用unique_ptr可以从文档和实现两个方面强制函数调用的重置语义。
Note(注意)
"reseat" means "making a pointer or a smart pointer refer to a different object."
“重置”的意思是使指针或者智能指针参照另外一个对象。
Example(示例)
Example, bad(反面示例)
Enforcement(实施建议)
- (Simple) Warn if a function takes a Unique_pointer<T> parameter by lvalue reference and does not either assign to it or call reset() on it on at least one code path. Suggest taking a T* or T& instead.
- (简单)如果一个函数以左值引用方式使用了Unique_pointer<T>类型参数,却没有至少一个代码路径上对它赋值或者调用reset方法,提出警告。建议改用T*或者T& 。
- (Simple) ((Foundation)) Warn if a function takes a Unique_pointer<T> parameter by reference to const. Suggest taking a const T* or const T& instead.
- (简单)((基础))如果一个函数以常量引用形式使用了Unique_pointer<T>参数,提出警告。建议改用const T* 或 const T&。
原文链接
觉得本文有帮助?欢迎点赞并享给更多的人。
阅读更多更新文章,请关注微信公众号【面向对象思考】
 
 
                     
            
        













 
                    

 
                 
                    