Concat enum of strings into one string
vit
vit at vit.vit
Tue Aug 14 16:03:05 UTC 2018
On Tuesday, 14 August 2018 at 14:37:33 UTC, Andrey wrote:
> On Tuesday, 14 August 2018 at 14:07:23 UTC, Timoses wrote:
>> Here's one version:
>>
>> template StringEnumValues(alias Enum)
>> {
>> import std.traits : EnumMembers;
>> string[] StringEnumValues()
>> {
>> string[] enumValues;
>> static foreach (member; EnumMembers!Enum)
>> enumValues ~= member;
>> return enumValues;
>> }
>> }
>>
>> import std.string : join;
>> pragma(msg, StringEnumValues!Type.join(" "));
>
> Thank you. Hmm, I thought that standard library already has
> this stuff.
import std.traits : EnumMembers;
import std.string : join;
import std.algorithm : map;
pragma(msg, [EnumMembers!Type].map!(x => cast(string)x).join("
"));
More information about the Digitalmars-d-learn
mailing list