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
This email and its attachments may be confidential and are intended solely for the use of the individual to whom it is addressed. Any views or opinions expressed are solely those of the author and do not necessarily represent those of NeoNova. If you are not the intended recipient of this email and its attachments, you must take no action based upon them, nor must you copy or show them to anyone. Please contact the sender if you believe you have received this email in error.