Re: Template parameters that don't affect template type

2016-08-12 Thread Engine Machine via Digitalmars-d-learn
On Thursday, 11 August 2016 at 20:43:13 UTC, Meta wrote: On Thursday, 11 August 2016 at 18:11:30 UTC, Engine Machine wrote: [...] It can be done, but you have to be explicit and should think very carefully if this is really a good design. struct X(int defaultSize = 100) { int size;

Re: Template parameters that don't affect template type

2016-08-11 Thread Meta via Digitalmars-d-learn
On Thursday, 11 August 2016 at 18:11:30 UTC, Engine Machine wrote: I have the need, in some cases, to pass static information to a template class but don't want it to affect its type. import std.algorithm, core.stdc.stdlib; struct X(int defaultSize = 100) { int Size; int* p; void foo(i

Re: Template parameters that don't affect template type

2016-08-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/11/16 4:15 PM, Engine Machine wrote: On Thursday, 11 August 2016 at 18:42:51 UTC, Steven Schveighoffer wrote: On 8/11/16 2:11 PM, Engine Machine wrote: I have the need, in some cases, to pass static information to a template class but don't want it to affect its type. import std.algorithm

Re: Template parameters that don't affect template type

2016-08-11 Thread Engine Machine via Digitalmars-d-learn
On Thursday, 11 August 2016 at 18:42:51 UTC, Steven Schveighoffer wrote: On 8/11/16 2:11 PM, Engine Machine wrote: I have the need, in some cases, to pass static information to a template class but don't want it to affect its type. import std.algorithm, core.stdc.stdlib; struct X(int defaultSi

Re: Template parameters that don't affect template type

2016-08-11 Thread Engine Machine via Digitalmars-d-learn
Also, what if we use a class instead of a struct? in this case they are both references to the same thing. I see a problem with reflection though, as one could get the template parameter value and it would wrong on conversion. D takes the easy way out of just preventing complex and potentially

Re: Template parameters that don't affect template type

2016-08-11 Thread Engine Machine via Digitalmars-d-learn
On Thursday, 11 August 2016 at 19:28:47 UTC, Lodovico Giaretta wrote: On Thursday, 11 August 2016 at 18:11:30 UTC, Engine Machine wrote: [...] If, in your case, it is possible to use one type as the other, then specify it. I mean, implement a templated opAssign that allows you to assign valu

Re: Template parameters that don't affect template type

2016-08-11 Thread Lodovico Giaretta via Digitalmars-d-learn
On Thursday, 11 August 2016 at 18:11:30 UTC, Engine Machine wrote: [...] If, in your case, it is possible to use one type as the other, then specify it. I mean, implement a templated opAssign that allows you to assign values of one instantiation to values of another. While doing so, remember

Re: Template parameters that don't affect template type

2016-08-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/11/16 2:42 PM, Steven Schveighoffer wrote: On 8/11/16 2:11 PM, Engine Machine wrote: I have the need, in some cases, to pass static information to a template class but don't want it to affect its type. import std.algorithm, core.stdc.stdlib; struct X(int defaultSize = 100) { int Size;

Re: Template parameters that don't affect template type

2016-08-11 Thread Ali Çehreli via Digitalmars-d-learn
On 08/11/2016 11:11 AM, Engine Machine wrote: > I have the need, in some cases, to pass static information to a template > class but don't want it to affect its type. > > import std.algorithm, core.stdc.stdlib; > struct X(int defaultSize = 100) > { >int Size; >int* p; >void foo(int siz

Re: Template parameters that don't affect template type

2016-08-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/11/16 2:11 PM, Engine Machine wrote: I have the need, in some cases, to pass static information to a template class but don't want it to affect its type. import std.algorithm, core.stdc.stdlib; struct X(int defaultSize = 100) { int Size; int* p; void foo(int size) { Size = m

Re: Template parameters that don't affect template type

2016-08-11 Thread sldkf via Digitalmars-d-learn
On Thursday, 11 August 2016 at 18:11:30 UTC, Engine Machine wrote: Is there any way to get D to understand I want do not want a template parameter to be part of the type comparison? No. Use a standard run-time parameter. Your problem can be solved by defining a constructor.

Re: Template parameters that don't affect template type

2016-08-11 Thread Engine Machine via Digitalmars-d-learn
On Thursday, 11 August 2016 at 18:11:30 UTC, Engine Machine wrote: I have the need, in some cases, to pass static information to a template class but don't want it to affect its type. import std.algorithm, core.stdc.stdlib; struct X(int defaultSize = 100) { int Size; int* p; void foo(i

Template parameters that don't affect template type

2016-08-11 Thread Engine Machine via Digitalmars-d-learn
I have the need, in some cases, to pass static information to a template class but don't want it to affect its type. import std.algorithm, core.stdc.stdlib; struct X(int defaultSize = 100) { int Size; int* p; void foo(int size) { Size = max(size, defaultSize); p = cast(int*)m