Skip to content

Commit

Permalink
[DSSv3] Fix Issue #21100: Add data() function to std.container.array.…
Browse files Browse the repository at this point in the history
…Array (dlang#8174)

[DSSv3] Fix Issue #21100: Add data() function to std.container.array.Array

Signed-off-by: Max Haughton <[email protected]>
Merged-on-behalf-of: Max Haughton <[email protected]>
  • Loading branch information
dandrei279 authored Jul 21, 2021
1 parent 220e922 commit 11bf097
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions std/container/array.d
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,17 @@ if (!is(immutable T == immutable bool))
return _data.refCountedStore.isInitialized ? _data._capacity : 0;
}

/**
* Returns: the internal representation of the array.
*
* Complexity: $(BIGOH 1).
*/

T[] data() @system
{
return _data._payload;
}

/**
* Ensures sufficient capacity to accommodate `e` _elements.
* If `e < capacity`, this method does nothing.
Expand Down Expand Up @@ -2601,3 +2612,12 @@ if (is(immutable T == immutable bool))
GC.collect();
arr[1].func();
}

@system unittest
{
Array!int arr = [1, 2, 4, 5];
int[] data = arr.data();

data[0] = 0;
assert(arr[0] == 0);
}

0 comments on commit 11bf097

Please sign in to comment.