How to make a static immutable associative array using assocArray in CT?

realhet real_het at hotmail.com
Wed Feb 11 09:00:03 UTC 2026


On Tuesday, 10 February 2026 at 22:47:12 UTC, monkyyy wrote:
> On Tuesday, 10 February 2026 at 21:52:52 UTC, realhet wrote:
>> On Tuesday, 10 February 2026 at 21:14:29 UTC, monkyyy wrote:
>>> On Tuesday, 10 February 2026 at 20:46:11 UTC, realhet wrote:
>>>> Hi,
>>>
>
> enum stringofenum(alias T)=(){
> 	string[T] o;
> 	static foreach(t;__traits(allMembers, T)){
> 		o[mixin("T."~t)]=t;
> 	}
> 	return o;
> }();
>

That's it THX!  It creates the thing and I can assign that to 
anything later.

Now I understood that the trick was to avoid that particular 
assocArray overload function which has no clue about my enum type 
in CT.


More information about the Digitalmars-d-learn mailing list