May 02, 2014 Re: Making enum join variadic | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | > So that leaves me with using an array of bool and rank() then, I guess...
Correction: I mean array of strings and find.
|
May 02, 2014 Re: Making enum join variadic | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | 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
|
May 02, 2014 Re: Making enum join variadic | ||||
---|---|---|---|---|
| ||||
Posted in reply to Artur Skawina | 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.
|
May 02, 2014 Re: Making enum join variadic | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | On 05/02/14 17:27, Meta via Digitalmars-d-learn wrote:
> 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.
>
> But that will also move the compile time check to a runtime one.
No; mixin arguments are always evaluated at CT.
artur
|
May 02, 2014 Re: Making enum join variadic | ||||
---|---|---|---|---|
| ||||
Posted in reply to Artur Skawina | > artur Collision detection should now be complete. https://github.com/nordlow/justd/blob/master/enums.d Superb! |
Copyright © 1999-2021 by the D Language Foundation