fork download
  1. int x = 42;
  2.  
  3. void printIfDefined(alias name)()
  4. {
  5. import std.stdio: writeln;
  6. static if( __traits(compiles, writeln(mixin(name))))
  7. writeln(mixin(name));
  8. }
  9.  
  10. void main(string[] args)
  11. {
  12. printIfDefined!"x";
  13. printIfDefined!"Foo.bar";
  14. }
Success #stdin #stdout 0s 2628KB
stdin
Standard input is empty
stdout
42