I have this little helper in my iopipe library:

template PropertyType(alias x)
{
    static if(is(typeof(x) == function))
        alias PropertyType = typeof(x());
    else
        alias PropertyType = typeof(x);
}

This is because when you have code like this:

x.foo

And you are introspecting some type, you can't tell whether this is a property function or a field.

If foo is a field, or a function marked as a @property, then typeof(x.foo) will be whatever x.foo returns. But if foo is a straight function, then typeof(x.foo) will be a function type.

As we all know, @property is not exactly popular, and having to mark functions @property just for introspection purposes (applying the tag actually has zero impact otherwise) seems incorrect.

But of course, if I want to know what type the expression x.foo will yield, I have to do the above.

Is there a use for this in Phobos? Is it already present somewhere? Where should it go if it's not there already?

-Steve

Reply via email to