Description
Inserts Count default-constructed elements at Index, shifting existing elements right. Unlike InsertZeroed, this calls the element's default constructor via DefaultConstructItems, making it safe for non-trivial types.
Caveats & Gotchas
- • For types where the default constructor does nothing (plain C structs without a constructor), this is equivalent to InsertUninitialized — not InsertZeroed. If you need a zero state for such types, use InsertZeroed instead.
- • Mid-array insertion shifts all elements after Index and is O(N). For large arrays with frequent insertions, consider appending to the end and sorting, or using a different container.
Signature
void InsertDefaulted(SizeType Index, SizeType Count = 1) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Index | SizeType | Position at which to insert the new default-constructed elements. | — |
| Count | SizeType | Number of elements to insert. | 1 |
Return Type
void Example
Insert placeholder entries into a structured list C++
TArray<FString> Names;
Names.Add(TEXT("Alice"));
Names.Add(TEXT("Charlie"));
// Insert a default (empty) FString between Alice and Charlie
Names.InsertDefaulted(1);
Names[1] = TEXT("Bob"); // Names is now {Alice, Bob, Charlie} Tags
Version History
Introduced in: 4.20
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?