microsoft / GSL

Guidelines Support Library
Other
6.22k stars 740 forks source link

span::operator() #424

Closed MikeGitb closed 8 years ago

MikeGitb commented 8 years ago

What is the purpose of / usecase for span::operator()? As it seems to have the same functionality as operator[] I wonder if it wouldn't be better to remove it.

The paper span: bounds-safe views for sequences of objects mentions compatibility with code written against view, but I wasn't able to determine, what that is.

neilmacintosh commented 8 years ago

@MikeGitb span::operator() exists to provide basic compatibility (i.e. copy-paste some code and it should still mostly work ;-)) with a multi-dimensional span-type. view was the name being used by the authors of a paper proposing such a type for standardization. They have now switched to mdspan until a final name is hit upon.

Such a type is likely to use operator() as a convenient way to express indexers. multi_span is an example of what such a type might roughly look like, but it does not track their proposal (having evolved from a different beginning).

If you'd like to dig into more details, here is the paper currently before the standardization committee that suggests a minimal definition of a multidimensional span.

I'm happy to keep operator() in place for now, especially as it provides an alternative notation for indexing that might be useful for some users who want to write generic algorithms across both multi- and single- dimensional spans.

MikeGitb commented 8 years ago

Thanks for the explanation.