diff --git a/doc/smart_ptr/make_shared.adoc b/doc/smart_ptr/make_shared.adoc index 350b8b5..662a05c 100644 --- a/doc/smart_ptr/make_shared.adoc +++ b/doc/smart_ptr/make_shared.adoc @@ -271,10 +271,7 @@ Remarks::: These overloads shall only participate in overload resolution when `T` is not an array type, or an array type of the `__U__[__N__]`. Returns::: A `shared_ptr` to a default-initialized object of type `T`, or a sequence of `_N_` default-initialized objects of type `_U_`, respectively. -Examples::: -* `struct X { double data[1024]; }; + - auto p = make_shared_noinit();` -* `auto p = make_shared_noinit();` +Example::: `auto p = make_shared_noinit();` ``` template diff --git a/doc/smart_ptr/make_unique.adoc b/doc/smart_ptr/make_unique.adoc index 5caf392..13d247c 100644 --- a/doc/smart_ptr/make_unique.adoc +++ b/doc/smart_ptr/make_unique.adoc @@ -1,5 +1,6 @@ //// Copyright 2017 Peter Dimov +Copyright 2017 Glen Joseph Fernandes (glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. @@ -13,3 +14,100 @@ http://www.boost.org/LICENSE_1_0.txt :toc-title: :idprefix: make_unique_ +## Description + +The `make_unique` function templates provide convenient and safe ways to +create `std::unique_ptr` objects. + +## Rationale + +The C$$++$$11 standard introduced `std::unique_ptr` but did not provide any +`make_unique` utility like `std::make_shared` that provided the same +exception safety and facility to avoid writing `new` expressions. Before it +was implemented by some standard library vendors (and prior to the C$$++$$14 +standard introducing `std::make_unique`), this library provided it due to +requests from users. + +This library also provides additional overloads of `make_unique` for +default-initialization, when users do not need or want to incur the expense +of value-initialization. The C$$++$$ standard does not yet provide this +feature with `std::make_unique`. + +## Synopsis + +`make_unique` is defined in ``. + +[subs=+quotes] +``` +namespace boost { + template + std::unique_ptr make_unique(Args&&... args); + + template + std::unique_ptr make_unique(_see below_ v); + + template + std::unique_ptr make_shared(std::size_t n); + + template + std::unique_ptr make_shared_noinit(); + + template + std::unique_ptr make_shared_noinit(std::size_t n); +} +``` + +## Free Functions + +``` +template + std::unique_ptr make_unique(Args&&... args); +``` +:: +Remarks::: These overloads shall only participate in overload resolution when +`T` is not an array type. +Returns::: `std::unique_ptr(new T(std::forward(args)$$...$$)`. +Example::: `auto p = make_unique();` + +[subs=+quotes] +``` +template + std::unique_ptr make_unique(_see below_ v); +``` +:: +Remarks::: +* These overloads shall only participate in overload resolution when `T` is +not an array type. +* The type of `v` is `std::remove_reference_t&&`. +Returns::: `std::unique_ptr(new T(std::move(v))`. +Example::: `auto p = make_unique >({1, 2});` + +``` +template + std::unique_ptr make_unique(std::size_t n); +``` +:: +Remarks::: These overloads shall only participate in overload resolution when +`T` is an array type of the form `__U__[]`. +Returns::: `std::unique_ptr<__U__[]>(new __U__[n]())`. +Example::: `auto p = make_unique(1024);` + +``` +template + std::unique_ptr make_unique_noinit(); +``` +:: +Remarks::: These overloads shall only participate in overload resolution when +`T` is not an array type. +Returns::: `std::unique_ptr(new T)`. +Example::: `auto p = make_unique_noinit();` + +``` +template + std::unique_ptr make_unique_noinit(std::size_t n); +``` +:: +Remarks::: These overloads shall only participate in overload resolution when +`T` is an array type of the form `__U__[]`. +Returns::: `std::unique_ptr<__U__[]>(new __U__[n])`. +Example::: `auto p = make_unique_noinit(1024);` \ No newline at end of file