On Saturday, 28 May 2016 at 14:11:56 UTC, Lodovico Giaretta wrote:
On Saturday, 28 May 2016 at 14:01:35 UTC, Era Scarecrow wrote:
 Do you still want the template i'm building?

Thank you very much for your effort.
Please if you don't need it, don't make it, because I don't know if I'll use it.

Well here's what i got. Maybe someone else will tell me how i did this wrong...

[code]
import std.traits;

template areAllFunctionsSafe(T)
if (!isNested!T) { //nested may be lifted later when i fix this
  enum areAllFunctionsSafe = check();

  bool check() {
    foreach(member; __traits(allMembers, T)) {
      static if(isCallable!(__traits(getMember, T, member))) {
        if (!isSafe!(__traits(getMember, T, member)))
          return false;
      }
    }
    return true;
  }
}

unittest {
  static struct S {
    int y;
    void foo() @safe {}
    void bar() @safe {}
  }
  static struct S2 {
    int y;
    void foo() @safe {}
    void bar() {}
  }

  assert(areAllFunctionsSafe!S);
  assert(!areAllFunctionsSafe!S2);
}
[/code]

Reply via email to