mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-20 08:58:00 +02:00
System.Index support
This commit is contained in:
parent
27fd5552cc
commit
05a65287d3
3 changed files with 124 additions and 1 deletions
|
@ -260,6 +260,35 @@ namespace System
|
|||
}
|
||||
}
|
||||
|
||||
public ref T this[Index index]
|
||||
{
|
||||
[Checked, Inline]
|
||||
get
|
||||
{
|
||||
int idx;
|
||||
switch (index)
|
||||
{
|
||||
case .FromFront(let offset): idx = offset;
|
||||
case .FromEnd(let offset): idx = mLength - 1 - offset;
|
||||
}
|
||||
if ((uint)idx >= (uint)mLength)
|
||||
Internal.ThrowIndexOutOfRange(1);
|
||||
return ref (&mFirstElement)[idx];
|
||||
}
|
||||
|
||||
[Unchecked, Inline]
|
||||
get
|
||||
{
|
||||
int idx;
|
||||
switch (index)
|
||||
{
|
||||
case .FromFront(let offset): idx = offset;
|
||||
case .FromEnd(let offset): idx = mLength - 1 - offset;
|
||||
}
|
||||
return ref (&mFirstElement)[idx];
|
||||
}
|
||||
}
|
||||
|
||||
public Span<T> this[IndexRange range]
|
||||
{
|
||||
#if !DEBUG
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue