Compile time string manipulation
js.mdnq
js_adddot+mdng at gmail.com
Sat Dec 15 00:47:33 PST 2012
How do we manipulate strings at compile time when using static
ifs?
static if (std.string.indexOf(S, ")") < -1)
...
else
...
This always returns false regardless if S contains a 7 or not.
from http://dpaste.dzfl.pl/64025e0a
mixin(StructNestType!("B", "b1"));
but I would like to modify so that I can do this
_Offset
as at the moment StructNestType2 doesn't handle struct's with
more than 1 type parameter. I simply need to parse the string and
determine if it contains type arguments.
e.g.,
struct B(T1,T2, int offset) { ... }
mixin(StructNestType!("B!(T1,T2)", "b1")); // (hide offset in
string, not needed explicitly)
but I also need the code to work with
struct B(int offset) { ... }
mixin(StructNestType!("B", "b1"));
So I need to compare and replace the string to make it fit into
StructNestType2. (as of right now I'm assuming only one argument,
the ofs)
I thought CTFE would work with indexOf but I guess it won't?
Essentially I need to form B!(T1,T2, _my offset value_) and/or
B!(_my offset value_) from the two cases above at compile time.
More information about the Digitalmars-d-learn
mailing list