Using templates with interfaces

2017-06-25 Thread Andrew Chapman via Digitalmars-d-learn
Hi guys, I'm a little confused as to whether D supports interfaces with templates. I can compile OK, but linking reports an error like this: Error 42: Symbol Undefined _D12relationaldb10interfaces21RÇëÜDBIÇêÿ35__T7loadRowTS6prefix÷6P¶ZÇêáMFAyaAS3std7variant18Çâ└8VÇåìNVki20ZÇëÅZÇûð Essential

Accessing function frame from struct

2017-06-25 Thread Sebastien Alaiwan via Digitalmars-d-learn
Hi guys, here's my full code below. My problem is that last "auto Y = X" assignment, that the compiler won't accept: yo.globalFunction.DirectStruct.IndirectStruct.indirectMemberFunc cannot access frame of function yo.globalFunction I was expecting X to be accessible from here. Suprisingly, i

Re: Using templates with interfaces

2017-06-25 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 25 June 2017 at 11:39:27 UTC, Andrew Chapman wrote: Hi guys, I'm a little confused as to whether D supports interfaces with templates. I can compile OK, but linking reports an error like this: Error 42: Symbol Undefined _D12relationaldb10interfaces21RÇëÜDBIÇêÿ35__T7loadRowTS6prefi

Re: Using templates with interfaces

2017-06-25 Thread Andrew Chapman via Digitalmars-d-learn
On Sunday, 25 June 2017 at 13:04:32 UTC, Nicholas Wilson wrote: On Sunday, 25 June 2017 at 11:39:27 UTC, Andrew Chapman wrote: Hi guys, I'm a little confused as to whether D supports interfaces with templates. I can compile OK, but linking reports an error like this: Error 42: Symbol Undefin

Re: Using templates with interfaces

2017-06-25 Thread Andrew Chapman via Digitalmars-d-learn
I think you've answered the question with "You cannot have unimplemented templates in interfaces". Thanks for the answer. I'll rethink the way I'm doing this. Cheers.

Re: Interfacing with C - calling member function of D struct from C?

2017-06-25 Thread unleashy via Digitalmars-d-learn
On Sunday, 25 June 2017 at 02:09:53 UTC, Adam D. Ruppe wrote: On Sunday, 25 June 2017 at 02:05:35 UTC, unleashy wrote: How would I call `addToBar` from C code? You don't. Instead write it like: struct Foo { int bar; } extern(C) void addToBar(Foo* foo, int what) { foo.bar += what;

Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Johan Engelen via Digitalmars-d-learn
How would you solve this problem: do an optional function call depending on some version(X). If version(X) is not defined, there should be no call and no extra code at -O0. ``` { ... foo(); // either compiles to a function call, or to _nothing_. ... } ``` In C, you could do something like:

Re: Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Anonymouse via Digitalmars-d-learn
On Sunday, 25 June 2017 at 15:58:48 UTC, Johan Engelen wrote: How would you solve this problem: do an optional function call depending on some version(X). If version(X) is not defined, there should be no call and no extra code at -O0. ``` { ... foo(); // either compiles to a function call,

Re: Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 25 June 2017 at 15:58:48 UTC, Johan Engelen wrote: [...] If version(X) is not defined, there should be no call and no extra code at -O0. [...] In C, you could do something like: ``` #if X void foo() {..} #else #define foo() #endif ``` How would you do this in D? By requi

Re: Using templates with interfaces

2017-06-25 Thread via Digitalmars-d-learn
On Sunday, 25 June 2017 at 13:32:57 UTC, Andrew Chapman wrote: I think you've answered the question with "You cannot have unimplemented templates in interfaces". Thanks for the answer. I'll rethink the way I'm doing this. Cheers. Yes, function templates in classes or interfaces are implicit

Re: Using templates with interfaces

2017-06-25 Thread via Digitalmars-d-learn
On Sunday, 25 June 2017 at 13:32:57 UTC, Andrew Chapman wrote: I think you've answered the question with "You cannot have unimplemented templates in interfaces". Thanks for the answer. I'll rethink the way I'm doing this. Cheers. In your case you can probably use something along the lines o

Re: Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 25 June 2017 at 16:31:52 UTC, Moritz Maxeiner wrote: On Sunday, 25 June 2017 at 15:58:48 UTC, Johan Engelen wrote: [...] If version(X) is not defined, there should be no call and no extra code at -O0. [...] In C, you could do something like: ``` #if X void foo() {..} #else

Re: Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 25 June 2017 at 16:29:20 UTC, Anonymouse wrote: Am I missing something, or can't you just version both the function and the function ćall? version(X) void foo() { /* ... */ } void main() { version(X) { foo(); } } I am hoping for something where "foo()" would

Re: Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 25 June 2017 at 21:55:22 UTC, Johan Engelen wrote: On Sunday, 25 June 2017 at 16:31:52 UTC, Moritz Maxeiner wrote: By requiring the compiler to inline the empty foo: This won't work. Yes, it does; comment out the call to `foo` and notice no change in the assembly in my link.

Re: Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 25 June 2017 at 22:23:44 UTC, Moritz Maxeiner wrote: The solution obviously does *not* work if you change the premise of your question after the fact by artificially injecting instructions into all function bodies I meant semantically no call. I am asking for a little more imagin

Re: Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 25 June 2017 at 22:53:07 UTC, Johan Engelen wrote: I meant semantically no call. In the existing language, I think version (or static if) at the usage and definition points both is as good as you're going to get. unless you use a preprocessor lol But the good news about version

std.concurrency and sendWithDelay

2017-06-25 Thread Christian Köstlin via Digitalmars-d-learn
I really like the std.concurrency (https://dlang.org/phobos/std_concurrency.html) with spawn, send, receive ... Is there a builtin way to schedule core or an event after a delay (e.g. in android: https://developer.android.com/reference/android/os/Handler.html#postDelayed(java.lang.Runnable, long)

range of ranges into one range?

2017-06-25 Thread Jonathan Marler via Digitalmars-d-learn
I'm using the phobos "chain" function to iterate over a set of string arrays. However, one of the variables is actually an array of structs that each contain a string array. So I use "map" to get a range of string arrays, but "chain" expects each variable to be a string array, not a range of

Re: range of ranges into one range?

2017-06-25 Thread rikki cattermole via Digitalmars-d-learn
Perhaps? http://dlang.org/phobos/std_algorithm_iteration.html#.joiner

Re: Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Guillaume Piolat via Digitalmars-d-learn
On Sunday, 25 June 2017 at 15:58:48 UTC, Johan Engelen wrote: In C, you could do something like: ``` #if X void foo() {..} #else #define foo() #endif ``` Curious no one has mentionned it. Just use alias. version(X) alias myFunc = impl1; else alias myFunc = impl2; I do it a lo

Re: range of ranges into one range?

2017-06-25 Thread Russel Winder via Digitalmars-d-learn
On Mon, 2017-06-26 at 07:19 +0100, rikki cattermole via Digitalmars-d- learn wrote: > Perhaps? > http://dlang.org/phobos/std_algorithm_iteration.html#.joiner > I think this is yet another case where if Phobos had flatMap life would be a lot easier. -- Russel. ===