Re: How to properly use variadic templates (functions)?

2021-12-22 Thread eugene via Digitalmars-d-learn
sorry for intervening... :) On Wednesday, 22 December 2021 at 08:17:03 UTC, rempas wrote: No garbage collector, no exceptions GOLDEN WORDS!!! Yeah, Seriously D's developers and user really underestimate the fact that the biggest percent of people not using D are doing so because of the

Re: How to properly use variadic templates (functions)?

2021-12-22 Thread rempas via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 22:50:57 UTC, russhy wrote: I took a look and to be honest, it's the same story as everything in the STD, they try to do everything at the same time, so they up end calling each other, you end up lost in multiple 8k LOC modules, not understanding what the

Re: How to properly use variadic templates (functions)?

2021-12-21 Thread russhy via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 18:51:38 UTC, Stanislav Blinov wrote: On Tuesday, 21 December 2021 at 15:42:59 UTC, russhy wrote: Please keep us updated, that'll be interesting to see how a pure D printf would look like! It already exists, it's called std.format.write.formattedWrite, in

Re: How to properly use variadic templates (functions)?

2021-12-21 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 15:42:59 UTC, russhy wrote: Please keep us updated, that'll be interesting to see how a pure D printf would look like! It already exists, it's called std.format.write.formattedWrite, in terms of which things like std.stdio.writef are implemented.

Re: How to properly use variadic templates (functions)?

2021-12-21 Thread rempas via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 17:33:09 UTC, Steven Schveighoffer wrote: The reason your original isn't working is that indexing a list of differently-typed things cannot be done using a runtime index. I'd say that an inner function + static foreach + switch is the best way to convert

Re: How to properly use variadic templates (functions)?

2021-12-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/21/21 4:28 AM, rempas wrote: On Tuesday, 21 December 2021 at 08:42:35 UTC, vit wrote: You can use switch + static foreach: ```d import std.stdio;     //this print args in reverse order:     void print(T...)(string prompt, T args)     {     void print_arg(size_t index){    

Re: How to properly use variadic templates (functions)?

2021-12-21 Thread rempas via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 15:42:59 UTC, russhy wrote: Please keep us updated, that'll be interesting to see how a pure D printf would look like! Glad someone is interested! I'm actually planning to make a whole library ;) Check my

Re: How to properly use variadic templates (functions)?

2021-12-21 Thread russhy via Digitalmars-d-learn
Please keep us updated, that'll be interesting to see how a pure D printf would look like!

Re: How to properly use variadic templates (functions)?

2021-12-21 Thread rempas via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 08:42:35 UTC, vit wrote: You can use switch + static foreach: ```d import std.stdio; //this print args in reverse order: void print(T...)(string prompt, T args) { void print_arg(size_t index){ switch(index){

Re: How to properly use variadic templates (functions)?

2021-12-21 Thread vit via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 08:26:17 UTC, rempas wrote: On Tuesday, 21 December 2021 at 08:11:39 UTC, Anonymouse wrote: I'm not certain I understand, but won't `foreach (i, a; args) { /* ... */ }` in his example do that? As in, if you necessarily must index `args` instead of using a

Re: How to properly use variadic templates (functions)?

2021-12-21 Thread rempas via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 08:11:39 UTC, Anonymouse wrote: I'm not certain I understand, but won't `foreach (i, a; args) { /* ... */ }` in his example do that? As in, if you necessarily must index `args` instead of using a foreach variable, ```d import core.stdc.stdio : putc, stdout;

Re: How to properly use variadic templates (functions)?

2021-12-21 Thread Anonymouse via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 06:44:36 UTC, rempas wrote: This will not do for me because I want to do formatted output and I need the index. But thanks a lot for tying to help! I'm not certain I understand, but won't `foreach (i, a; args) { /* ... */ }` in his example do that? As in, if

Re: How to properly use variadic templates (functions)?

2021-12-20 Thread rempas via Digitalmars-d-learn
On Monday, 20 December 2021 at 22:02:02 UTC, russhy wrote: Here how i'd do, but i'm not sure how to keep track of the index of the arguments, i forgot.. ```D import core.stdc.stdio: putc, stdout; void print(T...)(string prompt, T args) { foreach (a; args) { alias A =

Re: How to properly use variadic templates (functions)?

2021-12-20 Thread rempas via Digitalmars-d-learn
On Monday, 20 December 2021 at 21:49:59 UTC, Adam D Ruppe wrote: still use foreach(arg; args) and skip that index variable. I know I can use foreach ("static foreach" more specifically) but I need to be able to get the index to choose a specific argument because I want to do formatting

Re: How to properly use variadic templates (functions)?

2021-12-20 Thread russhy via Digitalmars-d-learn
Here how i'd do, but i'm not sure how to keep track of the index of the arguments, i forgot.. ```D import core.stdc.stdio: putc, stdout; void print(T...)(string prompt, T args) { foreach (a; args) { alias A = typeof(a); static if (is(A : string)) {

Re: How to properly use variadic templates (functions)?

2021-12-20 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 20 December 2021 at 21:26:45 UTC, rempas wrote: // Suppose all 'args' are of type "string" for this example still use foreach(arg; args) and skip that index variable.

How to properly use variadic templates (functions)?

2021-12-20 Thread rempas via Digitalmars-d-learn
I'm trying to implement "printf" and I'm getting an error. The smallest possible code to demonstrate the error is: ``` import core.stdc.stdio; void print(T...)(string prompt, T args) { // Suppose all 'args' are of type "string" for this example ulong carg = 0; for (ulong i = 0; i <