how to determine if type is final/abstract

JS js.mdnq at gmail.com
Thu Jul 11 16:15:31 PDT 2013


On Thursday, 11 July 2013 at 23:04:20 UTC, JS wrote:
> On Thursday, 11 July 2013 at 22:45:47 UTC, JS wrote:
>> I have some code that needs to determine if a type 
>> isFinalFunction or isAbstractFunction but they don't seem to 
>> work:
>>
>>    foreach(k, t; TargetMembers)
>>    {
>>        alias TypeTuple!(t.type)[0] type;
>>        if (isFinalFunction!(t)) { ... }
>>    }
>>
>> the if statement never gets executed. I've tried using type 
>> instead of t and various other things. I suppose the
>>
>> the function is defined as
>>
>> final string foo() { ...}
>>
>> but TargetMembers is
>>
>> "tuple(FuncInfo!("foo", pure nothrow @safe string()), 
>> FuncInfo!("Value", @property int()), FuncInfo!("Value", 
>> @property int(int value)))"
>>
>> 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?
>
> much of the code used can be found at 
> http://dpaste.dzfl.pl/209e260b.
>
> I can get the attributes of the function no problem and 
> implement the interface except for final functions, which try 
> to get implemented again... hence I need to prevent 
> reimplementation of final functions but seem to have no way to 
> determine if a function is final.

I've also tried __traits and other stuff. I have access to the 
interface and I've tried hard coding the name and other stuff... 
Using them on simple example case works so it is an issue with 
the code, here is the full code:


http://dpaste.dzfl.pl/16bc4a7e

just mixin the templates to use use them, e.g.,



interface A(T)
{
	final string foo() { return ""; }
	mixin tPropertyBuilder!(0, T);
	alias Value this;
}


class B(T) : A!T
{
	@property T Value() { return _value; }
	mixin tPropertyImplementer!(0, T); // implements foo, causes 
compile time error. should not implement final members.
}


More information about the Digitalmars-d-learn mailing list