R.23: Use make_unique() to make unique_ptrs

R.23: 使用make_unique构建unique_ptr

 

Reason(原因)

For convenience and consistency with shared_ptr.

出于习惯。保持和shared_ptr用法的一致性。

 

Note(注意)

make_unique() is C++14, but widely available (as well as simple to write).

make_unique()是C++14引入的功能,但是可以广泛使用(也很容易自己写一个)

 

Enforcement(实施建议)

(Simple) Warn if a unique_ptr is constructed from the result of new rather than make_unique.

(简单)如果unique_ptr从new得到的结果构建而不是使用make_uinque,报警。

 

原文链接

​https:///isocpp/CppCoreGuidelines/blob/master/#r23-use-make_unique-to-make-unique_ptrs​


 

觉得本文有帮助?欢迎点赞并分享给更多的人。

阅读更多更新文章,请关注微信公众号【面向对象思考】