diff --git a/make_shared_array.html b/make_shared_array.html index e7d80d4..76e4f20 100644 --- a/make_shared_array.html +++ b/make_shared_array.html @@ -8,13 +8,13 @@
make_shared and allocate_shared
for arraysIntroduction
- Synopsis
+
Introduction
+ Synopsis
+ Common Requirements
Free Functions
- Examples
History
References
Originally the Boost function templates make_shared and
allocate_shared were for efficient allocation of shared
objects only. There was a need to have efficient allocation of
@@ -28,24 +28,24 @@
make_shared uses the global operator new to
allocate memory, whereas allocate_shared uses an
user-supplied allocator, allowing finer control.
namespace boost {
template<typename U> // U is T[]
shared_ptr<U> make_shared(size_t size);
template<typename U, typename A> // U is T[]
shared_ptr<U> allocate_shared(const A& allocator, size_t size);
-
+
template<typename U> // U is T[N]
shared_ptr<U> make_shared();
template<typename U, typename A> // U is T[N]
shared_ptr<U> allocate_shared(const A& allocator);
-
+
template<typename U> // U is T[]
shared_ptr<U> make_shared(size_t size, const T& value);
- template<typename U, typename A> // U is T[]
+ template<typename U, typename A> // U is T[]
shared_ptr<U> allocate_shared(const A& allocator, size_t size, const T& value);
template<typename U> // U is T[N]
@@ -66,95 +66,183 @@
template<typename U, typename A> // U is T[N]
shared_ptr<U> allocate_shared_noinit(const A& allocator);
}
- template<typename U> // U is T[] -shared_ptr<U> make_shared(size_t size); - -template<typename U, typename A> // U is T[] -shared_ptr<U> allocate_shared(const A& allocator, size_t size); - -template<typename U> // U is T[N] -shared_ptr<U> make_shared(); - -template<typename U, typename A> // U is T[N] -shared_ptr<U> allocate_shared(const A& allocator);+
template<typename U> + shared_ptr<U> make_shared(args); +template<typename U, typename A> + shared_ptr<U> allocate_shared(const A& allocator, args); +template<typename U> + shared_ptr<U> make_shared_noinit(args); +template<typename U, typename A> + shared_ptr<U> allocate_shared_noinit(const A& allocator, args);
--Requires: The expression -
-new(pointer) T(), wherepointeris a -void*pointing to storage suitable to hold an object of - typeT, shall be well-formed.Ashall be an - Allocator, as described in section 20.1.5 (Allocator - requirements) of the C++ Standard. The copy constructor and - destructor ofAshall not throw.Effects: Allocates memory suitable for an array of type -
+Tand sizesizeand constructs an array of - objects in it via the placement new expressionnew(pointer) - T().allocate_shareduses a copy of -allocatorto allocate memory. If an exception is thrown, - has no effect.Requires:
+Uis of the formT[]or +T[N].Ashall be an Allocator, as + described in section 17.6.3.5 [Allocator + requirements] of the C++ Standard. The copy constructor and + destructor ofAshall not throw exceptions.Effects: Allocates memory for an object of type
U+ (orT[size]whenUisT[], + wheresizeis determined fromargs+ as specified by the concrete overload). The object is initialized as + specified by the concrete overload. The templates +allocate_sharedandallocate_shared_noinit+ use a copy ofallocatorto allocate memory. If an + exception is thrown, the functions have no effect.Returns: A
-shared_ptrinstance that stores and - owns the address of the newly constructed array of typeT- and sizesize.Postconditions: -
-get() != 0 && use_count() == 1.Throws:
-bad_alloc, or an exception thrown from -A::allocateor the constructor ofT.Notes: This implementation allocates the memory required for - the returned
-shared_ptrand an array of type -Tof sizesizein a single allocation. This - provides efficiency to equivalent to an intrusive smart pointer.
template<typename U> // U is T[] -shared_ptr<U> make_shared(size_t size, const T& value); - -template<typename U, typename A> // U is T[] -shared_ptr<U> allocate_shared(const A& allocator, size_t size, const T& value); - -template<typename U> // U is T[N] -shared_ptr<U> make_shared(const T& value); - -template<typename U, typename A> // U is T[N] -shared_ptr<U> allocate_shared(const A& allocator, const T& value);-
--Notes: These overloads initialize array objects with the given + owns the address of the newly constructed object.
+Postconditions:
+r.get() != 0 && + r.use_count() == 1, whereris the return value.Throws:
bad_alloc, an exception thrown from +A::allocate, or from the initialization of the + object.
template<typename U> // U is T[] -shared_ptr<U> make_shared_noinit(size_t size); - -template<typename U, typename A> // U is T[] -shared_ptr<U> allocate_shared_noinit(const A& allocator, size_t size); - -template<typename U> // U is T[N] -shared_ptr<U> make_shared_noinit(); - -template<typename U, typename A> // U is T[N] -shared_ptr<U> allocate_shared_noinit(const A& allocator);
--Notes: These overloads do not perform value initialization of - array objects.
-
The following examples value-initialize objects.
---boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>(size); -boost::shared_ptr<int[8]> a2 = boost::make_shared<int[8]>(); -boost::shared_ptr<int[][2]> a3 = boost::make_shared<int[][2]>(size); -boost::shared_ptr<int[4][2]> a4 = boost::make_shared<int[4][2]>();+Remarks:
++This implementation performs no more than one memory + allocation. This provides efficiency to equivalent to an intrusive + smart pointer.
+When an object of an array type
+Tis specified to be + initialized to a value of the same typevalue, this + shall be interpreted to mean that each array element of the object + is initialized to the corresponding element from +value.When an object of an array type is specified to be + value-initialized, this shall be interpreted to mean that each + array element of the object is value-initialized.
+Array elements are initialized in ascending order of their + addresses.
+When a subobject of a non-array type
+Tis specified to + be initialized to a valuevalue, or to +T(list...), wherelist...is a list of + constructor arguments,make_sharedshall perform this + initialization via the expression::new(ptr) T(value)+ or::new(ptr) T(list...)respectively, where +ptrhas typevoid*and points to storage + suitable to hold an object of typeT.When a subobject of non-array type
+Tis specified to + be value-initialized,make_sharedshall perform this + initialization via the expression::new(ptr) T(), where +ptrhas typevoid*and points to storage + suitable to hold an object of typeT.When a subobject of non-array type
+Tis specified to + be default-initialized,make_shared_noinitand +allocate_shared_noinitshall perform this + initialization via the expression::new(ptr) T, where +ptrhas typevoid*and points to storage + suitable to hold an object of typeT.When the lifetime of the object managed by the return value ends, + or when the initialization of an array element throws an exception, + the initialized elements should be destroyed in the reverse order + of their construction.
+
The following examples initialize objects with a given value.
+template<typename U> + shared_ptr<U> make_shared(size_t size); +template<typename U, typename A> + shared_ptr<U> allocate_shared(const A& allocator, size_t size);
--boost::shared_ptr<int[]> a5 = boost::make_shared<int[]>(size, 1); -boost::shared_ptr<int[8]> a6 = boost::make_shared<int[8]>(1); -boost::shared_ptr<int[][2]> a7 = boost::make_shared<int[][2]>(size, {1, 2}); -boost::shared_ptr<int[4][2]> a8 = boost::make_shared<int[4][2]>({1, 2});+Returns: A
+shared_ptrto a value-initialized + object of typeT[size].Remarks: These overloads shall only participate in overload + resolution when
Uis of the formT[].
The following examples default-initialize objects.
-+boost::shared_ptr<int[]> a9 = boost::make_shared_noinit<int[]>(size); -boost::shared_ptr<int[8]> a10 = boost::make_shared_noinit<int[8]>(); -boost::shared_ptr<int[][2]> a11 = boost::make_shared_noinit<int[][2]>(size); -boost::shared_ptr<int[4][2]> a12 = boost::make_shared_noinit<int[4][2]>();+Examples:
+++boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>(size); +boost::shared_ptr<int[][2]> a2 = boost::make_shared<int[][2]>(size);+
template<typename U> + shared_ptr<U> make_shared(); +template<typename U, typename A> + shared_ptr<U> allocate_shared(const A& allocator);+
++Returns: A
+shared_ptrto a value-initialized + object of typeT[N].Remarks: These overloads shall only participate in overload + resolution when
+Uis of the formT[N].
++Examples:
+++boost::shared_ptr<int[8]> a1 = boost::make_shared<int[8]>(); +boost::shared_ptr<int[4][2]> a2 = boost::make_shared<int[4][2]>();+
template<typename U> + shared_ptr<U> make_shared(size_t size, const T& value); +template<typename U, typename A> + shared_ptr<U> allocate_shared(const A& allocator, size_t size, const T& value);+
++Returns: A
+shared_ptrto an object of type +T[size], where each array element of typeT+ is initialized tovalue.Remarks: These overloads shall only participate in overload + resolution when
+Uis of the formT[].
++Examples:
+++boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>(size, 1); +boost::shared_ptr<int[][2]> a2 = boost::make_shared<int[][2]>(size, {1, 2});+
template<typename U> + shared_ptr<U> make_shared(const T& value); +template<typename U, typename A> + shared_ptr<U> allocate_shared(const A& allocator, const T& value);+
++Returns: A
+shared_ptrto an object of type +T[N], where each array element of typeTis + initialized tovalue.Remarks: These overloads shall only participate in overload + resolution when
+Uis of the formT[N].
++Examples:
+++boost::shared_ptr<int[8]> a1 = boost::make_shared<int[8]>(1); +boost::shared_ptr<int[4][2]> a2 = boost::make_shared<int[4][2]>({1, 2});+
template<typename U> + shared_ptr<U> make_shared_noinit(size_t size); +template<typename U, typename A> + shared_ptr<U> allocate_shared_noinit(const A& allocator, size_t size);+
++Returns: A
+shared_ptrto a default-initialized + object of typeT[size].Remarks: These overloads shall only participate in overload + resolution when
+Uis of the formT[].
++Examples:
+++boost::shared_ptr<int[]> a1 = boost::make_shared_noinit<int[]>(size); +boost::shared_ptr<int[][2]> a2 = boost::make_shared_noinit<int[][2]>(size);+
template<typename U> + shared_ptr<U> make_shared_noinit(); +template<typename U, typename A> + shared_ptr<U> allocate_shared_noinit(const A& allocator);+
++Returns: A
+shared_ptrto a default-initialized + object of typeT[N].Remarks: These overloads shall only participate in overload + resolution when
+Uis of the formT[N].
+Examples:
++boost::shared_ptr<int[8]> a1 = boost::make_shared_noinit<int[8]>(); +boost::shared_ptr<int[4][2]> a2 = boost::make_shared_noinit<int[4][2]>();+
January 2014. Glen Fernandes reduced the overloads of make_shared and diff --git a/make_unique.html b/make_unique.html index 2d5544d..fc46428 100644 --- a/make_unique.html +++ b/make_unique.html @@ -7,16 +7,16 @@
make_uniqueIntroduction
- Synopsis
+
Introduction
+ Synopsis
+ Common Requirements
Free Functions
- Examples
History
The header file <boost/make_unique.hpp> provides overloaded
function template make_unique for convenient creation of
unique_ptr objects.
namespace boost {
template<typename U> // U is not array
unique_ptr<U> make_unique();
@@ -29,103 +29,127 @@
template<typename U> // U is not array
unique_ptr<U> make_unique(U&& value);
+ template<typename U> // U is T[]
+ unique_ptr<U> make_unique(size_t size);
+
template<typename U> // U is not array
unique_ptr<U> make_unique_noinit();
- template<typename U> // U is T[]
- unique_ptr<U> make_unique(size_t size);
-
template<typename U> // U is T[]
unique_ptr<U> make_unique_noinit(size_t size);
}
- template<typename U> // U is not array -unique_ptr<U> make_unique();+
template<typename U> + unique_ptr<U> make_unique(args); +template<typename U> + unique_ptr<U> make_unique_noinit(args);
--Requires: The expression
-new U()shall be - well-formed.Effects: Constructs an object of type
+Uvia the - expressionnew U().Effects: Allocates memory for an object of type
U+ (orT[size]whenUisT[], + wheresizeis determined fromargsas + specified by the concrete overload). The object is initialized from +argsas specified by the concrete overload. If an + exception is thrown, the functions have no effect.Returns: A
-unique_ptrinstance that stores and owns the address of the newly constructed object.Postconditions:
+get() != 0.Postconditions:
r.get() != 0, where +ris the return value.Throws:
+ the initialization of the object.bad_alloc, or an exception thrown from - the constructor ofU.
template<typename U, typename... Args> // U is not array -unique_ptr<U> make_unique(Args&&... args);
--Requires: The expression -
-new U(forward<Args>(args)...)shall be - well-formed.Effects: Constructs an object of type
+Uvia the - expressionnew U(forward<Args>(args)...).Remarks:
++When an object of a non-array type
+Tis specified to + be initialized to a valuevalue, or to +T(list...), wherelist...is a list of + constructor arguments,make_uniqueshall perform this + initialization via the expressionnew T(value)or +new T(list...)respectively.When an object of type
+Tis specified to be + value-initialized,make_uniqueshall perform this + initialization via the expressionnew T().When an object of type
+Tis specified to be + default-initialized,make_unique_noinitshall perform + this initialization via the expressionnew T.
template<typename U> // U is not array +Free Functions
+template<typename U, typename... Args> +unique_ptr<U> make_unique(Args&&... args);+++Returns: A unique_ptr to an object of type
+U, + initialized toU(forward<Args>(args)...).Remarks: This overload shall only participate in overload + resolution when
+Uis not an array type.++Examples:
+++unique_ptr<float> p1 = boost::make_unique<float>(); +unique_ptr<point> p2 = boost::make_unique<point>(x, y);+template<typename U> unique_ptr<U> make_unique(U&& value);--Requires: The expression
-new U(move(value))shall - be well-formed.Effects: Constructs an object of type
+Uvia the - expressionnew U(move(value)).Returns: A unique_ptr to an object of type
+U, + initialized tomove(value).Remarks: This overload shall only participate in overload + resolution when
Uis not an array type.template<typename U> // U is not array -unique_ptr<U> make_unique_noinit();--Requires: The expression
-new Ushall be - well-formed.Effects: Constructs an object of type
+Uvia the - expressionnew U.Examples:
++unique_ptr<string> p1 = boost::make_unique<string>({'a', 'b'}); +unique_ptr<point> p2 = boost::make_unique<point>({-10, 25});+template<typename U> // U is T[] -unique_ptr<U> make_unique(size_t size);+template<typename U> +unique_ptr<U> make_unique(size_t size);--Requires: The expression
-new T[size]()shall be - well-formed.Effects: Constructs an array of objects of type -
+Uand sizesizevia the expression -new T[size]().Returns: A unique_ptr to a value-initialized object of type +
+T[size].Remarks: This overload shall only participate in overload + resolution when
Uis of the formT[].template<typename U> // U is T[] -unique_ptr<U> make_unique_noinit(size_t size);--Requires: The expression
-new T[size]shall be - well-formed.Effects: Constructs an array of objects of type -
-Uand sizesizevia the expression -new T[size].Examples
-For objects with value-initialization.
---unique_ptr<float> p1 = boost::make_unique<float>(); -unique_ptr<point> p2 = boost::make_unique<point>();+Examples:
++unique_ptr<double[]> p1 = boost::make_unique<double[]>(4); +unique_ptr<int[][2]> p2 = boost::make_unique<int[][2]>(2);+For objects with construction arguments.
+template<typename U> +unique_ptr<U> make_unique_noinit();--unique_ptr<float> p3 = boost::make_unique<float>(1.0f); -unique_ptr<point> p4 = boost::make_unique<point>(x, y);+Returns: A unique_ptr to a default-initialized object of + type
+U.Remarks: This overload shall only participate in overload + resolution when
Uis not an array type.For objects with given value.
--unique_ptr<string> p4 = boost::make_unique<string>({'a', 'b'}); -unique_ptr<type> p5 = boost::make_unique<type>({3, 5, 4});+Examples:
++unique_ptr<float> p1 = boost::make_unique_noinit<float>(); +unique_ptr<point> p2 = boost::make_unique_noinit<point>();+For objects with default-initialization.
+template<typename U> +unique_ptr<U> make_unique_noinit(size_t size);--unique_ptr<float> p6 = boost::make_unique_noinit<float>(); -unique_ptr<point> p7 = boost::make_unique_noinit<point>();+Returns: A unique_ptr to a default-initialized object of + type
+T[size].Remarks: This overload shall only participate in overload + resolution when
Uis of the formT[].For arrays with value-initialization.
--unique_ptr<double[]> a1 = boost::make_unique<double[]>(); -unique_ptr<int[][4]> a2 = boost::make_unique<int[][4]>();+Examples:
++unique_ptr<double[]> p1 = boost::make_unique_noinit<double[]>(4); +unique_ptr<int[][2]> p2 = boost::make_unique_noinit<int[][2]>(2);+For arrays with default-initialization.
--unique_ptr<double[]> a3 = boost::make_unique_noinit<double[]>(); -unique_ptr<int[][4]> a4 = boost::make_unique_noinit<int[][4]>();-History
January 2014. Glen Fernandes contributed implementations of make_unique for objects and arrays.