Re: Struct template cannot deduce function from argument types

2018-06-27 Thread Luka Aleksic via Digitalmars-d-learn
On Wednesday, 27 June 2018 at 17:07:52 UTC, Jonathan M Davis wrote: On Wednesday, June 27, 2018 16:19:56 Luka Aleksic via Digitalmars-d-learn wrote: [...] [...] Well, for one, what's on the left side of the = doesn't normally affect the type of what's on the right. It does in some cases w

Re: Struct template cannot deduce function from argument types

2018-06-27 Thread lithium iodate via Digitalmars-d-learn
On Wednesday, 27 June 2018 at 16:19:56 UTC, Luka Aleksic wrote: […] I am getting the following error: scratch.d(14): Error: struct scratch.pair cannot deduce function from argument types !()(char, int), candidates are: scratch.d(2):scratch.pair(T, U) Failed: ["/usr/bin/dmd", "-v", "-o-

Re: Struct template cannot deduce function from argument types

2018-06-27 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 27, 2018 at 04:19:56PM +, Luka Aleksic via Digitalmars-d-learn wrote: [...] > struct pair(T, U) { > T first; > U second; > > this(T arg_first, U arg_second) { > first = arg_first; > second = arg_second; > } > }; > > void main()

Re: Struct template cannot deduce function from argument types

2018-06-27 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, June 27, 2018 16:19:56 Luka Aleksic via Digitalmars-d-learn wrote: > Hello, > > In the following code: > > T first; > U second; > > this(T arg_first, U arg_second) { > first = arg_first; > second = arg_second; > } > }; > > void main() { > > pair!(char, uint) p1

Struct template cannot deduce function from argument types

2018-06-27 Thread Luka Aleksic via Digitalmars-d-learn
Hello, In the following code: struct pair(T, U) { T first; U second; this(T arg_first, U arg_second) { first = arg_first; second = arg_second; } }; void main() { pair!(char, uint) p1 = pair('a', 1); } I am getting the f

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

Re: Struct template

2014-11-04 Thread Meta via Digitalmars-d-learn
On Monday, 3 November 2014 at 17:05:21 UTC, John Colvin wrote: static if (is(typeof(T) == int)) should be static if (is(T == int)) T is already a type. I thought this was supposed to produce an error message rather than fail silently... I'm positive this used to be an error. Did it change

Re: Struct template

2014-11-03 Thread John Colvin via Digitalmars-d-learn
On Monday, 3 November 2014 at 17:03:33 UTC, deed wrote: struct Internal { int i; double d; string s; } struct External_int { Internal internal; @property Internal* ptr () { return &internal; } this (int a) { internal.s = "int"; internal.i = a; } } struct External (T)

Re: Struct template

2014-11-03 Thread deed via Digitalmars-d-learn
static if (is(typeof(T) == int)) should be static if (is(T == int)) T is already a type. Ahh. Thanks!

Struct template

2014-11-03 Thread deed via Digitalmars-d-learn
struct Internal { int i; double d; string s; } struct External_int { Internal internal; @property Internal* ptr () { return &internal; } this (int a) { internal.s = "int"; internal.i = a; } } struct External (T) { Internal internal; @property Internal* ptr () { ret

Re: struct template help

2014-07-12 Thread Danyal Zia via Digitalmars-d-learn
On Saturday, 12 July 2014 at 19:42:13 UTC, Ali Çehreli wrote: Actually, that works too but members must be initialized from the beginning. The trailing ones are left with .init values: struct S { int i; string s; } void main() { auto s = new S(42); static assert(is (typeof(s) =

Re: struct template help

2014-07-12 Thread Ali Çehreli via Digitalmars-d-learn
On 07/12/2014 12:38 PM, Danyal Zia wrote: > You can initialize in constructor this(), but you can't initialize > partial fields of struct when using pointer to struct. Actually, that works too but members must be initialized from the beginning. The trailing ones are left with .init values: st

Re: struct template help

2014-07-12 Thread Danyal Zia via Digitalmars-d-learn
On Saturday, 12 July 2014 at 19:32:48 UTC, seany wrote: do I have to initialize all variables of the struct? or may I also use a this(){} in the struct and initialize only those which are known at a given moment? You can initialize in constructor this(), but you can't initialize partial field

Re: struct template help

2014-07-12 Thread Ali Çehreli via Digitalmars-d-learn
On 07/12/2014 12:32 PM, seany wrote: > do I have to initialize all variables of the struct? No. The uninitialized ones get their .init values. > or may I also use a > this(){} in the struct and initialize only those which are known at a > given moment? That already works with structs. You don'

Re: struct template help

2014-07-12 Thread Ali Çehreli via Digitalmars-d-learn
On 07/12/2014 12:19 PM, seany wrote: > On Saturday, 12 July 2014 at 19:16:52 UTC, Danyal Zia wrote: >> On Saturday, 12 July 2014 at 19:09:44 UTC, seany wrote: >>>arc!(string, string[]) * a; >>>a.some_var = "hello"; >> "a" has not been instantiated. You are declaring it as a pointer to >

Re: struct template help

2014-07-12 Thread seany via Digitalmars-d-learn
do I have to initialize all variables of the struct? or may I also use a this(){} in the struct and initialize only those which are known at a given moment?

Re: struct template help

2014-07-12 Thread Danyal Zia via Digitalmars-d-learn
On Saturday, 12 July 2014 at 19:19:28 UTC, seany wrote: For reasons further down in the software, I need to do this with a pointer. How do I do it with a pointer, please? I don't know what are you trying to achieve, but if that's what you want, you can do: void MYfunction() { auto strArr

Re: struct template help

2014-07-12 Thread Danyal Zia via Digitalmars-d-learn
On Saturday, 12 July 2014 at 19:09:44 UTC, seany wrote: Please consider the following struct arc(T,U) { T some_var; U someother_var; } /* things */ class myclass { this(){} ~this(){} void MYfunction() { arc!(string, string[]) * a; a.some_var = "hello"; } } void main() {

Re: struct template help

2014-07-12 Thread seany via Digitalmars-d-learn
On Saturday, 12 July 2014 at 19:16:52 UTC, Danyal Zia wrote: On Saturday, 12 July 2014 at 19:09:44 UTC, seany wrote: Please consider the following struct arc(T,U) { T some_var; U someother_var; } /* things */ class myclass { this(){} ~this(){} void MYfunction() { arc!(string, string[

Re: struct template help

2014-07-12 Thread seany via Digitalmars-d-learn
Also, (*c).MYfunction() is leading to segmentation fault

Re: struct template help

2014-07-12 Thread seany via Digitalmars-d-learn
sorry, I meant (*a).some_var not (*c).MYfunction()

struct template help

2014-07-12 Thread seany via Digitalmars-d-learn
Please consider the following struct arc(T,U) { T some_var; U someother_var; } /* things */ class myclass { this(){} ~this(){} void MYfunction() { arc!(string, string[]) * a; a.some_var = "hello"; } } void main() { c = new myclass(); c.MYfunction(); } This leads to a

Re: Get struct template types

2014-02-04 Thread ed
On Tuesday, 4 February 2014 at 11:01:01 UTC, Jakob Ovrum wrote: On Tuesday, 4 February 2014 at 09:30:22 UTC, ed wrote: Hi, given a struct like so: struct S(alias N, T) {...} is there a way to get the template parameters of S? Something like: S.typetuple[0] == N, S.typetuple[1] == T I've h

Re: Get struct template types

2014-02-04 Thread Jakob Ovrum
On Tuesday, 4 February 2014 at 09:30:22 UTC, ed wrote: Hi, given a struct like so: struct S(alias N, T) {...} is there a way to get the template parameters of S? Something like: S.typetuple[0] == N, S.typetuple[1] == T I've had a look at std.typecons and std.typetuple but I don't see what

Re: Get struct template types

2014-02-04 Thread evilrat
On Tuesday, 4 February 2014 at 09:58:53 UTC, ed wrote: On Tuesday, 4 February 2014 at 09:46:01 UTC, evilrat wrote: On Tuesday, 4 February 2014 at 09:39:48 UTC, evilrat wrote: On Tuesday, 4 February 2014 at 09:30:22 UTC, ed wrote: Hi, given a struct like so: struct S(alias N, T) {...} is the

Re: Get struct template types

2014-02-04 Thread ed
On Tuesday, 4 February 2014 at 09:46:01 UTC, evilrat wrote: On Tuesday, 4 February 2014 at 09:39:48 UTC, evilrat wrote: On Tuesday, 4 February 2014 at 09:30:22 UTC, ed wrote: Hi, given a struct like so: struct S(alias N, T) {...} is there a way to get the template parameters of S? Something

Re: Get struct template types

2014-02-04 Thread evilrat
On Tuesday, 4 February 2014 at 09:39:48 UTC, evilrat wrote: On Tuesday, 4 February 2014 at 09:30:22 UTC, ed wrote: Hi, given a struct like so: struct S(alias N, T) {...} is there a way to get the template parameters of S? Something like: S.typetuple[0] == N, S.typetuple[1] == T I've had a

Re: Get struct template types

2014-02-04 Thread evilrat
On Tuesday, 4 February 2014 at 09:30:22 UTC, ed wrote: Hi, given a struct like so: struct S(alias N, T) {...} is there a way to get the template parameters of S? Something like: S.typetuple[0] == N, S.typetuple[1] == T I've had a look at std.typecons and std.typetuple but I don't see what

Get struct template types

2014-02-04 Thread ed
Hi, given a struct like so: struct S(alias N, T) {...} is there a way to get the template parameters of S? Something like: S.typetuple[0] == N, S.typetuple[1] == T I've had a look at std.typecons and std.typetuple but I don't see what I'm missing something and cannot see a way to do the ab