Thread overview | |||||
---|---|---|---|---|---|
|
March 04, 2016 Forwarding varadic function arguments | ||||
---|---|---|---|---|
| ||||
//f is a File* void fwrite(int line = __LINE__)(...) { f.write("/*",line,"*/ "); f.write(_argptr); //prints e.g 7FFF5B055440 } basically i want fwrite("1 ","2\t","3\n"); to print /*7*/ 1 2 3 do I have to iterate through _argptr |
March 03, 2016 Re: Forwarding varadic function arguments | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nicholas Wilson | On 03/03/2016 04:50 PM, Nicholas Wilson wrote: > //f is a File* > void fwrite(int line = __LINE__)(...) > { > f.write("/*",line,"*/ "); > f.write(_argptr); //prints e.g 7FFF5B055440 > } > basically i want > fwrite("1 ","2\t","3\n"); > to print > /*7*/ 1 2 3 > > do I have to iterate through _argptr I think so. Also noting that C-style varargs can only work with fundamental types (Am I correct there? I am carrying this assumption from C++.), you may be happier with a template-parameter solution: import std.stdio; File f; static this() { f = File("hello_world.txt", "w"); } //f is a File* void fwrite(int line = __LINE__, Args...)(Args args) { f.write("/*",line,"*/ "); f.write(args); } void main() { fwrite("1 ","2\t","3\n"); } Ali |
March 04, 2016 Re: Forwarding varadic function arguments | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Friday, 4 March 2016 at 01:13:37 UTC, Ali Çehreli wrote:
> On 03/03/2016 04:50 PM, Nicholas Wilson wrote:
> > [...]
>
> I think so. Also noting that C-style varargs can only work with fundamental types (Am I correct there? I am carrying this assumption from C++.), you may be happier with a template-parameter solution:
>
> import std.stdio;
>
> File f;
>
> static this() {
> f = File("hello_world.txt", "w");
> }
>
>
> //f is a File*
> void fwrite(int line = __LINE__, Args...)(Args args)
> {
> f.write("/*",line,"*/ ");
> f.write(args);
> }
>
> void main() {
> fwrite("1 ","2\t","3\n");
> }
>
> Ali
The template works great.
Thanks!
|
Copyright © 1999-2021 by the D Language Foundation