Re: Is it possible to store different subclasses in one array?

2020-04-12 Thread evilrat via Digitalmars-d-learn
On Monday, 13 April 2020 at 04:21:48 UTC, Leonardo wrote: foreach (ref gi; GameItems) { if (gi == Weapon) gi.Attack() } How would it be? Replying myself... weapon = cast(Weapon) gi; if (weapon !is null) weapon.Attack() can be simplified as: if (auto weapon =

Re: Is it possible to store different subclasses in one array?

2020-04-12 Thread Leonardo via Digitalmars-d-learn
On Monday, 13 April 2020 at 04:15:04 UTC, Leonardo wrote: On Monday, 13 April 2020 at 01:47:11 UTC, Adam D. Ruppe wrote: On Monday, 13 April 2020 at 01:42:51 UTC, Leonardo wrote: Is it possible to store different subclasses in one array? In C#, we have this example, but how I do that in D?

Re: Is it possible to store different subclasses in one array?

2020-04-12 Thread Leonardo via Digitalmars-d-learn
On Monday, 13 April 2020 at 01:47:11 UTC, Adam D. Ruppe wrote: On Monday, 13 April 2020 at 01:42:51 UTC, Leonardo wrote: Is it possible to store different subclasses in one array? In C#, we have this example, but how I do that in D? Did you try BaseItem[] GameItems; GameItems ~= new

Re: How to detect whethere if a JSON node exists

2020-04-12 Thread Adnan via Digitalmars-d-learn
On Monday, 13 April 2020 at 02:22:33 UTC, Adam D. Ruppe wrote: On Monday, 13 April 2020 at 02:20:39 UTC, Adnan wrote: Now in the above inner loop getStr(node["com"].str()) crashes in runtime if an array does not contain "com" node. I want to avoid that. How should I proceed? Try: if("com"

How to detect whethere if a JSON node exists

2020-04-12 Thread Adnan via Digitalmars-d-learn
In the following code, I want to process an json array (returned by the value of "posts") that might or might not have "com" key. If a "com" key does not exist, I want to ignore that item in the json array. uint[string] wordTable; const auto j = parseJSON(get(link));

Re: How to detect whethere if a JSON node exists

2020-04-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 13 April 2020 at 02:20:39 UTC, Adnan wrote: Now in the above inner loop getStr(node["com"].str()) crashes in runtime if an array does not contain "com" node. I want to avoid that. How should I proceed? Try: if("com" in node) { }

Re: Is it possible to store different subclasses in one array?

2020-04-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 13 April 2020 at 01:42:51 UTC, Leonardo wrote: Is it possible to store different subclasses in one array? In C#, we have this example, but how I do that in D? Did you try BaseItem[] GameItems; GameItems ~= new Weapon(); yet?

Is it possible to store different subclasses in one array?

2020-04-12 Thread Leonardo via Digitalmars-d-learn
Is it possible to store different subclasses in one array? In C#, we have this example, but how I do that in D? public class BaseItem{ public string name = ""; } public class Weapon : BaseItem{ public int damage = 10; } public class Potion : BaseItem{ public int

Re: linker aliases to carry dlang attributes for externs

2020-04-12 Thread Bruce Carneal via Digitalmars-d-learn
On Sunday, 12 April 2020 at 23:14:42 UTC, Bruce Carneal wrote: Could dlang compilers emit aliases for extern(C) and extern(C++) routines that would carry dlang specific information? (@safe, @nogc, nothrow, ...) I'm thinking two symbols. The first as per normal C/C++, and the second as per

linker aliases to carry dlang attributes for externs

2020-04-12 Thread Bruce Carneal via Digitalmars-d-learn
Could dlang compilers emit aliases for extern(C) and extern(C++) routines that would carry dlang specific information? (@safe, @nogc, nothrow, ...) I'm thinking two symbols. The first as per normal C/C++, and the second as per normal dlang with a "use API {C, C++, ...}" suffix.

Re: odd atomicOp errors from vibe-core

2020-04-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/12/20 6:30 AM, Iain Buclaw wrote: This is a regression caused by https://github.com/dlang/dmd/pull/10711 Thanks for finding that! I wasn't sure where the culprit was. -Steve

Re: Using the functions "map" and "any" on tuples in compile time.

2020-04-12 Thread realhet via Digitalmars-d-learn
On Sunday, 12 April 2020 at 12:42:40 UTC, Harry Gillanders wrote: On Sunday, 12 April 2020 at 11:17:39 UTC, realhet wrote: I only remembered the __traits(identifier...), but completely forgot about the getMember. And I never heard of anySatisfy. My JSON serializer is beautiful now. Thank

Re: How user dub packages in dmd without dub.exe ?

2020-04-12 Thread Marcone via Digitalmars-d-learn
On Sunday, 5 April 2020 at 14:19:40 UTC, WebFreak001 wrote: On Sunday, 5 April 2020 at 14:02:19 UTC, Baby Beaker wrote: On Saturday, 4 April 2020 at 21:54:34 UTC, Andre Pany wrote: On Saturday, 4 April 2020 at 20:21:03 UTC, Marcone wrote: [...] [...] If you can copy the D packages from the

Re: Using the functions "map" and "any" on tuples in compile time.

2020-04-12 Thread Harry Gillanders via Digitalmars-d-learn
On Sunday, 12 April 2020 at 11:17:39 UTC, realhet wrote: Hello, anyone can help me make this better? The functionality I want to achieve is: While serializing the fields of a struct, I want it to check the @STORED UDA on every field. If there is no fields are marked with @STORED, that means

Using the functions "map" and "any" on tuples in compile time.

2020-04-12 Thread realhet via Digitalmars-d-learn
Hello, anyone can help me make this better? The functionality I want to achieve is: While serializing the fields of a struct, I want it to check the @STORED UDA on every field. If there is no fields are marked with @STORED, that means every field must be serialized. Otherwise only the marked

Re: odd atomicOp errors from vibe-core

2020-04-12 Thread Iain Buclaw via Digitalmars-d-learn
On Friday, 10 April 2020 at 01:54:14 UTC, Steven Schveighoffer wrote: I'm building a library that uses vibe-core as an indirect dependency. Specifically, I'm testing the library with dub test. A very odd thing happens as I'm picking off compiler errors one at a time. After all the errors that