microsoft / GSL

Guidelines Support Library
Other
6.13k stars 737 forks source link

gsl::at variadic version #1072

Closed JaroPaska closed 1 year ago

JaroPaska commented 1 year ago

SL.Con.3 encourages the use bounds-checked functions such as .at() and gsl::at() over the use of operator[]. However, this becomes inconvenient when trying to access values inside multi-dimensional arrays.

For example, assume we have a 3-dimensional array named memo, which caches the values for some expensive function. To access a value, we would need to write memo.at(x).at(y).at(z), or at(at(at(memo, x), y), z) when using the GSL function. By using the new variadic template, we can simply write at(memo, x, y, z).

JaroPaska commented 1 year ago

@microsoft-github-policy-service agree

beinhaerter commented 1 year ago

Related: https://github.com/isocpp/CppCoreGuidelines/issues/2013

dmitrykobets-msft commented 1 year ago

Hi @JaroPaska, thanks for the PR. I'll wait for the decision on the related CoreGuidelines issue.

dmitrykobets-msft commented 1 year ago

closing as per the coreguidelines issue.