On Monday, 2 April 2018 at 14:20:49 UTC, Dennis wrote:
On Monday, 2 April 2018 at 13:57:14 UTC, Vladimirs Nordholm wrote:
Is there any reason for me to add the @property tags for the method?

A list of things the @property tag does can be found here:
https://dlang.org/spec/function.html#property-functions

This behavior is particularly useful for generic code:
"For the expression typeof(exp) where exp is an @property function, the type is the return type of the function, rather than the type of the function."

Before I knew about this, I wrote this template to get the type of 'field', because typeof(field) would return 'int()' instead of 'int' when it was a getter function without @property.

```
template ReturnOrValueType(type)
{
        static if (isSomeFunction!(type.field)) {
                alias ReturnOrValueType = ReturnType!(typeof(type.field));
        }
        else {
                alias ReturnOrValueType = typeof(type.field);
        }
}
```

Ah! First time I read the docs I didn't understand the typeof(exp) explanation, but yours made me understand that part.

Do you think I should I omit the @property tag, if the only wanted behaviour is to set a value (`foo.bar = "baz";`) ?

Reply via email to