Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.meta : AliasSeq;
- import std.traits : CopyConstness;
- alias Qualified(T) = AliasSeq!(T, const T, immutable T, inout T);
- struct Mutable { size_t length() { return 1; } }
- struct Const { size_t length() const { return 2; } }
- struct Immutable { size_t length() immutable { return 3; } }
- struct Inout { size_t length() inout { return 4; } }
- void main()
- {
- foreach (impl; AliasSeq!(empty, emptyInout))
- {
- foreach (T; AliasSeq!(Mutable, Const, Immutable, Inout))
- {
- foreach (Q; Qualified!T)
- {
- pragma (msg, "Calling: ", __traits(identifier, impl), "(", Q, ")");
- enum compiles = __traits(compiles, { impl(Q.init); });
- pragma (msg, " > compiles: ", compiles, "\n");
- }
- pragma (msg, "--\n");
- }
- }
- }
- @property bool empty(T)(auto ref scope T a)
- {
- pragma (msg, " > Instantiating `empty!(", typeof(a), ")`");
- return !a.length;
- }
- @property bool emptyInout(T)(auto ref scope inout(T) a)
- {
- pragma (msg, " > Instantiating `emptyInout!(", typeof(a), ")`");
- alias QT = CopyConstness!(typeof(T.init.length), T);
- return !(*cast(QT*)&a).length;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement