Strange behaviour of __traits(allMembers)

2023-06-18 Thread IchorDev via Digitalmars-d-learn
`source/mod/submod.d:` ```d module mod.submod; enum T1{ x } ``` `source/mod/package.d`: ```d module mod; import mod.submod; enum T2{ y } enum T3{ z } static foreach(member; __traits(allMembers, mod)){ pragma(msg, member); } /**Prints: object T1 **/ ``` I get the members of `mod.submod` instea

Re: Strange behaviour of __traits(allMembers)

2023-06-18 Thread FeepingCreature via Digitalmars-d-learn
On Sunday, 18 June 2023 at 09:48:40 UTC, IchorDev wrote: Does anyone understand why this happens? Is there any way to subvert this behaviour, or is it actually a bug? Yes, see also my bug report, https://issues.dlang.org/show_bug.cgi?id=20008 "__traits(allMembers) of packages is complete non

Re: Strange behaviour of __traits(allMembers)

2023-06-18 Thread IchorDev via Digitalmars-d-learn
On Sunday, 18 June 2023 at 10:04:14 UTC, FeepingCreature wrote: On Sunday, 18 June 2023 at 09:48:40 UTC, IchorDev wrote: Does anyone understand why this happens? Is there any way to subvert this behaviour, or is it actually a bug? Yes, see also my bug report, https://issues.dlang.org/show_bu

class Object with Dependency Injection

2023-06-18 Thread Salih Dincer via Digitalmars-d-learn
Hi, below is an example of DI-dependency injection with 3 versions nested in the code. If you remove the leading // characters, you will not get the "no property `deliver` for `service` of type `object.Object`" error. Because version-2I with interface wants its methods to depend on Object..

Re: Como puedo hacer funciones asincronas?

2023-06-18 Thread Ali Çehreli via Digitalmars-d-learn
On 6/17/23 20:20, Cecil Ward wrote: > On Saturday, 17 June 2023 at 22:05:37 UTC, Danico wrote: >> hola gente, quisiera saber como es que puedo hacer funciones asincronas. >> ` >> #!/usr/bin/env dmd >> import std; >> import std.stdio; >> import std.concurrency; >> //import archivo2; >> >> alias pri

Re: class Object with Dependency Injection

2023-06-18 Thread Ali Çehreli via Digitalmars-d-learn
On 6/18/23 07:37, Salih Dincer wrote: >auto truck = new Truck; >auto ship = new Ship; > >auto services = [ truck, ship ]; The problem is with the deduced type of 'services'. I don't know the mechanism behind it but the common type of 'truck' and 'ship' are deduced to be Object. App

Re: How does D’s ‘import’ work?

2023-06-18 Thread rempas via Digitalmars-d-learn
On Wednesday, 31 May 2023 at 18:43:52 UTC, Cecil Ward wrote: Is there an explanation of how D’s ‘import’ works somewhere? I’m trying to understand the comparison with the inclusion of .h files, similarities if any and differences with the process. I do wonder why no-one have linked the [Module

Re: How does D’s ‘import’ work?

2023-06-18 Thread rempas via Digitalmars-d-learn
On Thursday, 8 June 2023 at 04:17:20 UTC, Cecil Ward wrote: I was thinking about the situation in C where I have a rule in a make file that lists the .h files as well as the .c all as dependencies in creating an object file. I don't think I'm aware of what you mean with "lists .h and .c files

need `this` for `this` of type `ref @safe Test(string reg_arg)

2023-06-18 Thread rempas via Digitalmars-d-learn
Ok, so I'm having a struct that has a constructor that takes a template parameter. I suppose this question could also be named `how to initialize constructors with template parameters` but whatever! The funny thing is, I think that I may have already found how to do it in the past but I forgot.

Re: need `this` for `this` of type `ref @safe Test(string reg_arg)

2023-06-18 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 18 June 2023 at 17:43:01 UTC, rempas wrote: Ok, so I'm having a struct that has a constructor that takes a template parameter. I suppose this question could also be named `how to initialize constructors with template parameters` but whatever! The funny thing is, I think that I may ha

Re: need `this` for `this` of type `ref @safe Test(string reg_arg)

2023-06-18 Thread rempas via Digitalmars-d-learn
On Sunday, 18 June 2023 at 18:17:16 UTC, Paul Backus wrote: `__ctor` doesn't create a new object, it initializes an existing object. You need to create the object first, then call `__ctor` on it: ```d void main() { Test test; test.__ctor!("non_def")("Hello"); } ``` Thank you! Do you kn

Re: need `this` for `this` of type `ref @safe Test(string reg_arg)

2023-06-18 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 18 June 2023 at 19:05:19 UTC, rempas wrote: On Sunday, 18 June 2023 at 18:17:16 UTC, Paul Backus wrote: `__ctor` doesn't create a new object, it initializes an existing object. You need to create the object first, then call `__ctor` on it: ```d void main() { Test test; test._

Re: class Object with Dependency Injection

2023-06-18 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 18 June 2023 at 16:58:15 UTC, Ali Çehreli wrote: The problem is with the deduced type of 'services'. I don't know the mechanism behind it but the common type of 'truck' and 'ship' are deduced to be Object. Apparently, their interfaces don't take part in that decision. I don't know wh

Re: How does D’s ‘import’ work?

2023-06-18 Thread Cecil Ward via Digitalmars-d-learn
On Sunday, 18 June 2023 at 17:34:51 UTC, rempas wrote: On Thursday, 8 June 2023 at 04:17:20 UTC, Cecil Ward wrote: I was thinking about the situation in C where I have a rule in a make file that lists the .h files as well as the .c all as dependencies in creating an object file. I don't think

Re: How does D’s ‘import’ work?

2023-06-18 Thread Cecil Ward via Digitalmars-d-learn
On Thursday, 8 June 2023 at 05:11:04 UTC, Ali Çehreli wrote: On 6/7/23 21:17, Cecil Ward wrote: > I was thinking about the situation in C where I have a rule in a make > file that lists the .h files as well as the .c all as dependencies in > creating an object file. dmd's -makedeps command line

Re: need `this` for `this` of type `ref @safe Test(string reg_arg)

2023-06-18 Thread rempas via Digitalmars-d-learn
On Sunday, 18 June 2023 at 19:22:45 UTC, Paul Backus wrote: No, there is no way to pass template arguments to a constructor without using `__ctor`. My recommendation is to use a free function or a `static` method instead. For example: ```d import std.stdio; struct Test {} Test makeTest(s

Re: How does D’s ‘import’ work?

2023-06-18 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 18 June 2023 at 20:24:10 UTC, Cecil Ward wrote: On Thursday, 8 June 2023 at 05:11:04 UTC, Ali Çehreli wrote: dmd's -makedeps command line switch should be helpful there. (I did not use it.) Ali I wasn’t intending to use DMD, rather ldc if possible or GDC because of their excell

Re: Strange behaviour of __traits(allMembers)

2023-06-18 Thread FeepingCreature via Digitalmars-d-learn
On Sunday, 18 June 2023 at 10:21:16 UTC, IchorDev wrote: On Sunday, 18 June 2023 at 10:04:14 UTC, FeepingCreature wrote: On Sunday, 18 June 2023 at 09:48:40 UTC, IchorDev wrote: Does anyone understand why this happens? Is there any way to subvert this behaviour, or is it actually a bug? Yes,

Re: How does D’s ‘import’ work?

2023-06-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, June 18, 2023 2:24:10 PM MDT Cecil Ward via Digitalmars-d-learn wrote: > I wasn’t intending to use DMD, rather ldc if possible or GDC > because of their excellent optimisation, in which DMD seems > lacking, is that fair? (Have only briefly looked at dmd+x86 and > haven’t given DMD’s bac

Re: How does D’s ‘import’ work?

2023-06-18 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jun 18, 2023 at 03:51:14PM -0600, Jonathan M Davis via Digitalmars-d-learn wrote: > On Sunday, June 18, 2023 2:24:10 PM MDT Cecil Ward via Digitalmars-d-learn > wrote: > > I wasn’t intending to use DMD, rather ldc if possible or GDC > > because of their excellent optimisation, in which DM

Using C++ Classes From D: dmd cannot link, while ldc segfault

2023-06-18 Thread mw via Digitalmars-d-learn
Hi, I'm following this example: https://dlang.org/spec/cpp_interface.html#using_cpp_classes_from_d and try to wrap a std::list base.cpp ```cpp #include #include using namespace std; class Base { public: virtual void print3i(int a, int b, int c) = 0; }; class Derived : public B

Re: Using C++ Classes From D: dmd cannot link, while ldc segfault

2023-06-18 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
This is just a guess, but I think the problem is the vtable is incomplete. Because of this the offsets are wrong. So you wouldn't be calling push_back.

Re: Using C++ Classes From D: dmd cannot link, while ldc segfault

2023-06-18 Thread mw via Digitalmars-d-learn
On Monday, 19 June 2023 at 05:32:23 UTC, Richard (Rikki) Andrew Cattermole wrote: This is just a guess, but I think the problem is the vtable is incomplete. Because of this the offsets are wrong. So you wouldn't be calling push_back. So, you mean on the D side, it need to list all the fields

Re: Using C++ Classes From D: dmd cannot link, while ldc segfault

2023-06-18 Thread mw via Digitalmars-d-learn
On Monday, 19 June 2023 at 05:39:51 UTC, mw wrote: Then it will be very tedious, esp. for such library class std::list. Is there a tool that can automate this? A related question: basically I want to pass an array of objects from D side to the Cpp side, is there any example showing how to

Re: Using C++ Classes From D: dmd cannot link, while ldc segfault

2023-06-18 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 19/06/2023 5:39 PM, mw wrote: Then it will be very tedious, esp. for such library class std::list. Yes, you would also need to verify it with every compiler you need (MSVC, vs linux gcc). There could be a reason why it isn't in https://github.com/dlang/dmd/tree/master/druntime/src/core

Re: Using C++ Classes From D: dmd cannot link, while ldc segfault

2023-06-18 Thread mw via Digitalmars-d-learn
On Monday, 19 June 2023 at 05:46:13 UTC, Richard (Rikki) Andrew Cattermole wrote: On 19/06/2023 5:39 PM, mw wrote: Then it will be very tedious, esp. for such library class std::list. Yes, you would also need to verify it with every compiler you need (MSVC, vs linux gcc). There could be a

Re: Using C++ Classes From D: dmd cannot link, while ldc segfault

2023-06-18 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 19/06/2023 5:54 PM, mw wrote: Ha, I saw vector.d there, So I can use this vector.d as the D side of C++'s std::vector? Probably, I just don't know how well tested it is. But worth a go!

Re: Using C++ Classes From D: dmd cannot link, while ldc segfault

2023-06-18 Thread mw via Digitalmars-d-learn
On Monday, 19 June 2023 at 05:56:54 UTC, Richard (Rikki) Andrew Cattermole wrote: On 19/06/2023 5:54 PM, mw wrote: Ha, I saw vector.d there, So I can use this vector.d as the D side of C++'s std::vector? Probably, I just don't know how well tested it is. But worth a go! ``` import core.stdc

Re: Using C++ Classes From D: dmd cannot link, while ldc segfault

2023-06-18 Thread mw via Digitalmars-d-learn
If I use array: ``` extern(C++) { void getInts(core.stdcpp.array.array!(int, 10) vec) { foreach (int i; 0 .. 10) { vec.at(i) = i; } } } ``` ``` #include using namespace std; void getInts(array* vector); ``` Both DMD and LDC has link error: base.cpp:42: undefined reference to `getIn