Re: one liner to split a string into every n chars?

2022-04-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/13/22 2:26 AM, mw wrote: Hi, What's the D's idiom to split a string into an array of every n chars? (prefer one liner) str.byChar.chunks(2).array; Your request of "array of every n chars" is somewhat ambiguous. This is an array of chunks (not an array of arrays). -Steve

Re: Why do immutable variables need reference counting?

2022-04-13 Thread Ali Çehreli via Digitalmars-d-learn
On 4/12/22 21:34, Salih Dincer wrote: > I tried the following and I didn't understand one thing: Why is there no > need to use dup when slicing? I don't think I understand you fully. > ```d > struct S(T) { > T fileName; > >this(T fileName) { > this.fileName = fileName; > report(

Re: Why do immutable variables need reference counting?

2022-04-13 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Apr 13, 2022 at 08:39:17AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 4/12/22 21:34, Salih Dincer wrote: > > > I tried the following and I didn't understand one thing: Why is > > there no need to use dup when slicing? [...] Because of two things: (1) there is a GC, and (2) ch

RefCounted

2022-04-13 Thread JG via Digitalmars-d-learn
Hi, I would have thought that RefCounted!(T, RefCountedAutoInitialize.no) is to be used in place T* when I want reference counting instead of the usual garbage collection (or manual allocation). Perhaps this is wrong? If I am correct what am I doing wrong here? (Sorry for two space squashed

Re: RefCounted

2022-04-13 Thread JG via Digitalmars-d-learn
On Wednesday, 13 April 2022 at 20:47:33 UTC, JG wrote: Hi, I would have thought that RefCounted!(T, RefCountedAutoInitialize.no) is to be used in place T* when I want reference counting instead of the usual garbage collection (or manual allocation). Perhaps this is wrong? [...] Perhaps I

Re: RefCounted

2022-04-13 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 13 April 2022 at 21:15:13 UTC, JG wrote: On Wednesday, 13 April 2022 at 20:47:33 UTC, JG wrote: Hi, I would have thought that RefCounted!(T, RefCountedAutoInitialize.no) is to be used in place T* when I want reference counting instead of the usual garbage collection (or manual