http://d.puremagic.com/issues/show_bug.cgi?id=6207
Summary: Mixin template evaluated to string can convert to
string mixin expression implicitly
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: [email protected]
ReportedBy: [email protected]
--- Comment #0 from Kenji Hara <[email protected]> 2011-06-24 03:48:28 PDT ---
If mixin template instantiation makes manifest constant string and it appears
in expression context, the compiler converts it implicitly to string mixin
expression.
This enhancement feature does not conflict with any existing features.
Because normal instantiating with mixin template is illegal.
Sample code:
----
mixin template expand(string code)
{
static if (code.length >= 2 && code[0..2] == "$x")
{
enum expand = `x` ~ code[2..$];
pragma(msg, expand);
}
else
enum expand = code;
}
void main()
{
int x = 1;
int y = expand!q{$x+2};
// Rhs is implicitly converted to mixin(expand!(q{$x+2}))
assert(y == 3);
}
----
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------