Skip to content

Commit 6864a9f

Browse files
Clarify the status of dyn_array (isocpp#2243)
1 parent 8a59841 commit 6864a9f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

CppCoreGuidelines.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21326,7 +21326,7 @@ Use `not_null<zstring>` for C-style strings that cannot be `nullptr`. ??? Do we
2132621326
* `unique_ptr<T>` // unique ownership: `std::unique_ptr<T>`
2132721327
* `shared_ptr<T>` // shared ownership: `std::shared_ptr<T>` (a counted pointer)
2132821328
* `stack_array<T>` // A stack-allocated array. The number of elements is determined at construction and fixed thereafter. The elements are mutable unless `T` is a `const` type.
21329-
* `dyn_array<T>` // ??? needed ??? A heap-allocated array. The number of elements is determined at construction and fixed thereafter.
21329+
* `dyn_array<T>` // A container, non-growing dynamically allocated array. The number of elements is determined at construction and fixed thereafter.
2133021330
The elements are mutable unless `T` is a `const` type. Basically a `span` that allocates and owns its elements.
2133121331

2133221332
## <a name="SS-assertions"></a>GSL.assert: Assertions
@@ -22162,7 +22162,8 @@ No. `stack_array` is guaranteed to be allocated on the stack. Although a `std::a
2216222162

2216322163
### <a name="Faq-gsl-dyn-array"></a>FAQ.58: Is `dyn_array` the same as `vector` or the proposed `dynarray`?
2216422164

22165-
No. `dyn_array` is not resizable, and is a safe way to refer to a heap-allocated fixed-size array. Unlike `vector`, it is intended to replace array-`new[]`. Unlike the `dynarray` that has been proposed in the committee, this does not anticipate compiler/language magic to somehow allocate it on the stack when it is a member of an object that is allocated on the stack; it simply refers to a "dynamic" or heap-based array.
22165+
No. `dyn_array` is a container, like `vector`, but it is not resizable; its size is fixed at runtime when it is constructed.
22166+
It is a safe way to refer to a dynamically "heap"-allocated fixed-size array. Unlike `vector`, it is intended to replace array-`new[]`. Unlike the `dynarray` that has been proposed in the committee, this does not anticipate compiler/language magic to somehow allocate it on the stack when it is a member of an object that is allocated on the stack; it simply refers to a "dynamic" or heap-based array.
2216622167

2216722168
### <a name="Faq-gsl-expects"></a>FAQ.59: Is `Expects` the same as `assert`?
2216822169

0 commit comments

Comments
 (0)