Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import std;
  2.  
  3. struct Box(T)
  4. {
  5.     T thing;
  6.  
  7.     this(T newThing)
  8.     {
  9.         thing = newThing;
  10.     }
  11. }
  12.  
  13. void main()
  14. {
  15.     Box!int someInt = Box!int(5);
  16.     Box!string someString = Box!string("flerrp");
  17.     Box!bool someBool = Box!bool(true);
  18.  
  19.     static if (__traits(compiles, someInt.thing + 1))
  20.     {
  21.         writeln(someInt.thing + 5);
  22.     }
  23.     else static if (__traits(compiles, someString.thing ~= "asdf"))
  24.     {
  25.         someString.thing ~= " flirrp";
  26.         writeln(someString.thing);
  27.     }
  28.     else static if (__traits(compiles, someBool.thing = false))
  29.     {
  30.         someBool.thing = false;
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement