How to concatenate a tuple of strings at compile time?
paul
paul at example.com
Sat Jan 6 19:35:33 UTC 2018
Hi!
How to concatenate a tuple of strings at compile time?
Appending to an enum or an immutable string in a static foreach
doesn't work. (And shadowing the thing doesn't work either) a)
Calling a function recursively doesn't work because I had to turn
the tuple into an array which cannot be read at compile time. b)
a)
enum/immutable string connected;
static foreach(item; __traits(something))
connected ~= item;
b)
string concat(string[] a, string b = "", index i = 0)
{
if (s.length - 1 == index)
{
return b ~ a[$-1];
} else {
return concat(a,b[index],index+1);
}
}
concat([__traits(something)]);
An internet search didn't reward any solution but probably I'm
just missing something very trivial.
Any clues would be very appreciated. Thanks.
On a different note, what I want to achieve is to automatically
generate a function call that hides the fact of a struct being
initialized.
something like this:
struct X
{
int a;
string b;
}
class C
{
X _x;
this(int a, string b)
{
_x = X(a, b);
}
}
More information about the Digitalmars-d-learn
mailing list