Re: struct template constructors

2017-06-22 Thread via Digitalmars-d-learn
On Friday, 23 June 2017 at 00:54:36 UTC, Petar Kirov [ZombineDev] wrote: On Thursday, 22 June 2017 at 21:19:43 UTC, Boris-Barboris wrote: On Thursday, 22 June 2017 at 21:16:40 UTC, Ali Çehreli wrote: And yes, there should be one destructor, which may be a no-op if you grab its resource and set

Re: struct template constructors

2017-06-22 Thread via Digitalmars-d-learn
On Thursday, 22 June 2017 at 21:19:43 UTC, Boris-Barboris wrote: On Thursday, 22 June 2017 at 21:16:40 UTC, Ali Çehreli wrote: And yes, there should be one destructor, which may be a no-op if you grab its resource and set it to null. On all compilers... That's a relief, thank you for your he

Re: struct template constructors

2017-06-22 Thread Boris-Barboris via Digitalmars-d-learn
On Thursday, 22 June 2017 at 21:16:40 UTC, Ali Çehreli wrote: And yes, there should be one destructor, which may be a no-op if you grab its resource and set it to null. On all compilers... That's a relief, thank you for your help.

Re: struct template constructors

2017-06-22 Thread Ali Çehreli via Digitalmars-d-learn
On 06/22/2017 02:08 PM, Boris-Barboris wrote: On Thursday, 22 June 2017 at 20:05:46 UTC, Ali Çehreli wrote: To be complete, 'auto ref' passes lvalues by reference and rvalues by value, which you can detect with __traits(isRef): struct S{ } void foo()(auto ref S s) { static if (__traits(isR

Re: struct template constructors

2017-06-22 Thread Boris-Barboris via Digitalmars-d-learn
On Thursday, 22 June 2017 at 20:05:46 UTC, Ali Çehreli wrote: To be complete, 'auto ref' passes lvalues by reference and rvalues by value, which you can detect with __traits(isRef): struct S{ } void foo()(auto ref S s) { static if (__traits(isRef, s)) { pragma(msg, "lvalue"); }

Re: struct template constructors

2017-06-22 Thread Ali Çehreli via Digitalmars-d-learn
On 06/22/2017 12:57 PM, Boris-Barboris wrote: > On Thursday, 22 June 2017 at 19:17:13 UTC, Ali Çehreli wrote: >> No time to think about the rest of the design but just to get the code >> compiled, replace 'ref' with 'auto ref' like so: > > Ok, looks like this indeed passes rhs by reference, thank

Re: struct template constructors

2017-06-22 Thread Boris-Barboris via Digitalmars-d-learn
On Thursday, 22 June 2017 at 19:17:13 UTC, Ali Çehreli wrote: No time to think about the rest of the design but just to get the code compiled, replace 'ref' with 'auto ref' like so: Ok, looks like this indeed passes rhs by reference, thank you. destcalls - number of times UniquePtr destructor

Re: struct template constructors

2017-06-22 Thread Boris-Barboris via Digitalmars-d-learn
On Thursday, 22 June 2017 at 19:17:13 UTC, Ali Çehreli wrote: No time to think about the rest of the design but just to get the code compiled, replace 'ref' with 'auto ref' like so: this(DT)(scope auto ref UniquePtr!DT rhs) { // ... } Ali i added this static variable: st

Re: struct template constructors

2017-06-22 Thread Ali Çehreli via Digitalmars-d-learn
On 06/22/2017 12:06 PM, Boris-Barboris wrote: > Hi > > https://dpaste.dzfl.pl/0def4e286564 > > Is there a cleaner way to go than the one on the line 26? And why is the > constructor > > /d475/f781.d(37): f781.UniquePtr!(A).UniquePtr.__ctor(DT)(ref scope > UniquePtr!DT rhs) > > unfit for line 51? >

struct template constructors

2017-06-22 Thread Boris-Barboris via Digitalmars-d-learn
Hi https://dpaste.dzfl.pl/0def4e286564 Is there a cleaner way to go than the one on the line 26? And why is the constructor /d475/f781.d(37): f781.UniquePtr!(A).UniquePtr.__ctor(DT)(ref scope UniquePtr!DT rhs) unfit for line 51? Is it because the expression " = UniquePtr!B.make()" cannot b