Re: How to call function with variable arguments at runtime?

2017-10-11 Thread Mr. Jonse via Digitalmars-d-learn
On Tuesday, 10 October 2017 at 08:26:37 UTC, Marc Schütz wrote: On Tuesday, 10 October 2017 at 02:58:45 UTC, Mr. Jonse wrote: I need to store a hetrogeneous array of delegates. How can I do this but still call the function with the appropriate number of parameters at run time? I have the

Re: How to call function with variable arguments at runtime?

2017-10-10 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 10 October 2017 at 02:58:45 UTC, Mr. Jonse wrote: I need to store a hetrogeneous array of delegates. How can I do this but still call the function with the appropriate number of parameters at run time? I have the parameters as Variant[] params and a function/delegate

Re: How to call function with variable arguments at runtime?

2017-10-10 Thread bauss via Digitalmars-d-learn
On Tuesday, 10 October 2017 at 02:58:45 UTC, Mr. Jonse wrote: I need to store a hetrogeneous array of delegates. How can I do this but still call the function with the appropriate number of parameters at run time? I have the parameters as Variant[] params and a function/delegate

How to call function with variable arguments at runtime?

2017-10-09 Thread Mr. Jonse via Digitalmars-d-learn
I need to store a hetrogeneous array of delegates. How can I do this but still call the function with the appropriate number of parameters at run time? I have the parameters as Variant[] params and a function/delegate pointer(void* for now). Normally I'd push the parameters on the stack and

Re: Variable Arguments

2017-04-09 Thread rikki cattermole via Digitalmars-d-learn
On 09/04/2017 7:30 AM, Jethro wrote: void foo(A...)(A a) { foreach(aa; a) { for(int i = 0; i < a.length; i++) ... } } A can be strings or char, how can I easily deal with both? (e.g., a.length = 1 for a being a char... and also a[0] = a, so to speak). That is, I

Variable Arguments

2017-04-09 Thread Jethro via Digitalmars-d-learn
void foo(A...)(A a) { foreach(aa; a) { for(int i = 0; i < a.length; i++) ... } } A can be strings or char, how can I easily deal with both? (e.g., a.length = 1 for a being a char... and also a[0] = a, so to speak). That is, I want chars to be treated as

Re: vsprintf or printf variable arguments

2016-08-06 Thread Patrick Schluter via Digitalmars-d-learn
On Friday, 5 August 2016 at 08:32:42 UTC, kink wrote: On Thursday, 4 August 2016 at 21:03:52 UTC, Mark "J" Twain wrote: How can I construct a va_list for vsprintf when all I have is the a list of pointers to the data, without their type info? A va_list seems to be a packed struct of values

Re: vsprintf or printf variable arguments

2016-08-05 Thread flamencofantasy via Digitalmars-d-learn
On Friday, 5 August 2016 at 19:21:38 UTC, Mark "J" Twain wrote: On Friday, 5 August 2016 at 08:32:42 UTC, kink wrote: On Thursday, 4 August 2016 at 21:03:52 UTC, Mark "J" Twain [...] This has absolutely nothing to do with D as these are C functions, so you'd be better off asking this in

Re: vsprintf or printf variable arguments

2016-08-05 Thread Mark J Twain via Digitalmars-d-learn
On Friday, 5 August 2016 at 08:32:42 UTC, kink wrote: On Thursday, 4 August 2016 at 21:03:52 UTC, Mark "J" Twain [...] This has absolutely nothing to do with D as these are C functions, so you'd be better off asking this in another forum. Um, then I wonder why I am using D? Why does D even

Re: vsprintf or printf variable arguments

2016-08-05 Thread kink via Digitalmars-d-learn
On Thursday, 4 August 2016 at 21:03:52 UTC, Mark "J" Twain wrote: How can I construct a va_list for vsprintf when all I have is the a list of pointers to the data, without their type info? A va_list seems to be a packed struct of values and/or pointers to the data. While I could construct

Re: vsprintf or printf variable arguments

2016-08-04 Thread Mark J Twain via Digitalmars-d-learn
On Thursday, 4 August 2016 at 21:03:52 UTC, Mark "J" Twain wrote: How can I construct a va_list for vsprintf when all I have is the a list of pointers to the data, without their type info? A va_list seems to be a packed struct of values and/or pointers to the data. While I could construct

vsprintf or printf variable arguments

2016-08-04 Thread Mark J Twain via Digitalmars-d-learn
How can I construct a va_list for vsprintf when all I have is the a list of pointers to the data, without their type info? A va_list seems to be a packed struct of values and/or pointers to the data. While I could construct such a list, theoretically, I don't always know when I should store

Re: Variable arguments with file and line information?

2013-11-17 Thread Chris Nicholson-Sauls
On Saturday, 16 November 2013 at 23:55:47 UTC, Jonathan M Davis wrote: If you're dealing with variadic arguments, then making the file and line number be template arguments is really your only solution. However, I must warn you that that will result in a new template instantation _every_

Re: Variable arguments with file and line information?

2013-11-17 Thread Dicebot
What are the chances of the middle-man function being inlined, thus cutting down on template bloat in the final product? I should hope it would be practically guaranteed. Even full inlining can't and won't do anything about template bloat within D semantics. This approach will, however,

Re: Variable arguments with file and line information?

2013-11-17 Thread Jonathan M Davis
On Sunday, November 17, 2013 13:06:11 Chris Nicholson-Sauls wrote: Something I'm wondering: if one were to split the implementation along these lines: void error (string file = __FILE__, size_t line = __LINE__, Args...) (string msg, Args args) { errorImpl(file, line, msg, args); }

Re: Variable arguments with file and line information?

2013-11-17 Thread Dmitry Olshansky
17-Nov-2013 16:36, Jonathan M Davis пишет: On Sunday, November 17, 2013 13:06:11 Chris Nicholson-Sauls wrote: Something I'm wondering: if one were to split the implementation along these lines: void error (string file = __FILE__, size_t line = __LINE__, Args...) (string msg, Args args) {

Re: Variable arguments with file and line information?

2013-11-17 Thread Jonathan M Davis
On Sunday, November 17, 2013 16:49:11 Dmitry Olshansky wrote: At least we should fix this embarrassing limitation that kills inlining of std.ascii on ALL compilers. https://d.puremagic.com/issues/show_bug.cgi?id=10985 And it's not only std.ascii pretty much all non-templated stuff. Yeah,

Re: Variable arguments with file and line information?

2013-11-17 Thread Rob T
On Saturday, 16 November 2013 at 23:55:47 UTC, Jonathan M Davis wrote: [...] e.g. force the caller to call format when creating the message rather than supporting variadic arguments directly in error. - Jonathan M Davis OK, how about this implementation? string msg( S : string, T... )( S

Re: Variable arguments with file and line information?

2013-11-17 Thread Jonathan M Davis
On Sunday, November 17, 2013 20:11:20 Rob T wrote: On Saturday, 16 November 2013 at 23:55:47 UTC, Jonathan M Davis wrote: [...] e.g. force the caller to call format when creating the message rather than supporting variadic arguments directly in error. - Jonathan M Davis OK,

Re: Variable arguments with file and line information?

2013-11-17 Thread Rob T
Good points, got it down to this. void error(string a_Msg, string file = __FILE__, size_t line = __LINE__) { writefln( a_Msg ~ . In file %s on line %d., file, line ); } int main() { format(hallo).error; format(Hallo %s., du da).error; } There should be no more template bloat, and it

Re: Variable arguments with file and line information?

2013-11-17 Thread Jonathan M Davis
On Sunday, November 17, 2013 22:08:38 Rob T wrote: Good points, got it down to this. void error(string a_Msg, string file = __FILE__, size_t line = __LINE__) { writefln( a_Msg ~ . In file %s on line %d., file, line ); } int main() { format(hallo).error; format(Hallo %s.,

Re: Variable arguments with file and line information?

2013-11-17 Thread Rob T
On Sunday, 17 November 2013 at 21:29:03 UTC, Jonathan M Davis wrote: Yeah. Don't use concatenation in your format string: Right, that concat was bothering me too. Tks for the input. --rt

Variable arguments with file and line information?

2013-11-16 Thread Namespace
Hi. Is it possible to write something like that? void error(Args...)(string msg, Args args, string file = __FILE__, size_t line = __LINE__) { ... } ? Currently not, but how could it be done? I wont like to write: error(format(msg, args)); Thanks in advance. :)

Re: Variable arguments with file and line information?

2013-11-16 Thread Namespace
On Saturday, 16 November 2013 at 22:57:35 UTC, Namespace wrote: Hi. Is it possible to write something like that? void error(Args...)(string msg, Args args, string file = __FILE__, size_t line = __LINE__) { ... } ? Currently not, but how could it be done? I wont like to write:

Re: Variable arguments with file and line information?

2013-11-16 Thread Jonathan M Davis
On Sunday, November 17, 2013 00:09:53 Namespace wrote: On Saturday, 16 November 2013 at 22:57:35 UTC, Namespace wrote: Hi. Is it possible to write something like that? void error(Args...)(string msg, Args args, string file = __FILE__, size_t line = __LINE__) { ... } ?

Re: Variable arguments with file and line information?

2013-11-16 Thread bearophile
Namespace: It is always surprising how quickly one has found its own solution, after you have posted here... :) This is a well known psychological phenomenon: when you explain your problem to other people you lay down the problem very well, its constraints, its invariants, your needs, and

Re: Variable arguments with file and line information?

2013-11-16 Thread Timothee Cour
unfortunately this problem keeps arising every so often and the only thing we have are workarounds to name a few: digitalmars.D - Typesafe variadics in any position feature request: special optional argument (__FILE__, ...) AFTER variadic template On Sat, Nov 16, 2013 at 3:55 PM, Jonathan M

What is the proper way to handle pointers in variable arguments list?

2012-10-28 Thread Tyro[17]
The following fails because the compiler assumes I am trying to dereference non-pointer variables. Can this be done? void main() { int i; int* pi; double d; double* pd; char c; char* pc; scan(i, pi, d, pd, c, pc); } void scan(A...)(ref A data) { import

Re: What is the proper way to handle pointers in variable arguments list?

2012-10-28 Thread Dmitry Olshansky
On 29-Oct-12 00:36, Tyro[17] wrote: The following fails because the compiler assumes I am trying to dereference non-pointer variables. Can this be done? void main() { int i; int* pi; double d; double* pd; char c; char* pc; scan(i, pi, d, pd, c, pc); } void

Re: What is the proper way to handle pointers in variable arguments list?

2012-10-28 Thread Tyro[17]
On 10/28/12 4:44 PM, Dmitry Olshansky wrote: On 29-Oct-12 00:36, Tyro[17] wrote: The following fails because the compiler assumes I am trying to dereference non-pointer variables. Can this be done? void main() { int i; int* pi; double d; double* pd; char c; char*

Re: What is the proper way to handle pointers in variable arguments list?

2012-10-28 Thread Simen Kjaeraas
On 2012-08-28 22:10, Tyro[17] nos...@home.com wrote: On 10/28/12 4:44 PM, Dmitry Olshansky wrote: On 29-Oct-12 00:36, Tyro[17] wrote: The following fails because the compiler assumes I am trying to dereference non-pointer variables. Can this be done? void main() { int i; int* pi;

Re: What is the proper way to handle pointers in variable arguments list?

2012-10-28 Thread Tyro[17]
On 10/28/12 5:16 PM, Simen Kjaeraas wrote: On 2012-08-28 22:10, Tyro[17] nos...@home.com wrote: On 10/28/12 4:44 PM, Dmitry Olshansky wrote: On 29-Oct-12 00:36, Tyro[17] wrote: The following fails because the compiler assumes I am trying to dereference non-pointer variables. Can this be