C++ / Why Iterators Got It All Wrong

Ilya Yaroshenko via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 10 22:41:37 PDT 2017


On Thursday, 7 September 2017 at 20:46:22 UTC, jmh530 wrote:
> On Thursday, 7 September 2017 at 12:28:00 UTC, jmh530 wrote:
>> On Thursday, 7 September 2017 at 12:27:19 UTC, jmh530 wrote:
>>>
>>> auto x = data.sliced(2, 3).universal;
>>
>> Err, (3, 4) not (2, 3)
>
> All kinds of screwed up. This is what I get for not testing 
> things before I post them.
>
> unittest {
>     auto data = iota(12);
>
>     auto x = data.sliced(3, 4).universal;
>     assert(x.strides == [4, 1]);
>     assert(x[1, 2] == data[1 * 4 + 2 * 1]);
>
>     auto y = x.transposed;
>     assert(y.strides == [1, 4]);
>     assert(y[1, 2] == data[1 * 1 + 2 * 4]);
> }

Another small difference is slicing:
For example, for contiguous matrix m:
1. m[a .. b]         is contiguous
2. m[i]              is contiguous
3. m[a .. b, i]      is universal (because there are no 1D 
canonical slices)
4. m[a .. b, c .. d] is canonical

BTW, could you please update the docs or may be write a small 
article for Mir blog?
I will be happy to answer your questions if any.

Best Regards,
Ilya


More information about the Digitalmars-d mailing list