variadic mixin - the right tool for the job?
Daniel Kozák via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Mar 18 08:27:03 PDT 2015
On Wed, 18 Mar 2015 15:35:03 +0100
"Robert M. Münch via Digitalmars-d-learn"
<digitalmars-d-learn at puremagic.com> wrote:
> Hi, can something like this (I borrowed the C pre-processor idea) be
> done with variadic mixins?
>
> #define log(variadic-arg) sys-log("%s:%s" + variadic-arg[0],
> __FILE__, __LINE__, variadic-arg[1..$]);
>
> I read that mixins can only be used for declarations, and this here
> is a function call. So wondering, how something like this can be done.
>
You probably does not need mixins:
module main;
import core.vararg;
void some_fun(char c, string file, int line, ...) {
import std.stdio : writeln;
writeln(c, file, line);
}
void log(string file = __FILE__, size_t line = __LINE__, T...)
(T variadic_arg) {
some_fun(variadic_arg[0], file, line, variadic_arg[1 .. $]);
}
void main(string[] args)
{
log('c', 'm', 10);
}
More information about the Digitalmars-d-learn
mailing list