Advertisement
Guest User

Untitled

a guest
Apr 16th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import std.meta : AliasSeq;
  2. import std.traits : CopyConstness;
  3.  
  4. alias Qualified(T) = AliasSeq!(T, const T, immutable T, inout T);
  5.  
  6. struct Mutable { size_t length() { return 1; } }
  7. struct Const { size_t length() const { return 2; } }
  8. struct Immutable { size_t length() immutable { return 3; } }
  9. struct Inout { size_t length() inout { return 4; } }
  10.  
  11. void main()
  12. {
  13. foreach (impl; AliasSeq!(empty, emptyInout))
  14. {
  15. foreach (T; AliasSeq!(Mutable, Const, Immutable, Inout))
  16. {
  17. foreach (Q; Qualified!T)
  18. {
  19. pragma (msg, "Calling: ", __traits(identifier, impl), "(", Q, ")");
  20. enum compiles = __traits(compiles, { impl(Q.init); });
  21. pragma (msg, " > compiles: ", compiles, "\n");
  22. }
  23. pragma (msg, "--\n");
  24. }
  25. }
  26. }
  27.  
  28. @property bool empty(T)(auto ref scope T a)
  29. {
  30. pragma (msg, " > Instantiating `empty!(", typeof(a), ")`");
  31. return !a.length;
  32. }
  33.  
  34. @property bool emptyInout(T)(auto ref scope inout(T) a)
  35. {
  36. pragma (msg, " > Instantiating `emptyInout!(", typeof(a), ")`");
  37. alias QT = CopyConstness!(typeof(T.init.length), T);
  38. return !(*cast(QT*)&a).length;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement