Re: Template argument deduction from a function call question

2015-04-02 Thread Steven Schveighoffer via Digitalmars-d
On 4/1/15 2:46 PM, Dzugaru wrote: On Wednesday, 1 April 2015 at 18:37:24 UTC, Ali Çehreli wrote: On 04/01/2015 11:27 AM, Dzugaru wrote: > This code does work when you provide second (non-default) argument to > function, and doesn't if you do not (no way it can deduce E solely from > checks I as

Re: Template argument deduction from a function call question

2015-04-01 Thread Dzugaru via Digitalmars-d
On Wednesday, 1 April 2015 at 18:37:24 UTC, Ali Çehreli wrote: On 04/01/2015 11:27 AM, Dzugaru wrote: > This code does work when you provide second (non-default) argument to > function, and doesn't if you do not (no way it can deduce E solely from > checks I assume). > > My version, in constract

Re: Template argument deduction from a function call question

2015-04-01 Thread John Colvin via Digitalmars-d
On Wednesday, 1 April 2015 at 18:20:41 UTC, Dzugaru wrote: a) isn't this almost, if not exactly, the same as std.algorithm.reduce? b) you can write nice things like this: auto min = [2,4,1,3,5].aggregate!((a, b) => a < b ? a : b)(int.max); c) the deduction failure looks like a bug to me, p

Re: Template argument deduction from a function call question

2015-04-01 Thread Ali Çehreli via Digitalmars-d
On 04/01/2015 11:27 AM, Dzugaru wrote: > This code does work when you provide second (non-default) argument to > function, and doesn't if you do not (no way it can deduce E solely from > checks I assume). > > My version, in constract, works when you do not provide second argument > and doesn't if

Re: Template argument deduction from a function call question

2015-04-01 Thread Dzugaru via Digitalmars-d
On Wednesday, 1 April 2015 at 18:13:15 UTC, Ali Çehreli wrote: On 04/01/2015 10:57 AM, Dzugaru wrote: > ElementType!S aggregate(alias func, S)(S list, ElementType!S accum = > ElementType!S.init) > if(is(typeof(func(accum, accum)) == typeof(accum))) { [...] > } I can't explain exactly why that d

Re: Template argument deduction from a function call question

2015-04-01 Thread Dzugaru via Digitalmars-d
a) isn't this almost, if not exactly, the same as std.algorithm.reduce? b) you can write nice things like this: auto min = [2,4,1,3,5].aggregate!((a, b) => a < b ? a : b)(int.max); c) the deduction failure looks like a bug to me, perhaps there is a good reason why it can't work in the gene

Re: Template argument deduction from a function call question

2015-04-01 Thread John Colvin via Digitalmars-d
On Wednesday, 1 April 2015 at 18:13:15 UTC, Ali Çehreli wrote: On 04/01/2015 10:57 AM, Dzugaru wrote: > ElementType!S aggregate(alias func, S)(S list, ElementType!S accum = > ElementType!S.init) > if(is(typeof(func(accum, accum)) == typeof(accum))) { [...] > } I can't explain exactly why that d

Re: Template argument deduction from a function call question

2015-04-01 Thread Ali Çehreli via Digitalmars-d
On 04/01/2015 11:15 AM, John Colvin wrote: >> Instead of using >> ElementType!S in the parameter list, introduce a third one (E), which >> you check in the template constraint: >> >> ElementType!S aggregate(alias func, S, E)(S list, E accum = E.init) >> if(is (E == ElementType!S) &&

Re: Template argument deduction from a function call question

2015-04-01 Thread Ali Çehreli via Digitalmars-d
On 04/01/2015 10:57 AM, Dzugaru wrote: > ElementType!S aggregate(alias func, S)(S list, ElementType!S accum = > ElementType!S.init) > if(is(typeof(func(accum, accum)) == typeof(accum))) { [...] > } I can't explain exactly why that doesn't work. However, I've discovered a number of times that re

Re: Template argument deduction from a function call question

2015-04-01 Thread John Colvin via Digitalmars-d
On Wednesday, 1 April 2015 at 17:57:12 UTC, Dzugaru wrote: Following recent IRC discussion. I want to write a generic list aggregate function that works with builtin types like int[] as well as custom classes/structs that define front, empty, popFront: import std.range; ElementType!S aggreg

Template argument deduction from a function call question

2015-04-01 Thread Dzugaru via Digitalmars-d
Following recent IRC discussion. I want to write a generic list aggregate function that works with builtin types like int[] as well as custom classes/structs that define front, empty, popFront: import std.range; ElementType!S aggregate(alias func, S)(S list, ElementType!S accum = ElementTyp