merkle reverse
Seb
seb at wilzba.ch
Thu Apr 5 09:49:58 UTC 2018
On Thursday, 5 April 2018 at 09:24:31 UTC, SimonN wrote:
> On Thursday, 5 April 2018 at 09:07:52 UTC, Seb wrote:
>> FYI: The problem isn't chunks, but that strings aren't
>> bi-directional ranges (hello ugly auto-decoding!).
>> "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b".byCodeUnit
>
> Thanks! Very appropriate because it's all hex digits anyway.
>
> Instead of std.experimental.all, one can also import std.utf.
>
> Initially, I wondered whether autodecoding was the issue here,
> but I dismissed it because the OP's example calls retro
> immediately on a string, which is supposedly not autodecodable
> as bi-directional. But I should examine retro's implementation
> because I remember several Phobos functions having special
> cases for strings (which is exactly the issue of auto-decoding).
Well sorry for my poor words.
Strings are bi-directional ranges, but they aren't random-access
nor have a length which is typically required by other ranges to
forward bidirectionality.
chunks requires hasSlicing + hasLength:
https://github.com/dlang/phobos/blob/193c61d985a9645014b2161b59ddb8692308e063/std/range/package.d#L7851
slide requires just hasSlicing:
https://github.com/dlang/phobos/blob/193c61d985a9645014b2161b59ddb8692308e063/std/range/package.d#L8650
Now why does "aa"[0.. 1] work, but hasSlicing return false?
Because it's explicitly excluded:
https://github.com/dlang/phobos/blob/193c61d985a9645014b2161b59ddb8692308e063/std/range/primitives.d#L1557
tl;dr: if you want to do anything useful with strings, byCodeUnit
is usually your best friend.
More information about the Digitalmars-d-learn
mailing list