Where does the template parameter E come from?
simendsjo
simen.endsjo at pandavre.com
Mon Mar 28 08:14:07 PDT 2011
On 28.03.2011 17:07, David Nadlinger wrote:
> On 3/28/11 4:54 PM, simendsjo wrote:
>> When running compose with two arguments, the implementation uses the
>> template parameter E. I don't understand what's going on here as E isn't
>> submitted to the template - what type is E?
>> […]
>> typeof({ E a; return fun0(fun1(a)); }()) doIt(E)(E a)
>> { […] }
>
> doIt is a function template, so E will be deduced to be whatever type
> the passed argument is – you won't notice the extra »template layer« as
> E is automatically inferred from the argument.
>
> For better understanding, you might want to look at the definition like
> this:
>
> ---
> template composeImpl(fun...) {
> […]
> template doIt(E) {
> typeof({ E a; return fun0(fun1(a)); }()) doIt(E a) {
> […]
> }
> }
> }
> ---
>
> David
Thanks. That seems like a good way of mentally mapping template usage
until it comes more naturally.
More information about the Digitalmars-d-learn
mailing list