Template argument deduction from a function call question
Ali Çehreli via Digitalmars-d
digitalmars-d at puremagic.com
Wed Apr 1 11:13:15 PDT 2015
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 reducing the dependency
between template parameters helps. 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
More information about the Digitalmars-d
mailing list