How to pass an InputRange of dchars to a function that wants an Input range of chars?
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Thu Feb 20 03:54:28 UTC 2025
On Wednesday, February 19, 2025 7:48:48 PM MST Jonathan M Davis via Digitalmars-d-learn wrote:
> So you should probably either just make your code operate on ranges of
> dchar, or you'll need to wrap your ranges using byChar or byCodeUnit in
> order to get ranges of char. All range-based functions will treat your
> strings as ranges of dchar. So, if really need to have strings and be
> treating them as ranges of char without wrapping them and without
> potentially creating new strings from wrapped ranges, then you can't use any
> range-based functions to do what you're doing.
To add to this, another option is to use std.string.representation to cast a
string to immutable(ubyte)[] - or an array of whatever the corresponding
integer type is if you're not dealing with immutable(char)[] - and operate
on that instead. But you can't use string as-is and have a range of char.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list