Welcome to the new DelphiDabbler Code Library Documentation.

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.

CopyReversed<T> class method

Project: Array Utilities Unit

Unit: DelphiDabbler.Lib.ArrayUtils

Record: TArrayUtils

Applies to: ~>0.1

class function CopyReversed<T>(const A: array of T): TArray<T>;
  static;

Description

Returns a reversed copy of the elements of a given array.

The copy is a shallow copy, so any references within the resulting array are the same as those in the initial array.

Parameters:

Returns:

Note

If a deep copy of the reversed array is required, pass the return value of CopyReversed<T> to the deep copying overload of Copy<T> along with a suitable TCloner<T> implementation.

Example

procedure CopyReversed_Eg;
var
  A, R, Expected: TArray<Integer>;
begin
  A := TArray<Integer>.Create(0, 99, 42, 56);
  R := TArrayUtils.CopyReversed<Integer>(A);
  Expected := TArray<Integer>.Create(56, 42, 99, 0);
  Assert(TArrayUtils.Equal<Integer>(Expected, R));
end;

See Also