C++ std::string_view equivalent in D?
rikki cattermole
rikki at cattermole.co.nz
Wed Feb 21 09:27:54 UTC 2018
On 21/02/2018 9:21 AM, 0xFFFFFFFF wrote:
> What is the equivalent of C++17 std::string_view (an object that can
> refer to a constant contiguous sequence of char-like objects with the
> first element of the sequence at position zero) in D?
>
> PS: I'm getting back to D after years (since DMD 1 days). A lot changes
> since v1.0.
Think of string_view as a poor man's slice support.
Slices are essentially just dynamic arrays, a length and a pointer.
char* ptr = cast(char*)malloc(32);
char[] array = ptr[0 .. 32];
char[] anotherArray = array[16 .. $];
assert(anotherArray.length == 16);
It isn't limited to just char's either :)
More information about the Digitalmars-d-learn
mailing list