compile time printf -> .NET style format string conversion template.

Neal Alexander wqeqweuqy at hotmail.com
Thu Jan 3 04:46:58 PST 2008


Alright the basic idea behind this was:

- During tango porting i want all the stdlib wrapping done in 1 module.
- Any function that takes a format string cant be wrapped transparently 
without converting the string or doing something half baked (right?).

So i wrote this compile-time conversion template:

http://paste.dprogramming.com/dpjq2ug6 (See the FMT template for 
discussion purposes. The rest is just conversion/parsing).

Now for the questions:

- Why cant i do return x ~ FMT!(s[i .. $]); at line 106? This would 
avoid having to call skip() to count the fmt string length a 2nd time. 
The compiler complains s[i .. $] is an invalid argument or somethig.

- How do i template the print function so that the compiler retains the 
   immediateness of the format string arg.

with something like this you'd have to do:
---------------------------
void print(T...)(T t)
{
     version (Tango) Stdout.formatln(t);
     else            writefln(t);
}
print(FMT!("whatever %d"), 0);


where ideally you would want something like this:
---------------------------
void print(T...)(char[] fmt, T t)
{
     version (Tango) Stdout.formatln(FMT!(fmt), t);
     else            writefln(fmt, t);
}
print("whatever %d", 0);


More information about the Digitalmars-d-learn mailing list