This is a new site that's currently running on alpha code. There are going to be bugs. If you discover any, please report them on the site's issues page (GitHub account required). Thanks.
Warning: Many URLs are going to change. Refer to the README file to discover which library project's documentation has been completed.
Project: Array Utilities Unit
Unit: DelphiDabbler.Lib.ArrayUtils
Record: TArrayUtils
Applies to: ~>0.1
class function Pop<T>(var A: TArray<T>): T;
static;
Removes and returns the last element from a non-empty array.
The length of the array is reduced by one.
Parameters:
Returns:
Preconditions:
This example pops elements from an array until the array is empty.
procedure Pop_Eg;
var
A, Expected: TArray<string>;
begin
A := TArray<string>.Create('a', 'stitch', 'in', 'time');
Expected := TArray<string>.Create('a', 'stitch', 'in');
Assert(TArrayUtils.Pop<string>(A) = 'time');
Assert(TArrayUtils.Equal<string>(Expected, A, SameStr));
Expected := TArray<string>.Create('a', 'stitch');
Assert(TArrayUtils.Pop<string>(A) = 'in');
Assert(TArrayUtils.Equal<string>(Expected, A, SameStr));
Expected := TArray<string>.Create('a');
Assert(TArrayUtils.Pop<string>(A) = 'stitch');
Assert(TArrayUtils.Equal<string>(Expected, A, SameStr));
Expected := TArray<string>.Create();
Assert(TArrayUtils.Pop<string>(A) = 'a');
Assert(TArrayUtils.Equal<string>(Expected, A, SameStr));
end;