Re: Concat enum of strings into one string

2018-08-15 Thread Andrey via Digitalmars-d-learn
On Tuesday, 14 August 2018 at 16:03:05 UTC, vit wrote: import std.traits : EnumMembers; import std.string : join; import std.algorithm : map; pragma(msg, [EnumMembers!Type].map!(x => cast(string)x).join(" ")); Thank you! Jonathan M Davis, I understood.

Re: Concat enum of strings into one string

2018-08-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, August 14, 2018 8:37:33 AM MDT Andrey via Digitalmars-d-learn 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()

Re: Concat enum of strings into one string

2018-08-14 Thread vit via Digitalmars-d-learn
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

Re: Concat enum of strings into one string

2018-08-14 Thread Timoses via Digitalmars-d-learn
On Tuesday, 14 August 2018 at 14:37:33 UTC, Andrey wrote: Thank you. Hmm, I thought that standard library already has this stuff. There might be more elegant solutions and I'd be happy to see some more. I'm always just digging into std.traits [1] and Traits spec part [2] and try to fumble thi

Re: Concat enum of strings into one string

2018-08-14 Thread Andrey via Digitalmars-d-learn
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

Re: Concat enum of strings into one string

2018-08-14 Thread Timoses via Digitalmars-d-learn
On Tuesday, 14 August 2018 at 13:42:04 UTC, Andrey wrote: Hello, I have a enum: enum Type : string { One = "Q1", Two = "W2", Three = "R3" } I want to concat it in compile-time: enum result = doConcat!Type(); And get this result: writeln(result); // output: "Q1 W2 R3" Delimiter h

Re: Concat enum of strings into one string

2018-08-14 Thread Andrey via Digitalmars-d-learn
On Tuesday, 14 August 2018 at 13:45:48 UTC, Mike Franklin wrote: I think you just need to use the concatenation operator `~`. enum Type : string { One = "Q1", Two = "W2", Three = "R3" } enum concatenation = Type.One ~ " " ~ Type.Two ~ " " ~ Type.Three; void main() { import st

Re: Concat enum of strings into one string

2018-08-14 Thread Mike Franklin via Digitalmars-d-learn
On Tuesday, 14 August 2018 at 13:42:04 UTC, Andrey wrote: Hello, I have a enum: enum Type : string { One = "Q1", Two = "W2", Three = "R3" } I want to concat it in compile-time: enum result = doConcat!Type(); And get this result: writeln(result); // output: "Q1 W2 R3" Delimiter h

Concat enum of strings into one string

2018-08-14 Thread Andrey via Digitalmars-d-learn
Hello, I have a enum: enum Type : string { One = "Q1", Two = "W2", Three = "R3" } I want to concat it in compile-time: enum result = doConcat!Type(); And get this result: writeln(result); // output: "Q1 W2 R3" Delimiter here is space symbol. How do do it?