Re: Elegant way to test if members of array A are present in array B?

2019-06-12 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-06-11 17:34:00 +, Paul Backus said: It's a space/time tradeoff. foreach with canFind is O(n^2) time and O(1) space. Yes, that's why I asekd. They haystack is most likely >10 times larger than the needles. Speed has priority. If you use an associative array or a set, it's O(n)

arsd dom

2019-06-12 Thread Amex via Digitalmars-d-learn
When parsing an xml file I get #text for tagName on basically every other element. I'm trying to recurse through all the elements using void recurse(T)(T parent, int depth = 0) { foreach(c; parent.children) { recurse(c,

Re: I want an exception message but my threaded callback just dies or crashes

2019-06-12 Thread Markus via Digitalmars-d-learn
On Tuesday, 11 June 2019 at 05:15:17 UTC, Markus wrote: I have cleaned it up, kind of. Just in case you want to compile it. The Zip contains some DLL from https://github.com/spatialaudio/portaudio-binaries where you can find the original if you want. https://gofile.io/?c=NpUxrJ I'm in

static variable A cannot be read at compile time

2019-06-12 Thread Newbie2019 via Digitalmars-d-learn
https://run.dlang.io/is/s4cfiv onlineapp.d(23): Error: static variable A cannot be read at compile time onlineapp.d(23): Error: cannot implicitly convert expression 1 of type int to int* I see no reason the code should not work, and the second error message make no sense. please

Re: Elegant way to test if members of array A are present in array B?

2019-06-12 Thread Meta via Digitalmars-d-learn
On Tuesday, 11 June 2019 at 17:12:17 UTC, Robert M. Münch wrote: Is there a simple and elegant way to do this? Or is just using a foreach(...) with canFind() the best way? There are two versions of find that can find a range within another:

Re: static variable A cannot be read at compile time

2019-06-12 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 12, 2019 at 01:12:58PM +, Newbie2019 via Digitalmars-d-learn wrote: > https://run.dlang.io/is/s4cfiv > > onlineapp.d(23): Error: static variable A cannot be read at compile time > onlineapp.d(23): Error: cannot implicitly convert expression 1 of type int > to int* > > I see no

Re: static variable A cannot be read at compile time

2019-06-12 Thread Newbie2019 via Digitalmars-d-learn
On Wednesday, 12 June 2019 at 13:53:09 UTC, H. S. Teoh wrote: On Wed, Jun 12, 2019 at 01:12:58PM +, Newbie2019 via Digitalmars-d-learn wrote: Read: https://wiki.dlang.org/User:Quickfur/Compile-time_vs._compile-time T Thanks for the tips. I move the static array into local var then it

Re: arsd dom

2019-06-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 12 June 2019 at 10:06:39 UTC, Amex wrote: When parsing an xml file I get #text for tagName on basically every other element. Those are the text nodes representing the whitespace between elements. `bar ` has: element Foo, text " ", element text.

Re: How to "Inherit" the attributes from a given callable argument?

2019-06-12 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 12, 2019 at 07:46:12PM +, Mek101 via Digitalmars-d-learn wrote: [...] > > public size_t indexOf(alias pred = "a == b", Range)(Range array) > > { > > alias predicate = unaryFun!pred; > > for(size_t i = 0; i < array.length; i++) > > if(predicate(array[i])) > >

Re: How to "Inherit" the attributes from a given callable argument?

2019-06-12 Thread Mek101 via Digitalmars-d-learn
I didn't know it applied to templates other than lambdas. Thank you for your explanation.

Re: static variable A cannot be read at compile time

2019-06-12 Thread Machine Code via Digitalmars-d-learn
On Wednesday, 12 June 2019 at 14:09:08 UTC, Newbie2019 wrote: On Wednesday, 12 June 2019 at 13:53:09 UTC, H. S. Teoh wrote: On Wed, Jun 12, 2019 at 01:12:58PM +, Newbie2019 via Digitalmars-d-learn wrote: Read: https://wiki.dlang.org/User:Quickfur/Compile-time_vs._compile-time T

How to "Inherit" the attributes from a given callable argument?

2019-06-12 Thread Mek101 via Digitalmars-d-learn
I'll try to be straight. I have the following function: public size_t indexOf(alias pred = "a == b", Range)(Range array) { alias predicate = unaryFun!pred; for(size_t i = 0; i < array.length; i++) if(predicate(array[i])) return i;

Re: Elegant way to test if members of array A are present in array B?

2019-06-12 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 12 June 2019 at 06:57:55 UTC, Robert M. Münch wrote: If you use an associative array or a set, it's O(n) time and O(n) space. I don't see how this is the case. The AA itself has some overhead too. So, the checking loop is O(n) but the AA lookups not. Hash table insertion and