Forwarding my private reply to the entire group... ---------- Forwarded message --------- Od: Andrzej Krzemienski <akrzemi1@gmail.com> Date: czw., 22 sty 2026 o 09:50 Subject: Re: [Boost.Multi] Initial feedback To: Alfredo Correa <alfredo.correa@gmail.com> czw., 22 sty 2026 o 04:08 Alfredo Correa <alfredo.correa@gmail.com> napisał(a):
On Wed, Jan 21, 2026 at 1:56 PM Andrzej Krzemienski <akrzemi1@gmail.com> wrote:
What do you mean by contract?
All the characteristics that are usually described when documenting the Standard Library functions: https://cppreference.com/w/cpp/utility/optional/transform.html
Like: return type, constraints, const/constexpr properties, postconditions. In this case, I was interested in what properties the returned range has: random-access, contiguous? I naturally expect that it is a contiguous range for multi::array and multi::array_ref, so I wanted to confirm that. I suppose it is different for subarrays. I can hardly imagine they would have the same range category.
return type: A custom `elements_type`, which is a random access range. for `multi::array` the type is `multi::subarray<T, 1>` because it can be contiguous.
no contraints, .elements() always returns something valid, even if the array is empty. it is constexpr. postcontions, nothing changes, .elements() is just another view.
I say this now: "As an alternative, the elements can be iterated in a flat manner, using the `.elements()` member. This "elements" range also provides the `begin` and `end` iterators (`.elements().begin()`) and indexing, in the canonical order of the original arrays (rightmost index changes fastest). The elements range is always random-access, but it can be contiguous depending on the original array (`multi::array` generally give contiguous element ranges.)"
In the reference section, ``` | `elements` | a flatted random-access view of all the elements rearranged canonically. `A.elements()[0] -> A[0][0]`, `A.elements()[1] -> A[0][1]`, etc. The type of the result is not a subarray but a special kind of random-access range. Takes no arguments. ```
And, later for array_ref, ``` | `elements` | a flatten random-access and contiguous view of all the elements in the array in canonical order. (This is overwritten from the base class, to provide contiguous access) ```
Ok, so about these `elements()`: 1. Regarding the array_ref member, I request that you specify this more formally: that the returned type models the concept std::ranges::contiguous_range. This already implies that it is random-access. A range need not be copyable, if you want this to be part of the guarantee, say that the return type is a view that models std::ranges::contiguous_range. 2. Regarding the array member, the fact that it might be contiguous is also a useful guarantee. Could the docs be more specific under what circumstances I get a contiguous range? Regards, &rzej;
I also added that all member functions are constexpr unless specified differently. (almost all member functions are constexpr, a couple of exceptions is some destructors and some constructors, due to C++17 limitations).
The search box leads me to: "a flatted view of all the elements rearranged canonically. A.elements()[0] → A[0][0], A.elements()[1] → A[0][1], etc. The type of the result is not a subarray but a special kind of range. Takes no argument."
It takes me to subarray::elements, but that doesn't imply that array::elements would have the same contract. "special kind of range" is not the level of detail that I expected. I think you owe the user the range category.
range category: always random access, contiguous for multi::array.
Thanks, Alfredo