Nullptr in Array/OwnedArray


#1

Is it possible to have nullptr in an OwnedArray, between elements that are valid, or do i have to create a special “invalid” element for comparison if the slot is “empty” or “taken” in the array ?


#2

An Array can certainly hold pointer types, where elements may be nullptr. This idea only works with value semantics, though.

Edit: Scrapped the last bit I wrote; you can delete nullptr in C++, with little fuss - depending on the compiler (MSVC checks for null pointers in its delete). I guess you can pass in nullptr to add items to OwnedArray!


#3

That’s my question i need to poke “holes” in my OwnedArray and make sure i don’t loose the indexing of the elements (so that the rules where the array will shring/expand apply).


#4

Yes, OwnedArrays can contain nullptrs.

Yes, but it’s not compiler-dependent. Being able to delete a nullptr safely has always been required by the C++ standard, and will work in any compiler.


#5

Ah, okay… I was reading up on StackOverflow and that’s what I gathered.