A template for method forwarding?
Christopher Wright
dhasenan at gmail.com
Sat Dec 13 06:29:19 PST 2008
Christian Kamm wrote:
>> So looks like bad stringof is the culprit, once again.
>
> Why use stringof when you have an alias? This works for me in D1 - if you
> discount default arguments and parameter storage classes (will templates
> ever be able to touch these?).
stringof sucks, but it's easy to work with.
Your solution doesn't deal with method overloads. Passing in a method
alias would work:
template Forward(string classname, alias method)
{
mixin ("ReturnTypeOf!(method) " ~ method.stringof ~
"(ParameterTupleOf!(Method) parameters) {
return composed." ~ method.stringof ~ "(parameters);
}");
}
Except method.stringof doesn't work, so you have to do it like this:
template strof(alias method)
{
const strof = (&method).stringof[2..$];
}
template Forward(char[] classname, alias method)
{
mixin ("ReturnTypeOf!(method) " ~ strof!(method) ~
"(ParameterTupleOf!(method) parameters) {
return composed." ~ strof!(method) ~ "(parameters); }");
}
More information about the Digitalmars-d
mailing list