Re: Input/Output multiple values from function

2019-08-29 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 28 August 2019 at 13:11:46 UTC, Jabari Zakiya wrote: When I do this: uint a; uint b; uint[] c; uint[] d; AliasSeq!(a, b, c, d) = genPGparameters(pg); modpg= a; res_0= b; restwins = c; resinvrs = d; the compiler (ldc2 1.17) says: D Projects ~/D/bin/ldc2

Is removing elements of AA in foreach loop safe?

2019-08-29 Thread berni via Digitalmars-d-learn
Iterating of some structure and removing elements thereby is always errorprone and should be avoided. But: In case of AA, I've got the feeling, that it might be safe: foreach (k,v;ways) if (v.empty) ways.remove(k); Do you agree? Or is there a better way to achieve this?

Re: Input/Output multiple values from function

2019-08-29 Thread Jabari Zakiya via Digitalmars-d-learn
On Thursday, 29 August 2019 at 09:04:17 UTC, Simen Kjærås wrote: On Wednesday, 28 August 2019 at 13:11:46 UTC, Jabari Zakiya wrote: [...] Reduced example: unittest { int[] a; // cannot implicitly convert expression a of type int[] to shared(int[]) shared int[] b = a; } This is

Re: Test the return type of 'unaryFun' and 'binaryFun'.

2019-08-29 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 29 August 2019 at 08:58:18 UTC, Mek101 wrote: As the title says, is there a way to test the return type of the 'unaryFun' and 'binaryFun' templates from 'std.functional'? I have the following code, and I want to to be sure that 'predicate' returns a boolean, but neither

Re: Input/Output multiple values from function

2019-08-29 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 29 August 2019 at 10:39:44 UTC, Jabari Zakiya wrote: The values modpg, res_0, restwins, and resinvrs are constant (immutable) values that are generated at run time. They are global/shared and used inside threads. So this process is initializing them at the start of the program,

Re: Is removing elements of AA in foreach loop safe?

2019-08-29 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, August 29, 2019 4:11:58 AM MDT berni via Digitalmars-d-learn wrote: > Iterating of some structure and removing elements thereby is > always errorprone and should be avoided. But: In case of AA, I've > > got the feeling, that it might be safe: > > foreach (k,v;ways) > > > > if

Re: Question about generation of template functions

2019-08-29 Thread Jesse Phillips via Digitalmars-d-learn
On Wednesday, 28 August 2019 at 20:56:25 UTC, Machine Code wrote: I was writing a recursive function that uses template, I thought it would generate the proper template function on the fly to match the type in the parameter but it seems to not so so and try to use the called function,

Static initialization of rectangular arrays

2019-08-29 Thread rombankzero via Digitalmars-d-learn
Hey, everybody! I'm having Array Problems™. The documentation on arrays says that you can initialize all elements of a rectangular array with the following syntax: double[6][3] matrix = 0; // Sets all elements to 0. However this doesn't appear to work for static initialization: static

Re: Question about generation of template functions

2019-08-29 Thread Machine Code via Digitalmars-d-learn
That's right, thank you all guys. Found my mistake; should be: serialize!(typeof(field))(__traits(getMember, output, fieldName));

Test the return type of 'unaryFun' and 'binaryFun'.

2019-08-29 Thread Mek101 via Digitalmars-d-learn
As the title says, is there a way to test the return type of the 'unaryFun' and 'binaryFun' templates from 'std.functional'? I have the following code, and I want to to be sure that 'predicate' returns a boolean, but neither 'is(typeof(predicate) == bool)' or 'is(ReturnType!predicate ==

Re: Static initialization of rectangular arrays

2019-08-29 Thread rombankzero via Digitalmars-d-learn
On Thursday, 29 August 2019 at 19:06:04 UTC, kinke wrote: Sorry, that was wrt. the linked bugzilla and not this example here. - What does work is `static double[6][3] matrix = [0, 0, 0]`, i.e., initializing each nested 1D array with a scalar 0. I guess I'll use this workaround, though

Re: Static initialization of rectangular arrays

2019-08-29 Thread Les De Ridder via Digitalmars-d-learn
On Thursday, 29 August 2019 at 15:10:26 UTC, rombankzero wrote: [...] Is this a bug, or am I missing something? It would be really convenient to be able to statically initialize rectangular arrays in this way. Example: I have a struct that has a member that's a rectangular float array, but I

Re: Test the return type of 'unaryFun' and 'binaryFun'.

2019-08-29 Thread Mek101 via Digitalmars-d-learn
I made the following enumerations to test the predicates. private enum bool isUnaryPredicate(alias pred, Range) = is(typeof(unaryFun!(pred)((ElementType!Range).init)) == bool); private enum bool isBinaryPredicate(alias pred, Range, V) = is(typeof(binaryFun!(pred)((ElementType!Range).init,

Re: Static initialization of rectangular arrays

2019-08-29 Thread kinke via Digitalmars-d-learn
On Thursday, 29 August 2019 at 18:11:50 UTC, Les De Ridder wrote: It's a known bug[1]. As a workaround you could use a `static this()`: Or LDC, and GDC probably too.

Re: Static initialization of rectangular arrays

2019-08-29 Thread kinke via Digitalmars-d-learn
On Thursday, 29 August 2019 at 18:59:22 UTC, kinke wrote: On Thursday, 29 August 2019 at 18:11:50 UTC, Les De Ridder wrote: It's a known bug[1]. As a workaround you could use a `static this()`: Or LDC, and GDC probably too. Sorry, that was wrt. the linked bugzilla and not this example