C++核心準則R.23: 使用make_unique構建unique_ptr

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://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#r23-use-make_unique-to-make-unique_ptrs


 

覺得本文有幫助?歡迎點贊並分享給更多的人。

閱讀更多更新文章,請關注微信公衆號【面向對象思考】

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章