Re: Safe to remove AA elements while iterating over it via .byKeyValue?

2020-09-28 Thread Mike Parker via Digitalmars-d-learn
On Sunday, 27 September 2020 at 13:02:04 UTC, Per Nordlöw wrote: Is it safe to remove AA-elements from an `aa` I'm iterating over via aa.byKeyValue? I'm currently doing this: foreach (ref kv; aa.byKeyValue) { if (pred(kv.key)) aa.remove(kv.key); // ok? } if

How to work with and load/save sparse compressed matrices? (numir, mir.sparse)

2020-09-28 Thread Shaleen Chhabra via Digitalmars-d-learn
I wish to use load / save for sparse compressed matrices using mir. import mir.sparse; auto sp = sparse!double(5, 8); auto crs = sp.compress; How can I save/load sparse compressed arrays in `npz` format? (format: ``csc``, ``csr``, ``bsr``, ``dia`` or coo``) how can i again decompr

Re: I need "windowsx.d" Someone can send It to me?

2020-09-28 Thread Elronnd via Digitalmars-d-learn
On Sunday, 27 September 2020 at 18:30:10 UTC, Imperatorn wrote: I converting it using VisualD: https://pastebin.com/jzwKRnKZ Try it, maybe it works Somehow, I don't think this is going to fly: static if(__cplusplus) { extern (C) {/* Assume C declarations for C++ */ } /* __cplusplu

Re: How does alias exactly work

2020-09-28 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 29 September 2020 at 01:46:56 UTC, Ruby The Roobster wrote: I thought alias could work like this with classes: alias test = MyClass(3,"H",9.1); //Assume the constructor parameters for MyClass are (int,string,double). Can anybody fix this code? `alias` lets you create a new name

Re: How does alias exactly work

2020-09-28 Thread Ali Çehreli via Digitalmars-d-learn
On 9/28/20 6:46 PM, Ruby The Roobster wrote: I thought alias could work like this with classes: That would work with template parameters: alias A = Foo!(3, "hello"); alias test = MyClass(3,"H",9.1); //Assume the constructor parameters for MyClass are (int,string,double). Can anybody fix

How does alias exactly work

2020-09-28 Thread Ruby The Roobster via Digitalmars-d-learn
I thought alias could work like this with classes: alias test = MyClass(3,"H",9.1); //Assume the constructor parameters for MyClass are (int,string,double). Can anybody fix this code?

Re: How to write a counterpart to C++ std::invoke that works with both free functions and methods?

2020-09-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 27 September 2020 at 05:22:36 UTC, 60rntogo wrote: How would I check if it is actually a free function? but this doesn't even compile since I defined add inside my main function ah that's not a free function!! That's a nested function and thus actually has a hidden argument.

Re: App hangs, GC.collect() fixet it. Why?

2020-09-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/28/20 3:28 PM, Bastiaan Veelo wrote: I’m leaning towards ditching the memory mapped I/O on the D end, and replace it by regular serialisation/deserialisation. That will be a manual rewrite though, which is a bit of bummer as memory mapped files are widely used in our Pascal code. But this

Re: Safe to remove AA elements while iterating over it via .byKeyValue?

2020-09-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/28/20 1:18 PM, ikod wrote: On Monday, 28 September 2020 at 14:58:15 UTC, Steven Schveighoffer wrote: On 9/27/20 4:43 PM, Per Nordlöw wrote: On Sunday, 27 September 2020 at 14:23:11 UTC, H. S. Teoh wrote: No.  Modifying a container while iterating over it is, in general, a bad idea (unless

Re: Safe to remove AA elements while iterating over it via .byKeyValue?

2020-09-28 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 28, 2020 at 08:04:49PM +, ikod via Digitalmars-d-learn wrote: > On Monday, 28 September 2020 at 19:18:20 UTC, H. S. Teoh wrote: [...] > > The problem with arbitrary, unrestricted modification of a container > > while iterating over it, is that it inevitably leads to > > counterintui

Re: Safe to remove AA elements while iterating over it via .byKeyValue?

2020-09-28 Thread ikod via Digitalmars-d-learn
On Monday, 28 September 2020 at 19:18:20 UTC, H. S. Teoh wrote: On Mon, Sep 28, 2020 at 05:18:41PM +, ikod via Digitalmars-d-learn wrote: On Monday, 28 September 2020 at 14:58:15 UTC, Steven Schveighoffer wrote: [...] > One could write a specific function to iterate and remove. I This loo

Re: App hangs, GC.collect() fixet it. Why?

2020-09-28 Thread Bastiaan Veelo via Digitalmars-d-learn
On Monday, 28 September 2020 at 15:44:44 UTC, Steven Schveighoffer wrote: On 9/28/20 8:57 AM, Bastiaan Veelo wrote: I am glad to have found the cause of the breakage finally, but it won't be easy to find a generic solution... Obviously, this isn't a real piece of code, but there is no way ar

Re: Safe to remove AA elements while iterating over it via .byKeyValue?

2020-09-28 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 28, 2020 at 05:18:41PM +, ikod via Digitalmars-d-learn wrote: > On Monday, 28 September 2020 at 14:58:15 UTC, Steven Schveighoffer wrote: [...] > > One could write a specific function to iterate and remove. I > > This looks like dead end to me, as you may not only remove items from

Accessing non-binary Unicode properties with std.uni

2020-09-28 Thread Chloé Kekoa via Digitalmars-d-learn
The documentation of std.uni [1] says that the unicode struct provides sets for several binary properties. I am looking for a way to query non-binary properties of a character. Is that possible with std.uni or do I need to use a third-party library? I am specifically interested in the East_Asi

Re: Safe to remove AA elements while iterating over it via .byKeyValue?

2020-09-28 Thread ikod via Digitalmars-d-learn
On Monday, 28 September 2020 at 14:58:15 UTC, Steven Schveighoffer wrote: On 9/27/20 4:43 PM, Per Nordlöw wrote: On Sunday, 27 September 2020 at 14:23:11 UTC, H. S. Teoh wrote: No.  Modifying a container while iterating over it is, in general, a bad idea (unless the container is designed to be

Re: Any way to tell if an object is inside another class?

2020-09-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/28/20 7:11 AM, Ruby The Roobster wrote: For example: class test {} class T { auto c = new test(); } Any way to tell if an object of type test is a member of object T? I don't want to use the name of the member variable. I just want to know if this works in general. Why am I asking this?

Re: App hangs, GC.collect() fixet it. Why?

2020-09-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/28/20 8:57 AM, Bastiaan Veelo wrote: I am glad to have found the cause of the breakage finally, but it won't be easy to find a generic solution... Obviously, this isn't a real piece of code, but there is no way around this. You have to align your pointers. The other option is to not use

Re: Any way to tell if an object is inside another class?

2020-09-28 Thread Ruby The Roobster via Digitalmars-d-learn
On Monday, 28 September 2020 at 14:36:01 UTC, Mike Parker wrote: There's the `parent` trait. You can wrap it like this: `` then is (hasParent!f) legal code?

Re: Safe to remove AA elements while iterating over it via .byKeyValue?

2020-09-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/27/20 4:43 PM, Per Nordlöw wrote: On Sunday, 27 September 2020 at 14:23:11 UTC, H. S. Teoh wrote: No.  Modifying a container while iterating over it is, in general, a bad idea (unless the container is designed to be used that way, but even then, such removal is generally restricted), becau

Re: Any way to tell if an object is inside another class?

2020-09-28 Thread Mike Parker via Digitalmars-d-learn
On Monday, 28 September 2020 at 14:23:12 UTC, Ruby The Roobster wrote: On Monday, 28 September 2020 at 14:22:34 UTC, Ruby The Roobster wrote: I meant User Defined types. not UDAs. Anyways, the whole thing is me trying to find a hacky workaround that allows something similar to multiple alias th

Re: Any way to tell if an object is inside another class?

2020-09-28 Thread Ruby The Roobster via Digitalmars-d-learn
On Monday, 28 September 2020 at 14:09:07 UTC, Paul Backus wrote: Can you re-write this as actual valid D code, but with the implementation of the function stubbed out? I still don't understand what your function is supposed to take as its input(s), or what "parent object is a member variable of

Re: Any way to tell if an object is inside another class?

2020-09-28 Thread Ruby The Roobster via Digitalmars-d-learn
On Monday, 28 September 2020 at 14:22:34 UTC, Ruby The Roobster wrote: I meant User Defined types. not UDAs. Anyways, the whole thing is me trying to find a hacky workaround that allows something similar to multiple alias this declarations(because multiple of these are not possible). And for th

Re: Any way to tell if an object is inside another class?

2020-09-28 Thread Paul Backus via Digitalmars-d-learn
On Monday, 28 September 2020 at 13:45:30 UTC, Ruby The Roobster wrote: On Monday, 28 September 2020 at 13:00:43 UTC, Paul Backus wrote: Can you give some examples of inputs and corresponding outputs for this, like you would for a unit test? I don't understand exactly what you're asking, and it

Re: Any way to tell if an object is inside another class?

2020-09-28 Thread Ruby The Roobster via Digitalmars-d-learn
On Monday, 28 September 2020 at 13:00:43 UTC, Paul Backus wrote: Can you give some examples of inputs and corresponding outputs for this, like you would for a unit test? I don't understand exactly what you're asking, and it would help clarify. Okay. Here is an example. class Test { this.is_in

Re: Any way to tell if an object is inside another class?

2020-09-28 Thread Paul Backus via Digitalmars-d-learn
On Monday, 28 September 2020 at 11:11:13 UTC, Ruby The Roobster wrote: For example: class test {} class T { auto c = new test(); } Any way to tell if an object of type test is a member of object T? I don't want to use the name of the member variable. I just want to know if this works in gener

Re: App hangs, GC.collect() fixet it. Why?

2020-09-28 Thread Bastiaan Veelo via Digitalmars-d-learn
On Friday, 5 June 2020 at 21:20:09 UTC, Steven Schveighoffer wrote: This kind of sounds like a codegen bug, a race condition, or (worst case) memory corruption. I think it must have been memory corruption: I had not realized that our old Pascal compiler aligns struct members on one byte bound

Re: Any way to tell if an object is inside another class?

2020-09-28 Thread Ruby The Roobster via Digitalmars-d-learn
On Monday, 28 September 2020 at 11:40:40 UTC, k2aj wrote: pragma(msg, hasFieldOfType!(T, int)); //false pragma(msg, hasFieldOfType!(T, test)); //true Not exactly what I meant. I more of meant is there a way to check if a test object is a member variable, not if it is in a particular class.

Re: Any way to tell if an object is inside another class?

2020-09-28 Thread k2aj via Digitalmars-d-learn
On Monday, 28 September 2020 at 11:11:13 UTC, Ruby The Roobster wrote: For example: class test {} class T { auto c = new test(); } Any way to tell if an object of type test is a member of object T? I don't want to use the name of the member variable. I just want to know if this works in gener

Any way to tell if an object is inside another class?

2020-09-28 Thread Ruby The Roobster via Digitalmars-d-learn
For example: class test {} class T { auto c = new test(); } Any way to tell if an object of type test is a member of object T? I don't want to use the name of the member variable. I just want to know if this works in general. Why am I asking this? Because I need it to develop this Multiple Al

Re: Safe to remove AA elements while iterating over it via .byKeyValue?

2020-09-28 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 28 September 2020 at 10:01:23 UTC, ikod wrote: Is it specific to some types? What if collection supports stable "foreach"? Yes it depends on how collection members (such as insert, find, replace, erase, etc) are implemented. I presume we need attributes on mutating collection memb

Re: Safe to remove AA elements while iterating over it via .byKeyValue?

2020-09-28 Thread ikod via Digitalmars-d-learn
On Monday, 28 September 2020 at 10:10:10 UTC, Per Nordlöw wrote: On Monday, 28 September 2020 at 10:01:23 UTC, ikod wrote: Is it specific to some types? What if collection supports stable "foreach"? Yes it depends on how collection members (such as insert, find, replace, erase, etc) are imple

Re: Safe to remove AA elements while iterating over it via .byKeyValue?

2020-09-28 Thread ikod via Digitalmars-d-learn
On Monday, 28 September 2020 at 09:41:02 UTC, Per Nordlöw wrote: On Monday, 28 September 2020 at 07:15:27 UTC, Imperatorn wrote: Yes, this should be a compile-time error Spec here: https://dlang.org/spec/statement.html#foreach_restrictions Is it specific to some types? What if collection su

Re: Safe to remove AA elements while iterating over it via .byKeyValue?

2020-09-28 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 28 September 2020 at 07:15:27 UTC, Imperatorn wrote: Yes, this should be a compile-time error Spec here: https://dlang.org/spec/statement.html#foreach_restrictions

Re: AA with class keys compared with identity instead of opEquals

2020-09-28 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 28 September 2020 at 08:26:15 UTC, Per Nordlöw wrote: In the case where the AA-KeyType is a class (which is represented as a pointer in D) I want the equality (opEquals) and the hashing (toHash) of the AA to compare and hash the pointers themselves, not the fields the classes points

Re: AA with class keys compared with identity instead of opEquals

2020-09-28 Thread Per Nordlöw via Digitalmars-d-learn
On Sunday, 27 September 2020 at 19:45:07 UTC, Ferhat Kurtulmuş wrote: Sorry I did not understand what you meant. It would be better if you share the answer here. I found this also https://dlang.org/library/std/traits/key_type.html, but I dont know if it is related. In the case where the AA-Ke

Re: Safe to remove AA elements while iterating over it via .byKeyValue?

2020-09-28 Thread Imperatorn via Digitalmars-d-learn
On Sunday, 27 September 2020 at 20:43:19 UTC, Per Nordlöw wrote: On Sunday, 27 September 2020 at 14:23:11 UTC, H. S. Teoh wrote: [...] I believe it's high time we start thinking about detecting these violations at compile-time. I recall it's in the spec somewhere so we should start a depreca