dsharlet / array

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

Find a good syntax for expressing ranges #25

Closed dsharlet closed 4 years ago

dsharlet commented 4 years ago

The current interval/range syntax is pretty verbose. It would be great to be able to write something like a(x0:x1, y0:y1, z) to crop x, y and slice z, similar to numpy style. In C++ we are more limited. The current syntax is something like a(interval(x0, x1), interval(y0, y1), z), or a(range<>(x0, x1 - x0), range<>(y0, y1 - y0), z).

Possible options I can think of are:

Some additional thoughts:

jiawen commented 4 years ago

How about:

nda::all() or nda::slice() can also be shorthands the equivalent of ":" in Python when reading.

dsharlet commented 4 years ago

I decided to go ahead and use your suggestion. I already had a function interval that was exactly your suggestion, and range was the object that interval produced. I basically swapped those names, and added r to make it less verbose.

I also added all, which is an alias for _, which already existed.

dsharlet commented 4 years ago

I'm going to close this because this is C++ and I don't see any realistic and not ultra-hacky way to make this any better than short function names.