dsharlet / array

C++ multidimensional arrays in the spirit of the STL
Apache License 2.0
198 stars 15 forks source link

Use helper class for individual compile-time constants #1

Closed dsharlet closed 4 years ago

dsharlet commented 4 years ago

Currently, dim has 3 template parameter compile-time constants. Each of these is implemented manually, resulting in a ~3x code duplication.

More importantly, methods like shape::min, shape::extent, and shape::stride lose compile-time constants, because they are simply instances of std::tuple<index_t, ...>.

This could be avoided if dim::min, dim::extent, etc. returned a constant<Value = UNK> object, and would reduce the code duplication.

The downside is errors would become less clear, and it would require implicit conversions from the new object to index_t for many basic operations, and might be annoying if it fails in some cases, or require a lot of operator overloading to implement <, <=, etc.