Warning: statement is not reachable

ag0aep6g via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Mar 1 14:04:53 PST 2016


On 01.03.2016 22:30, Tamas wrote:
>      struct Tag {}
>
>      template isTagged(S) {
>        enum bool isTagged =
>          delegate() {
>            foreach(attr; __traits(getAttributes, S)) {
>              static if (is(attr == Tag)) {
>                return true;
>              }
>            }
>            return false;
>          }();
>      }

This is off topic, but you can use std.meta.staticIndexOf to check if 
something is in an alias seq:

----
template isTagged(S) {
     import std.meta: staticIndexOf;
     enum bool isTagged =
         staticIndexOf!(Tag, __traits(getAttributes, S)) >= 0;
}
----

And for UDAs in particular there is std.traits.hasUDA:

----
template isTagged(S) {
     import std.traits: hasUDA;
     enum bool isTagged = hasUDA!(S, Tag);
}
----


More information about the Digitalmars-d-learn mailing list