Source code annotations alla Java
Jacob Carlborg
doob at me.com
Thu Jan 20 12:43:21 PST 2011
On 2011-01-20 20:10, Trass3r wrote:
>> class Foo
>> {
>> int x;
>> int y;
>> int z;
>>
>> mixin NonSerialized!(z);
>> }
>
> Had a quick look at
> http://dsource.org/projects/orange/browser/orange/serialization/Serializable.d
>
> 1. How come it works without 'mixin' in the template declaration (mixin
> template NonSerialized)?
I think it's optional, it works with DMD 2.052
> 2. What if several fields need to be tagged?
You use the mixin several times.
> 3. Is there a reason to use a struct instead of e.g. __nonSerialized =
> ["field1", "field2", ...]?
Hmm, I think I had a good reason. First it needs to be const so it works
during compile time. But I think I used a struct because I used that on
another project which required more data than just then name the field.
If I would store it in an array you could only do the mixin once, I
think. And that would require you to use strings instead of aliases, I
think.
template foo (args...) {}
Does that work with aliases?
> 4. Couldn't that field be static to save space or maybe even enum?
That field should absolutely be static, I'm currently working on fixing
that. I didn't think of that when I implemented it. This will also only
work with one mixin (see the answer for the third comment).
--
/Jacob Carlborg
More information about the Digitalmars-d-learn
mailing list