On Tue, Mar 12, 2019 at 04:23:29PM +0000, Victor Porton via Digitalmars-d-learn 
wrote:
[...]
> I know what is eponymous template. But how it behaves when the
> eponymous member inside itself is also a template? How to instantiate
> it? (provide please an example how to instantiate)

You need to provide two sets of template arguments. Usually, the only
time we nest eponymous templates this way is when we're writing a
function that needs to take two variadic sets of template parameters. In
that case, we only need to write one set of template parameters and let
IFTI fill in the second set of parameters for us.

For example:

        template map(funcs...) {
                template map(Ranges...) {
                        auto map(Ranges rr) {
                                ...
                        }
                }
        }

        auto r = map!(func1, func2)(r1, r2);

The first part `map!(func1, func2)` resolves to an instantiation of the
outer template, which is an inner template, then the compiler uses IFTI
to deduce the second set of arguments as !(typeof(r1), typeof(r2)) in
order to instantiate the inner template.

If you want to instantiate it by hand, you could do something like this:

        alias Outer = map!(func1, func2);       // instantiate outer template
        alias inner = Outer!(int[], int[]);     // instantiate inner template
        inner([ 1, 2, 3], [ 4, 5, 6 ]);


T

-- 
People say I'm indecisive, but I'm not sure about that. -- YHL, CONLANG

Reply via email to