Re: Call different member functions on object sequence with a generic handler function?

2018-07-01 Thread Timoses via Digitalmars-d-learn
On Sunday, 1 July 2018 at 06:55:35 UTC, Robert M. Münch wrote: The looping needs to be done in the handler because there are two loops running one after the other and the range to loop over is detected in the handler too. Otherwise a lot of code duplication would happen. Maybe an

0xC0000005: 0x0000000000000000 access violation...

2018-07-01 Thread Robert M. Münch via Digitalmars-d-learn
This one look nasty... I get an access violation crash after some time. The crash is reproducible in that it always happens after some time while executing the same code sequence (meaning the same function call chain). The debugger kicks in with a call stack, but it looks strange to me:

Function Template for Dynamic Parameter

2018-07-01 Thread vino.B via Digitalmars-d-learn
All, Request your help, the D document states that "Template functions are useful for avoiding code duplication - instead of writing several copies of a function, each with a different parameter type, a single function template can be sufficient" which mean we can passing any type of

Re: template alias that includes a parameter

2018-07-01 Thread Timoses via Digitalmars-d-learn
On Sunday, 1 July 2018 at 01:48:15 UTC, Simen Kjærås wrote: I'd send you straight to std.meta.ApplyLeft, but it seems to do the wrong thing here, in that it doesn't handle IFTI. This thing does: void fooImpl(int n, T)(const T line) { } unittest { alias fun = applyLeft!(fooImpl, 3);

Re: Function Template for Dynamic Parameter

2018-07-01 Thread Timoses via Digitalmars-d-learn
On Sunday, 1 July 2018 at 09:46:32 UTC, vino.B wrote: All, Request your help, the D document states that "Template functions are useful for avoiding code duplication - instead of writing several copies of a function, each with a different parameter type, a single function template can be

Re: Call different member functions on object sequence with a generic handler function?

2018-07-01 Thread Robert M. Münch via Digitalmars-d-learn
On 2018-06-30 22:53:47 +, Jerry said: Btw this is pretty much std.algorithm.each import std.algorithm; void main() { auto cs = [ new C(), new C() ]; cs.each!(o => o.A()); } https://dlang.org/phobos/std_algorithm_iteration.html#.each The looping needs to be done in the handler

Re: Call different member functions on object sequence with a generic handler function?

2018-07-01 Thread Basile B. via Digitalmars-d-learn
On Sunday, 1 July 2018 at 06:55:35 UTC, Robert M. Münch wrote: On 2018-06-30 22:53:47 +, Jerry said: Btw this is pretty much std.algorithm.each import std.algorithm; void main() { auto cs = [ new C(), new C() ]; cs.each!(o => o.A()); }

Re: Function Template for Dynamic Parameter

2018-07-01 Thread vino.B via Digitalmars-d-learn
On Sunday, 1 July 2018 at 09:55:34 UTC, Timoses wrote: On Sunday, 1 July 2018 at 09:46:32 UTC, vino.B wrote: All, Request your help, the D document states that "Template functions are useful for avoiding code duplication - instead of writing several copies of a function, each with a

Re: Function Template for Dynamic Parameter

2018-07-01 Thread Alex via Digitalmars-d-learn
On Sunday, 1 July 2018 at 11:19:50 UTC, vino.B wrote: Hi Timoses, Thank you very much, can you help me on how to rewrite the below using Variadic template Passing function as a parameter to another function: void ptFun(T)(T function(string, string, int) coRoutine, Array!string Dirlst, )

Re: Function Template for Dynamic Parameter

2018-07-01 Thread vino.B via Digitalmars-d-learn
On Sunday, 1 July 2018 at 11:52:19 UTC, Alex wrote: On Sunday, 1 July 2018 at 11:19:50 UTC, vino.B wrote: Hi Timoses, Thank you very much, can you help me on how to rewrite the below using Variadic template Passing function as a parameter to another function: void ptFun(T)(T

Re: template alias that includes a parameter

2018-07-01 Thread Simen Kjærås via Digitalmars-d-learn
On Sunday, 1 July 2018 at 09:46:55 UTC, Timoses wrote: Would be nice if std.meta.ApplyLeft did the job here.. Is there no way of achieving that? [snip] Would have to find a way to determine whether Template would resolve to a function or not. Can't find anything in Traits[1] or std.traits[2].

Re: Function Template for Dynamic Parameter

2018-07-01 Thread Timoses via Digitalmars-d-learn
On Sunday, 1 July 2018 at 11:19:50 UTC, vino.B wrote: On Sunday, 1 July 2018 at 09:55:34 UTC, Timoses wrote:> Hi Timoses, Thank you very much, can you help me on how to rewrite the below using Variadic template Passing function as a parameter to another function: void ptFun(T)(T

Re: Linker error for core.sys.windows.winuser imports when compiling as 64 bit.

2018-07-01 Thread Chris M. via Digitalmars-d-learn
On Sunday, 1 July 2018 at 01:16:59 UTC, Jonathan M Davis wrote: On Sunday, July 01, 2018 00:42:30 spikespaz via Digitalmars-d-learn wrote: Hey guys, I'm getting a linker error when compiling with DMD `-m63` that I don't get as 23 bit. I'm importing `ShowWindow` from

Re: High memory usage in vibe.d application

2018-07-01 Thread Jacob Shtokolov via Digitalmars-d-learn
On Sunday, 1 July 2018 at 05:20:17 UTC, Anton Fediushin wrote: Now I tried it and indeed, it's vibe.d's fault. I'm not quite sure what causes it and if this problem is known, I'll look into that later and open an issue if it doesn't exist already. Yes, please do this when you have time. That

Re: Function Template for Dynamic Parameter

2018-07-01 Thread Timoses via Digitalmars-d-learn
On Sunday, 1 July 2018 at 11:58:30 UTC, vino.B wrote: On Sunday, 1 July 2018 at 11:52:19 UTC, Alex wrote: NewType.d(19): Error: function declaration without return type. (Note that constructors are always named this) [...] auto coCleanFiles(T ...)(T args) { auto dFiles =

Re: template alias that includes a parameter

2018-07-01 Thread Timoses via Digitalmars-d-learn
On Sunday, 1 July 2018 at 11:55:15 UTC, Simen Kjærås wrote: On Sunday, 1 July 2018 at 09:46:55 UTC, Timoses wrote: Would be nice if std.meta.ApplyLeft did the job here.. Is there no way of achieving that? [snip] Would have to find a way to determine whether Template would resolve to a

Re: template alias that includes a parameter

2018-07-01 Thread Timoses via Digitalmars-d-learn
On Sunday, 1 July 2018 at 13:01:20 UTC, Timoses wrote: Aw, okay, then that won't work. Still, this looks like it should work: void foo(F, T)(T param) { writeln("Called with type: ", T.stringof); } alias tfoo = ApplyLeft!(foo, int); tfoo!string("hi"); // tfoo("hi"); // Error

Re: High memory usage in vibe.d application

2018-07-01 Thread Anton Fediushin via Digitalmars-d-learn
On Sunday, 1 July 2018 at 12:32:25 UTC, Jacob Shtokolov wrote: On Sunday, 1 July 2018 at 05:20:17 UTC, Anton Fediushin wrote: Now I tried it and indeed, it's vibe.d's fault. I'm not quite sure what causes it and if this problem is known, I'll look into that later and open an issue if it

Can I call GC.addRoot from constructor and trigger collection with destroy()?

2018-07-01 Thread Robert M. Münch via Digitalmars-d-learn
I'm creating a bunch of objects and need to use these object pointers with C code. Hence I need to protect them from being GC with GC.addRoot. Can this call be made out of a constructor? So that I can protect the objects as earyl as possible? Could I then unprotect the memory inside the

Re: 0xC0000005: 0x0000000000000000 access violation...

2018-07-01 Thread Robert M. Münch via Digitalmars-d-learn
On 2018-07-01 09:05:56 +, Robert M. Münch said: This one look nasty... And it was... the problem was, that I kept D allocated pointers in C code without informing the GC that the memory can't be collected nor moved. Bridging from D to C and back, is pretty tricky to not miss any

Re: High memory usage in vibe.d application

2018-07-01 Thread crimaniak via Digitalmars-d-learn
On Sunday, 1 July 2018 at 13:44:23 UTC, Anton Fediushin wrote: I reduced the test case to _one_ line: ``` 1.seconds.setTimer(() => "http://google.com".requestHTTP((scope req) {}, (scope res) {res.disconnect;}), true); ``` What happens is `res.disconnect` doesn't free all of the internal

Re: High memory usage in vibe.d application

2018-07-01 Thread Anton Fediushin via Digitalmars-d-learn
On Sunday, 1 July 2018 at 20:15:02 UTC, crimaniak wrote: On Sunday, 1 July 2018 at 13:44:23 UTC, Anton Fediushin wrote: I reduced the test case to _one_ line: ``` 1.seconds.setTimer(() => "http://google.com".requestHTTP((scope req) {}, (scope res) {res.disconnect;}), true); ``` What

Dynamic arrays / ~= giving an exception...

2018-07-01 Thread Robert M. Münch via Digitalmars-d-learn
I'm a bit puzzled because I think this is pretty straight forward but doesn't work... struct mystruct { myPtr* root; opApply(...){ myPtr*[] childs; childs ~= root; ... } } foreach(node; mystruct(myRoot)){

Re: Dynamic arrays / ~= giving an exception...

2018-07-01 Thread Robert M. Münch via Digitalmars-d-learn
On 2018-07-01 20:55:16 +, Robert M. Münch said: I'm a bit puzzled because I think this is pretty straight forward but doesn't work... struct mystruct { myPtr* root; opApply(...){ myPtr*[] childs; childs ~= root;

Re: Dynamic arrays / ~= giving an exception...

2018-07-01 Thread Cym13 via Digitalmars-d-learn
On Sunday, 1 July 2018 at 20:55:16 UTC, Robert M. Münch wrote: I'm a bit puzzled because I think this is pretty straight forward but doesn't work... struct mystruct { myPtr* root; opApply(...){ myPtr*[] childs; childs ~= root;

Re: Dynamic arrays / ~= giving an exception...

2018-07-01 Thread Robert M. Münch via Digitalmars-d-learn
On 2018-07-01 21:05:43 +, Cym13 said: On Sunday, 1 July 2018 at 20:55:16 UTC, Robert M. Münch wrote: I'm a bit puzzled because I think this is pretty straight forward but doesn't work... struct mystruct { myPtr* root; opApply(...){ myPtr*[] childs;