February 21, 2018
On Wednesday, 21 February 2018 at 10:22:56 UTC, rikki cattermole wrote:
> On 21/02/2018 10:17 AM, 0xFFFFFFFF wrote:
>> On Wednesday, 21 February 2018 at 09:21:58 UTC, 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.
>> 
>> Wow! Thanks guys.
>> Those are handy, but I specifically want to do something like:
>> 
>> ```
>> string_view sv = "some string";
>> ```
>
> string sv = "some string";
> assert(sv.length == 11);
>
> Or just "some string".length ;)


Thanks, it took time before I updated my reply to prevous answers.
I didn't see these before I did.

[I'm not that dumb] :winks:
February 21, 2018
On Wednesday, 21 February 2018 at 09:21:58 UTC, 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.

Thanks guys @all. I completed the task.

Glad to know there are lots people helping out here.
February 21, 2018
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]
February 21, 2018
On 21/02/2018 10:41 AM, 0xFFFFFFFF wrote:
> On Wednesday, 21 February 2018 at 09:21:58 UTC, 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.
> 
> Thanks guys @all. I completed the task.
> 
> Glad to know there are lots people helping out here.

Hop on to IRC (FreeNode #d) or Discord https://discord.gg/sVMHUD (invite expires in a day) if you'd like a more interactive conversation :)
February 21, 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.
February 21, 2018
On Wednesday, 21 February 2018 at 10:43:14 UTC, 0xFFFFFFFF wrote:
> Gotta save this too.
>
> [BTW how do I post a thumbs up emoji]

👍
1 2
Next ›   Last »