static foreach / How to construct concatenated string?
MoonlightSentinel
moonlightsentinel at disroot.org
Sat Mar 7 16:41:47 UTC 2020
On Saturday, 7 March 2020 at 16:30:59 UTC, Robert M. Münch wrote:
> Is this possible at all?
You can use an anonymous lambda to build the string in CTFE:
------------------------------------------
struct S {
int a;
bool b;
}
import std;
enum string sql = {
string s = "CREATE TABLE data(";
static foreach(f; FieldNameTuple!S) {
s ~= f ~ ",";
}
s ~= ");";
return s;
} ();
pragma(msg, sql);
------------------------------------------
This prints "CREATE TABLE data(a, b);"
More information about the Digitalmars-d-learn
mailing list