r/learncpp • • Jun 25 '20

list of c style arrays

Hey. In my code implementation i have something like this

struct MYTABLE
{
int table[NUMBER][NUMBER];
}

where NUMBER is a constant and is decided in compile time with a define.

After some calculations i have a number of results that i'd like to store. These number of results are varied dependent on the size of the matrix (the bigger the NUMBER the more i get).

Is there an solution where i can make something like this:

std::list<MYTABLE> result_set;

result_set later needs to be iterated trough and picked out results that are each others mirrors, rotations etc
Thank you!

1 Upvotes

8 comments sorted by

View all comments

Show parent comment

3

u/jedwardsol Jun 25 '20 edited Jun 25 '20

Ah, you're trying to put an array in the list, not a struct which has an array as a member. Although they're superficially very similar, they're pretty different in what operations the language allows to be performed upon them.

3 suggestions

  • Copy A (the array) into a struct (my_table) and then insert the struct into the list.
  • Change A from an array to a my_table.
  • Get rid of raw arrays and the my_table struct. Pass around std::arrays

The last can be done with

 using my_table = std::array<std::array<int,4>, 4>;

and continue using the my_table type everywhere.

1

u/omen_tenebris Jun 25 '20

i think i'm starting to understand.

thank you so much

1

u/omen_tenebris Jun 25 '20

holly shit the first solution worked!

you're a god dude thank you so much. This piece of shit program have been plaguing me for so ling finally i can move ahead a little