Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- auto Foo(Char)(Char[] text)
- if ( !is(Char T : T[]) ) // Basically just ensure that `Char` isn't a string or array.
- {
- import std.stdio;
- Foo!(Char[]) foo;
- foo.payload = text;
- pragma(msg, "function Char.stringof == "~Char.stringof);
- return foo;
- }
- struct Foo(StrT)
- if ( is(StrT CharT : CharT[]) ) // Ensure that `StrT` is a string|array; declare `CharT` as it's element type.
- {
- StrT payload;
- pragma(msg, "struct StrT.stringof == " ~ StrT.stringof);
- /// Bonus jank: These fail to compile because `CharT` isn't declared /in this scope/.
- // CharT ch;
- // pragma(msg, "struct CharT.stringof == " ~ CharT.stringof);
- }
- void main()
- {
- import std.stdio;
- auto foo = Foo("x"); // IFTI for Foo constructor!
- writefln(foo.payload);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement