Re: Picking function templates with __traits(getOverloads, ..., true)

2020-07-29 Thread Jean-Louis Leroy via Digitalmars-d-learn

On Thursday, 30 July 2020 at 00:27:49 UTC, user1234 wrote:
On Wednesday, 29 July 2020 at 23:57:21 UTC, Jean-Louis Leroy 
wrote:

This works:

[...]
I may be missing the obvious...or it's a compiler bug???


Yes and it's just been fixed, see 
https://github.com/dlang/dmd/pull/11431.

So uncommenting the second times works on ~master.


Ah thanks! In the meantime I realized that picking the 
overload at index 1 works. That's the difference between 'foo' 
and 'times'. Then I was 80% sure it was a bug.


Re: Picking function templates with __traits(getOverloads, ..., true)

2020-07-29 Thread user1234 via Digitalmars-d-learn
On Wednesday, 29 July 2020 at 23:57:21 UTC, Jean-Louis Leroy 
wrote:

This works:

[...]
I may be missing the obvious...or it's a compiler bug???


Yes and it's just been fixed, see 
https://github.com/dlang/dmd/pull/11431.

So uncommenting the second times works on ~master.




Picking function templates with __traits(getOverloads, ..., true)

2020-07-29 Thread Jean-Louis Leroy via Digitalmars-d-learn

This works:

module test;

void foo(T)(T a, T b) {}
void foo(T)(char a, T b) {}

template InstantiateTemplateAt(alias Module, string name, int 
index, T...) {
alias Template = __traits(getOverloads, test, name, 
true)[index];

alias InstantiateTemplateAt = Template!(T);
}

pragma(msg, typeof(InstantiateTemplateAt!(test, "foo", 1, int)));
// pure nothrow @nogc @safe void(char a, int b)

class Matrix(T) {}

Matrix!T times(T)(Matrix!T a, T b);
// Matrix!T times(T)(T a, Matrix!T b); // <-- second 'times' 
overload


pragma(msg, typeof(InstantiateTemplateAt!(test, "times", 0, 
int)));

// Matrix!int(Matrix!int a, int b)

But if I uncomment the second 'times' function template, I get an 
error:


templateoverloads.d(8): Error: template `test.times` matches more 
than one template declaration:

templateoverloads.d(16): `times(T)(Matrix!T a, T b)`
and
templateoverloads.d(17): `times(T)(T a, Matrix!T b)`
templateoverloads.d(19): Error: template instance 
`test.InstantiateTemplateAt!(test, "times", 0, int)` error 
instantiating

_error_

I may be missing the obvious...or it's a compiler bug???
(not sure if this belongs to the Learn section either)




Re: is using predSwitch the only way to create to create recursive functions in D ?

2020-07-29 Thread Ali Çehreli via Digitalmars-d-learn

On 7/29/20 3:13 PM, Andy Balba wrote:

,,


Not at all. The wording in the documentation is misleading.

Recursive functions are as trivial as they are:

int foo(uint i) {
  if (i == 0) {
return 42;
  }

  return foo(i - 1);
}

void main() {
  assert(foo(7) == 42);
}

Ali


is using predSwitch the only way to create to create recursive functions in D ?

2020-07-29 Thread Andy Balba via Digitalmars-d-learn

,,


Re: dub build to generate different kinds of libs

2020-07-29 Thread Andre Pany via Digitalmars-d-learn

On Wednesday, 29 July 2020 at 17:42:20 UTC, jeff thompson wrote:

On Wednesday, 29 July 2020 at 13:26:45 UTC, Andre Pany wrote:

On Tuesday, 28 July 2020 at 22:10:58 UTC, jeff thompson wrote:
On Tuesday, 28 July 2020 at 22:08:14 UTC, Steven 
Schveighoffer wrote:

[...]


Thanks Steve!, ya i know i can call build twice but i was 
wondering if there was any config magic for dub to make it 
output multiple library types in one call to build


As far as I remember if you set the targetType of the main 
package to none it build all the sub packages in one call. 
Therefore you have 2 sub packages instead of 2 configurations.


But I have to say I have never done it myself, but just saw 
the pr which should implement this behavior.


Kind regards
Andre


Awesome, cant wait to get that ability, as far as my issue i 
was being a D newb and was setting everything up incorrectly. 
Im all good now. Thanks


-J


Here the example from the dub repository
https://github.com/dlang/dub/tree/814b06edb304701a41b97f98973bdae7870d4d8b/test/issue97-targettype-none

Kind regards
Andre


Re: dub build to generate different kinds of libs

2020-07-29 Thread jeff thompson via Digitalmars-d-learn

On Wednesday, 29 July 2020 at 13:26:45 UTC, Andre Pany wrote:

On Tuesday, 28 July 2020 at 22:10:58 UTC, jeff thompson wrote:
On Tuesday, 28 July 2020 at 22:08:14 UTC, Steven Schveighoffer 
wrote:

[...]


Thanks Steve!, ya i know i can call build twice but i was 
wondering if there was any config magic for dub to make it 
output multiple library types in one call to build


As far as I remember if you set the targetType of the main 
package to none it build all the sub packages in one call. 
Therefore you have 2 sub packages instead of 2 configurations.


But I have to say I have never done it myself, but just saw the 
pr which should implement this behavior.


Kind regards
Andre


Awesome, cant wait to get that ability, as far as my issue i was 
being a D newb and was setting everything up incorrectly. Im all 
good now. Thanks


-J


Re: dub build to generate different kinds of libs

2020-07-29 Thread Andre Pany via Digitalmars-d-learn

On Tuesday, 28 July 2020 at 22:10:58 UTC, jeff thompson wrote:
On Tuesday, 28 July 2020 at 22:08:14 UTC, Steven Schveighoffer 
wrote:

On 7/28/20 5:50 PM, jeff thompson wrote:

Hello

Im brand new to D (loving it btw!) and have decided to build 
a largish windows project in the language. First question, is 
there a dub.json setup to have a dub build to generate 
multiple binaries in one call? Like a dll and a static lib. 
Seems like it would be easy maybe im missing something 
obvious? Like a configuration with multiple targetTypes.


Yes, just do that (make multiple configurations)

You just have to build them separately:

dub build --config=library
dub build --config=application

-Steve


Thanks Steve!, ya i know i can call build twice but i was 
wondering if there was any config magic for dub to make it 
output multiple library types in one call to build


As far as I remember if you set the targetType of the main 
package to none it build all the sub packages in one call. 
Therefore you have 2 sub packages instead of 2 configurations.


But I have to say I have never done it myself, but just saw the 
pr which should implement this behavior.


Kind regards
Andre