mirror of
https://github.com/WerWolv/ImHex-Patterns.git
synced 2026-03-27 23:37:04 -05:00
Docs: describe how to create multidimensional std::Array (#407)
doc: descirbe how to create multidimensional std::Array Co-authored-by: paxcut <53811119+paxcut@users.noreply.github.com>
This commit is contained in:
@@ -6,6 +6,22 @@ import std.core;
|
||||
/*!
|
||||
The array library contains a helper type to make it easier to create multi-dimensional arrays
|
||||
and pass arrays to functions as parameters.
|
||||
|
||||
## Multi-dimensional arrays
|
||||
|
||||
The following example shows how to use multi-dimensional arrays with structs.
|
||||
|
||||
```rust
|
||||
import std.array;
|
||||
|
||||
struct File {
|
||||
u8 width, height;
|
||||
std::Array<std::Array<u8, parent.width>, height> cells;
|
||||
};
|
||||
|
||||
File file @ 0x00;
|
||||
```
|
||||
|
||||
*/
|
||||
|
||||
namespace auto std {
|
||||
@@ -27,7 +43,7 @@ namespace auto std {
|
||||
struct ByteSizedArray<T, auto NumBytes> {
|
||||
u64 startAddress = $;
|
||||
T array[while($ - startAddress < NumBytes)] [[inline]];
|
||||
|
||||
|
||||
std::assert($ - startAddress == NumBytes, "Not enough bytes available to fit a whole number of types");
|
||||
} [[format("std::impl::format_array")]];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user