getUDAs

  1. template getUDAs(alias symbol, alias attr)
  2. alias getUDAs(alias symbol) = AliasSeq!(__traits(getAttributes, symbol))
    alias getUDAs(alias symbol) = AliasSeq!(__traits(getAttributes, symbol))

Examples

static struct Attr
{
    int i;
}
@Attr int a;
static assert(getUDAs!(a, Attr).length == 1);

@Attr(8) int b;
static assert(getUDAs!(b, Attr).length == 1);
static assert(getUDAs!(b, Attr)[0].i == 8);
static assert(getUDAs!(b, Attr(8)).length == 1);
static assert(getUDAs!(b, Attr(7)).length == 0);

@("string", 5) int c;
static assert(getUDAs!(c, "string").length == 1);
static assert(getUDAs!(c, 5).length == 1);
static assert(getUDAs!(c, "String").length == 0);
static assert(getUDAs!(c, 4).length == 0);

static struct T(U)
{
    enum U s = 7;
    U i;
}
@T!int @T!int(8) int d;
static assert(getUDAs!(d, T).length == 2);
static assert(getUDAs!(d, T)[0].s == 7);
static assert(getUDAs!(d, T)[1].i == 8);

@T int e;
static assert(getUDAs!(e, T).length == 0);

Meta