Template context

Marcin Kuszczak aarti at interia.pl
Sun Jan 7 16:13:52 PST 2007


Chris Nicholson-Sauls wrote:

> Perhaps 'context' should be '_context' in the vein of _arguments and
> _args though.  Getting the symbol, etc, wouldn't really be all that
> difficult.  Just define _context as a namespace of constants available
> during template instantiation.


ohhh.. please... do not make another strange _context object!

Personally I think that passing information about variadic arguments of
function with _arguments and _argptr is black side of D... To get it work
properly IMHO there should be build in variant type (which is really
usefull in some cases) and arguments to variadic functions could be sent in
standard way:

void varfunction(variant[] vals ...); // Same syntax like D typesafe
variadic functions.

-----------------------------

In case of template instatiation context the idea is nice and very usefull,
but I would rather propose property like syntax for getting context:

void trace(T_Args...)(T_Args args...) {
        writef("%s:%d (%s): ", trace.context.file, trace.context.line,
trace.context.symbol);
        foreach( arg ; args )
                writef(arg);
        writefln();
        }

Advantages:
1. Properties for functions already works (nothing interesting, but compiles
without problem with DMD), so it is nothing new for compiler.
2. It could work also for normal functions
3. Makes less pollution of namespace


-- 
Regards
Marcin Kuszczak (Aarti_pl)
-------------------------------------
Ask me why I believe in Jesus - http://zapytaj.dlajezusa.pl (en/pl)
Doost (port of few Boost libraries) - http://www.dsource.org/projects/doost/
-------------------------------------




More information about the Digitalmars-d mailing list