how to determine if type is final/abstract
JS
js.mdnq at gmail.com
Fri Jul 12 00:21:41 PDT 2013
On Friday, 12 July 2013 at 06:38:54 UTC, Jacob Carlborg wrote:
> On 2013-07-12 00:45, JS wrote:
>
>> I believe the issue is that isFinalFunction requires an actual
>> function
>> symbol but I'm passing it a string?
>>
>>
>> How can I get this to work?
>
> Have you tried using a mixin?
>
> __traits(isFinalFunction, mixin(className ~ "." ~ member));
The issue is with the template being in a different module. Same
code works fine when in the same module...
module main;
import std.stdio, std.cstream, std.conv, std.traits, testmodule;
template test(alias i)
{
alias typeof(i) I;
static string eval()
{
enum name = "foo";
//enum qname = moduleName!(I)~"."~I.stringof~"."~name;
enum qname = I.stringof~"."~name;
pragma(msg, "main: "~qname);
return (__traits(isFinalFunction, mixin(qname))).stringof;
}
enum test = eval();
pragma(msg, "main: isfinal: "~test);
}
interface A
{
final void foo() { };
void foo(int x);
}
int main(string[] argv)
{
A a;
writeln(mixin(test!(a)));
writeln(mixin(test2!(a)));
din.getc();
return 0;
}
testmodule.d:
module testmodule;
import std.traits;
template test2(alias i)
{
alias typeof(i) I;
static string eval()
{
enum name = "foo";
enum qname = moduleName!(I)~"."~I.stringof~"."~name;
//enum qname = I.stringof~"."~name;
pragma(msg, "testmodule: "~qname);
return (__traits(isFinalFunction, mixin(qname))).stringof;
}
enum test2 = eval();
pragma(msg, "testmodule: isfinal: "~test2);
}
------------
note test2 fails even though it is the same code.
While this is probably a rather simple fix I would still have the
problem of checking if an overloaded function is actually final
rather than just the symbol name(which I guess is just the first
function).
More information about the Digitalmars-d-learn
mailing list