On Friday, 2 May 2014 at 15:18:06 UTC, Artur Skawina via
Digitalmars-d-learn wrote:
On 05/02/14 15:38, "Nordlöw" via Digitalmars-d-learn wrote:
template MemberNamesUnion(E...) if (allSatisfy!(isEnum, E))
{
bool[string] allMembers; // used to detect member
collisions
mixin({
string r = "enum MemberNamesUnion { ";
foreach (T; E) {
import std.range: join;
foreach (member; __traits(allMembers, T)) {
static assert (member in allMembers,
"Member collision");
allMembers[member] = true;
}
r ~= [__traits(allMembers, T)].join(",") ~ ",";
}
return r ~ " }";
}());
}
It fails as
enums.d(25,46): Error: static variable allMembers cannot be
read at compile time
enums.d(25,21): while evaluating: static assert("a" in
allMembers)
Is there a solution to this problem?
Move the AA declaration to inside the lambda, remove the
'static'
from the assert, and fix the condition ("member !in
allMembers"), then
it will work.
artur
But that will also move the compile time check to a runtime one.