Template argument deduction from a function call question
Ali Çehreli via Digitalmars-d
digitalmars-d at puremagic.com
Wed Apr 1 11:24:40 PDT 2015
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) && // <-- ADDED
>> is(typeof(func(accum, accum)) == typeof(accum))) {
>> // ...
>> }
>>
>> Now it works.
>>
>> Ali
>
> Great tip. Is that in your book somewhere?
I don't think so; not that one... (Noted though; I may get to it.)
I had carefully tried to avoid adding "too much" information. However,
as the book progressed added more and more information like that,
especially after Luís Marques's recommendations. I am very grateful for
the effort he has put into reviewing and editing the book.
Ali
More information about the Digitalmars-d
mailing list