Re: Template type deduction and specialization

2015-05-21 Thread Daniel Kozák via Digitalmars-d-learn
On Wed, 20 May 2015 17:23:05 -0700 Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On 05/20/2015 04:10 PM, Mike Parker wrote: On Wednesday, 20 May 2015 at 13:46:22 UTC, Daniel Kozák wrote: DOC say `may not have` not `must not have` ;-) OK, if that's the

Re: Template type deduction and specialization

2015-05-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/21/15 2:35 AM, Daniel Kozák via Digitalmars-d-learn wrote: On Wed, 20 May 2015 17:23:05 -0700 Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On 05/20/2015 04:10 PM, Mike Parker wrote: On Wednesday, 20 May 2015 at 13:46:22 UTC, Daniel Kozák wrote: DOC say

Re: Template type deduction and specialization

2015-05-21 Thread Daniel Kozak via Digitalmars-d-learn
On Thursday, 21 May 2015 at 13:12:36 UTC, Daniel Kozák wrote: On Thu, 21 May 2015 08:54:54 -0400 Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On 5/21/15 2:35 AM, Daniel Kozák via Digitalmars-d-learn wrote: On Wed, 20 May 2015 17:23:05 -0700 Ali

Re: Template type deduction and specialization

2015-05-21 Thread Daniel Kozák via Digitalmars-d-learn
On Thu, 21 May 2015 08:54:54 -0400 Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On 5/21/15 2:35 AM, Daniel Kozák via Digitalmars-d-learn wrote: On Wed, 20 May 2015 17:23:05 -0700 Ali Çehreli via Digitalmars-d-learn

Re: Template type deduction and specialization

2015-05-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/21/15 10:15 AM, Daniel Kozák via Digitalmars-d-learn wrote: import std.stdio; void f(T:T*)(T* t) { writeln(before change this is not called); } void f(T)(T t) { writeln(before change this is called); } void main() { int val; f(val); f!(int*)(val); } now it

Re: Template type deduction and specialization

2015-05-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/21/15 9:14 AM, Daniel Kozak wrote: On Thursday, 21 May 2015 at 13:12:36 UTC, Daniel Kozák wrote: On Thu, 21 May 2015 08:54:54 -0400 Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On 5/21/15 2:35 AM, Daniel Kozák via Digitalmars-d-learn wrote: On

Re: Template type deduction and specialization

2015-05-21 Thread Daniel Kozák via Digitalmars-d-learn
On Thu, 21 May 2015 09:58:16 -0400 Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On 5/21/15 9:14 AM, Daniel Kozak wrote: On Thursday, 21 May 2015 at 13:12:36 UTC, Daniel Kozák wrote: On Thu, 21 May 2015 08:54:54 -0400 Steven Schveighoffer via

Re: Template type deduction and specialization

2015-05-20 Thread Namespace via Digitalmars-d-learn
On Wednesday, 20 May 2015 at 06:31:13 UTC, Mike Parker wrote: I don't understand why this behaves as it does. Given the following two templates: ``` void printVal(T)(T t) { writeln(t); } void printVal(T : T*)(T* t) { writeln(*t); } ``` I find that I actually have to explicitly

Re: Template type deduction and specialization

2015-05-20 Thread jklp via Digitalmars-d-learn
On Wednesday, 20 May 2015 at 06:31:13 UTC, Mike Parker wrote: I don't understand why this behaves as it does. Given the following two templates: ``` void printVal(T)(T t) { writeln(t); } void printVal(T : T*)(T* t) { writeln(*t); } ``` I find that I actually have to explicitly

Template type deduction and specialization

2015-05-20 Thread Mike Parker via Digitalmars-d-learn
I don't understand why this behaves as it does. Given the following two templates: ``` void printVal(T)(T t) { writeln(t); } void printVal(T : T*)(T* t) { writeln(*t); } ``` I find that I actually have to explicitly instantiate the template with a pointer type to get the

Re: Template type deduction and specialization

2015-05-20 Thread Mike Parker via Digitalmars-d-learn
On 5/20/2015 6:35 PM, Daniel Kozak wrote: DOCS: http://dlang.org/template.html#function-templates says: Function template type parameters that are to be implicitly deduced may not have specializations: Thanks. For the record, the example there is the exact same case. void Foo(T : T*)(T t) {

Re: Template type deduction and specialization

2015-05-20 Thread Mike Parker via Digitalmars-d-learn
On 5/20/2015 6:35 PM, Jonathan M Davis via Digitalmars-d-learn wrote: I'm using a fairly recent version of dmd master, and it prints out the address for px in both cases when I compile your code. So, if it's printing out 100 for you on the second call, it would appear to be a bug that has been

Re: Template type deduction and specialization

2015-05-20 Thread Daniel Kozák via Digitalmars-d-learn
On Wed, 20 May 2015 06:31:11 + Mike Parker via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: I don't understand why this behaves as it does. Given the following two templates: ``` void printVal(T)(T t) { writeln(t); } void printVal(T : T*)(T* t) {

Re: Template type deduction and specialization

2015-05-20 Thread Daniel Kozak via Digitalmars-d-learn
On Wednesday, 20 May 2015 at 09:24:28 UTC, Daniel Kozák wrote: On Wed, 20 May 2015 06:31:11 + Mike Parker via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: I don't understand why this behaves as it does. Given the following two templates: ``` void printVal(T)(T t) {

Re: Template type deduction and specialization

2015-05-20 Thread Mike Parker via Digitalmars-d-learn
On 5/20/2015 4:36 PM, Namespace wrote: What about: import std.stdio; void printVal(T)(T t) { static if (is(T : U*, U)) printVal(*t); else writeln(t); } Thanks, but I'm not looking for alternatives. I'm trying to figure out why it doesn't work as expected.

Re: Template type deduction and specialization

2015-05-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, May 20, 2015 06:31:11 Mike Parker via Digitalmars-d-learn wrote: I don't understand why this behaves as it does. Given the following two templates: ``` void printVal(T)(T t) { writeln(t); } void printVal(T : T*)(T* t) { writeln(*t); } ``` I find that I actually have

Re: Template type deduction and specialization

2015-05-20 Thread Daniel Kozak via Digitalmars-d-learn
On Wednesday, 20 May 2015 at 07:27:53 UTC, jklp wrote: --- import std.stdio; void printVal(T)(T t) { writeln(t); } void printVal(T: T)(T* t) { writeln(*t); } void main() { int x = 100; printVal(x); int* px = x; printVal(px); } --- here it's

Re: Template type deduction and specialization

2015-05-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, May 20, 2015 07:36:21 Namespace via Digitalmars-d-learn wrote: What about: import std.stdio; void printVal(T)(T t) { static if (is(T : U*, U)) printVal(*t); else writeln(t); } void main() { int x = 100; printVal(x); int*

Re: Template type deduction and specialization

2015-05-20 Thread Daniel Kozak via Digitalmars-d-learn
On Wednesday, 20 May 2015 at 09:35:48 UTC, Jonathan M Davis wrote: Well, if printVal!(int*)(px); prints 100, then that's a bug. It should print the address. In fact, it should be _impossible_ for the second overload of printVal to ever be instantiated IMHO thats not true, it should print

Re: Template type deduction and specialization

2015-05-20 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 20 May 2015 at 09:35:43 UTC, Daniel Kozak wrote: DOCS: http://dlang.org/template.html#function-templates says: Function template type parameters that are to be implicitly deduced may not have specializations: OK, having reread this, I'm not clear at all what's going on. Here,

Re: Template type deduction and specialization

2015-05-20 Thread Daniel Kozák via Digitalmars-d-learn
DOC say `may not have` not `must not have` ;-) On Wed, 20 May 2015 13:24:22 + Mike Parker via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Wednesday, 20 May 2015 at 09:35:43 UTC, Daniel Kozak wrote: DOCS: http://dlang.org/template.html#function-templates says:

Re: Template type deduction and specialization

2015-05-20 Thread Ali Çehreli via Digitalmars-d-learn
On 05/20/2015 04:10 PM, Mike Parker wrote: On Wednesday, 20 May 2015 at 13:46:22 UTC, Daniel Kozák wrote: DOC say `may not have` not `must not have` ;-) OK, if that's the intent, it needs to be reworded. As it stands, it looks more like it's saying specialization is not permissible, rather

Re: Template type deduction and specialization

2015-05-20 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 20 May 2015 at 13:46:22 UTC, Daniel Kozák wrote: DOC say `may not have` not `must not have` ;-) OK, if that's the intent, it needs to be reworded. As it stands, it looks more like it's saying specialization is not permissible, rather than what might be possible. As in:

Re: Template type deduction and specialization

2015-05-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, May 20, 2015 19:20:19 Mike Parker via Digitalmars-d-learn wrote: On 5/20/2015 6:35 PM, Jonathan M Davis via Digitalmars-d-learn wrote: I'm using a fairly recent version of dmd master, and it prints out the address for px in both cases when I compile your code. So, if it's