1.. title:: clang-tidy - modernize-make-unique 2 3modernize-make-unique 4===================== 5 6This check finds the creation of ``std::unique_ptr`` objects by explicitly 7calling the constructor and a ``new`` expression, and replaces it with a call 8to ``std::make_unique``, introduced in C++14. 9 10.. code-block:: c++ 11 12 auto my_ptr = std::unique_ptr<MyPair>(new MyPair(1, 2)); 13 14 // becomes 15 16 auto my_ptr = std::make_unique<MyPair>(1, 2); 17 18This check also finds calls to ``std::unique_ptr::reset()`` with a ``new`` 19expression, and replaces it with a call to ``std::make_unique``. 20 21.. code-block:: c++ 22 23 my_ptr.reset(new MyPair(1, 2)); 24 25 // becomes 26 27 my_ptr = std::make_unique<MyPair>(1, 2); 28 29Options 30------- 31 32.. option:: MakeSmartPtrFunction 33 34 A string specifying the name of make-unique-ptr function. Default is 35 `std::make_unique`. 36 37.. option:: MakeSmartPtrFunctionHeader 38 39 A string specifying the corresponding header of make-unique-ptr function. 40 Default is `<memory>`. 41 42.. option:: IncludeStyle 43 44 A string specifying which include-style is used, `llvm` or `google`. Default 45 is `llvm`. 46 47.. option:: IgnoreMacros 48 49 If set to `true`, the check will not give warnings inside macros. Default 50 is `true`. 51 52.. option:: IgnoreDefaultInitialization 53 54 If set to non-zero, the check does not suggest edits that will transform 55 default initialization into value initialization, as this can cause 56 performance regressions. Default is `1`. 57