C++ std::string_view equivalent in D?

rikki cattermole rikki at cattermole.co.nz
Wed Feb 21 10:46:26 UTC 2018


On 21/02/2018 10:43 AM, 0xFFFFFFFF wrote:
> On Wednesday, 21 February 2018 at 10:24:39 UTC, ketmar wrote:
>> 0xFFFFFFFF wrote:
>>
>>> [...]
>>
>> and that is exactly what slices are for! ;-)
>>
>> you are probably better to use `const(char)[]`, tho. like this:
>>
>>     // don't store `s`, as it's contents may change after exiting of 
>> `myfunc`
>>     // (this is what `const` implies here)
>>     void myfunc (const(char)[] s) { ... }
>>
>>     ...
>>     string s = "test string";
>>     myfunc(s); // yep, this works
>>     s = s[2..4]; // this doesn't allocate
>>     myfunc(s);
>>     myfunc(s[3..6]); // or this, it doesn't allocate
>>     myfunc("abc"); // or this, doesn't allocate
>>
>> you got the idea.
> 
> Gotta save this too.
> 
> [BTW how do I post a thumbs up emoji]

+X (typically just 1) means that you agree.

But here we just say "thanks". This "forum" is backed by an NNTP server, 
so lots of the more newer concepts don't exist here.


More information about the Digitalmars-d-learn mailing list