chadjoan

地獄()

Jul 31st, 2020 (edited)
1,315
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Test program for determining if alias-this symbols are included
  2. // in __traits's getOverloads results.
  3. // (Spoilers: They are not.)
  4. import std.stdio;
  5.  
  6. struct Foo
  7. {
  8.     int doTheThing()
  9.     {
  10.         return 57;
  11.     }
  12. }
  13.  
  14. struct Bar
  15. {
  16.     Foo foo;
  17.     alias foo this;
  18.  
  19.     string doTheThing(float ifYouSaySo)
  20.     {
  21.         import std.conv;
  22.         return "If you say so: "~ifYouSaySo.to!string;
  23.     }
  24. }
  25.  
  26. void main()
  27. {
  28.     // The below prints "string(float ifYouSaySo)" as of dmd 2.093.
  29.     // Foo's version of the function is callable, but does not appear
  30.     // in the overload list.
  31.  
  32.     foreach( func; __traits(getOverloads, Bar, "doTheThing", true) )
  33.         writeln(typeof(func).stringof);
  34. }
RAW Paste Data