Finding UDAs with Templates
Artur Skawina
art.08.09 at gmail.com
Tue Jul 23 03:59:58 PDT 2013
On 07/23/13 08:38, Jacob Carlborg wrote:
> static bool doesFieldSync (string field) ()
> {
> alias attrs = TypeTuple!(__traits(getAttributes, mixin("FileData." ~ field)));
> return staticIndexOf!(Sync, attrs) != -1;
> }
>
> The important things here are that __traits(getAttributes) returns a tuple. You cannot assign a tuple to a variable.
We can. :)
enum attrs = __traits... // `auto` would work too.
Just be careful and remember the `typeof(attrs)` part if/when
using staticIndexOf with types - it might otherwise return bogus
results (instead of failing).
staticIndexOf!(Sync, typeof(attrs))
artur
More information about the Digitalmars-d-learn
mailing list