Tuesday, October 3, 2017

C++14: std::make_unique

C++14 added the make_unique template function to construct an object and wrap a unique_ptr around it. Here is an example:

#include <memory>

int main()
{
  std::unique_ptr<int  > myInt      = std::make_unique<int  >(42);
  std::unique_ptr<int[]> myIntArray = std::make_unique<int[]>(42);
  
  return 0;
}
Reference: http://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique

No comments:

Post a Comment