microsoft / GSL

Guidelines Support Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do we use gsl::at with multi-dimension arrays?

ajtruckle opened this issue · comments

At the moment I have:

if( aryUIntSynchData[iPTS][iCol])

Up until now the arrays I have been porting are one dimension, e.g:

if(gsl::at(array, index))

How do we write this for a two dimensional array?

You can write gsl::at(gsl::at(aryUIntSynchData, iPTS), iCol).

It does not like that:
Error2

It would be nice if we could simply do:

if(gsl::at(aryUIntSynchData, iPTS, iCol))

The code works for raw arrays:

#include <gsl/gsl>

void f()
{
	int aryUIntSynchData[14][14]{};
	int iPTS{}, iCol{};
	if (aryUIntSynchData[iPTS][iCol]) {}
	if (gsl::at(gsl::at(aryUIntSynchData, iPTS), iCol)) {}
 }

If you use MFC's CUIntArray you should have mentioned this in the first place. It is a relevant part of the question. So: what is the exact type of aryUIntSynchData?

You can try gsl::at(aryUIntSynchData, iPTS)[iCol].

@beinhaerter I am really sorry that I overlooked that important clarification!

what is the exact type of aryUIntSynchData?

It is:
CUIntArray aryUIntSynchData[to_underlying(CPTSDatabase::Sync::Count)];
I just tried your suggestion and I get no warnings. Thanks.