Detecting a property setter?

Rory McGuire rmcguire at neonova.co.za
Mon Jul 19 12:51:16 PDT 2010


Hi,

Does anyone know how to detect if there is a setter for a property? The  
code below prints the same thing for both
the setter and the getter of "front":

==============================
import std.traits;

class Foo {
     uint num;

     @property ref uint front() {
         return num;
     }
     @property void front(uint i) {
         num = i;
     }

     ref uint front2() {
     	return num;
     }
}

template isProperty(alias func) if (isCallable!(func)) {
	enum isProperty = (functionAttributes!(func) &  
FunctionAttribute.PROPERTY)==0 ? false : true;
}

template hasSetter(alias func) if (isCallable!(func)) {
	enum hasSetter = (isProperty!(func) && ParameterTypeTuple!(func).length >  
0 && ReturnType!(func).stringof != "void") ? true : false;
}

void main() {
     Foo foo;
	pragma(msg, hasSetter!(foo.front));
	
	static if (isProperty!(foo.front)) {
		pragma(msg, "property");
	} else {
		pragma(msg, "not a property");
	}
	
	alias MemberFunctionsTuple!(Foo,"front") fronts;
	foreach (s; fronts) {
		pragma(msg, ReturnType!(s)); // this line just prints "uint" for both  
"front" properties!
	}
}
============================


Is this a compiler bug? Or am I wrong again?

Thanks
Rory


www.neonova.co.za: http://cf.neonova.co.za/9YXp
View: https://mail1.clearformat.com/vcard.php?uid=11&pid=10
Beta Test Advert: http://fwd.clearformat.com/9YXn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20100719/294691bc/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: logo.jpg
Type: image/jpeg
Size: 4855 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20100719/294691bc/attachment.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ff2d54b.jpg
Type: image/jpeg
Size: 7452 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20100719/294691bc/attachment-0001.jpg>


More information about the Digitalmars-d-learn mailing list