Skip to content

Getting the indexes of a 2D array #1958

Answered by paxcut
iain-waugh asked this question in Get Help
Discussion options

You must be logged in to vote

You have defined the 2d array as an array of an array so there are two indices that need to be dealt with. You could also define the 2-d array as an array of rows*columnsentries so I'll write the code to implement the case you posted and write all the details needed to use one index only.

The following code is a possible implementation of the two indices approach. It has been tested on some random data and it appears to work as expected as shown in the image below.

import std.array;

const u32 rows =4;
const u32 columns = 5;

struct Data {
  u16 slice_header;
  std::print("Row {}, Column {} :    Slice header {} ",std::core::array_index(), parent.parent.sliceIndex,slice_header );
  // std:…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@iain-waugh
Comment options

Answer selected by iain-waugh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants