How to know if opSlice is defined for a type (including built-in types)?

chardetm via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jan 20 09:03:05 PST 2016


On Wednesday, 20 January 2016 at 15:25:10 UTC, Jonathan M Davis 
wrote:
> On Wednesday, January 20, 2016 13:06:00 chardetm via 
> Digitalmars-d-learn wrote:
>> Anyone who has the same problem: I found 
>> std.range.primitives.hasSlicing 
>> (https://dlang.org/phobos/std_range_primitives.html#hasSlicing) which does exactly what I want!
>
> Note that because strings are treated as ranges of dchar 
> regardless of what their actual character type is, arrays of 
> char and wchar (so-called "narrow" strings) are not consider to 
> have slicing or random access by the traits in std.range. So, 
> hasSlicing!string is false, though for anything other than an 
> array of char or wchar, it will do what you're looking for, 
> whereas for arrays of char or wchar, you really shouldn't be 
> using the slice operator on them without knowing that they're 
> what you're operating on so that you take the Unicode issues 
> into account correctly.
>
> - Jonathan M Davis

Yes and that was the next step of my problem, it turned out that 
it was already taken into account by hasSlicing!

Thank you very much!


More information about the Digitalmars-d-learn mailing list