-4

I was going through self learning of std::make_unique functionality where I found the below declaration at cppreference.com

template< class T, class... Args >
unique_ptr<T> make_unique( Args&&... args );

I am completely not able to understand the signature of the method / function above.

F.M.F.
  • 1,929
  • 3
  • 23
  • 42
Programmer
  • 8,303
  • 23
  • 78
  • 162
  • 1
    Your second question makes this too broad. Why are you trying to learn every new feature? – Tas Jul 26 '17 at 05:09
  • 2
    FYI though: https://isocpp.org/files/papers/p0636r0.html – Tas Jul 26 '17 at 05:10
  • No - not all but at least what they are like how I learned C++ 98 similarly I wish to advance my skills to the new level by step by step practice by practice like the same way I learned C++ 98 – Programmer Jul 26 '17 at 05:14
  • 2
    Read about [parameter packs](http://en.cppreference.com/w/cpp/language/parameter_pack) for [variadic templates](https://en.wikipedia.org/wiki/Variadic_template). But you should take several days to read some [good C++11 programming book](https://stackoverflow.com/q/388242/841108). Asking questions for every new features of C++ is inappropriate here. – Basile Starynkevitch Jul 26 '17 at 05:15
  • 1
    Read [this](http://thbecker.net/articles/rvalue_references/section_01.html) article by Thomas Becker explaining move semantics and rvalue references. – Paul Rooney Jul 26 '17 at 05:22

1 Answers1

2

There are many "new" features used in this declaration:

Basically the code means "declare a template for functions with an arbitrary number of parameters of any type and return a unique_ptr specialised for the given type T". In addition the rvalue reference (&&) tells you that the parameters will be moved instead of copied.

In short: make_unique<Type>(v) is basically the same as unique_ptr<Type>(new Type(v)).

Andreas H.
  • 1,757
  • 12
  • 24
  • 1
    The main value of C++14's ``std::make_unique`` in addition to being both convenient and an equivalent to C++11's ``std::make_shared`` is that exception handling semantics are clearer if the ``new`` throws vs. the ctor throws. The only downside is that Visual Studio IntelliSense isn't as helpful as it could be with the parameters. – Chuck Walbourn Jul 26 '17 at 06:19