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

2020-09-26 Thread 60rntogo via Digitalmars-d-learn
On Saturday, 26 September 2020 at 23:23:13 UTC, Adam D. Ruppe wrote: As a result, you `add` works fine I'm afraid not. __traits(isStaticFunction, add) is false, I think it's because it checks if it is a static member function of some struct/class. How would I check if it is actually a free

Re: conflicting alias in package module

2020-09-26 Thread 60rntogo via Digitalmars-d-learn
On Sunday, 27 September 2020 at 03:33:20 UTC, Mike Parker wrote: package.d is for your external interface. Fair enough, thanks.

Re: conflicting alias in package module

2020-09-26 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 26 September 2020 at 22:43:10 UTC, 60rntogo wrote: OK, sure. It's just that the motivation behind doing public imports in package.d is that I can write "import pack" instead of "import pack.foo". I guess it simply doesn't work within the package itself. package.d is for your

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

2020-09-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 26 September 2020 at 22:58:44 UTC, 60rntogo wrote: I get the error "undefined identifier isValid". How can I make this work? This part is easy, you need to give the name like assert(invoke!(Foo.isValid)(foo, 3)); Now, the other part is tricky, and a new feature just released

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

2020-09-26 Thread 60rntogo via Digitalmars-d-learn
I tried this: --- auto invoke(alias fun, Args...)(Args args) { return fun(args); } --- which works with free functions: --- int add(int a, int b) { return a + b; } assert(invoke!add(1, 2) == 3); --- but with a method: --- struct Foo { bool isValid(int a) { return a > 0; } }

Re: Is it possible to "overload" based on visibility?

2020-09-26 Thread 60rntogo via Digitalmars-d-learn
On Friday, 25 September 2020 at 18:58:54 UTC, H. S. Teoh wrote: You probably need to use the long-form of templates, with separate function declarations, to accomplish this. E.g.: ... Alright, but your example still contains shouldReturnByRef which presumably I need to implement myself. But

Re: conflicting alias in package module

2020-09-26 Thread 60rntogo via Digitalmars-d-learn
On Saturday, 26 September 2020 at 15:12:47 UTC, Steven Schveighoffer wrote: Instead: import pack.foo : Foo; Works. OK, sure. It's just that the motivation behind doing public imports in package.d is that I can write "import pack" instead of "import pack.foo". I guess it simply doesn't work

Re: Struct initializer in UDA

2020-09-26 Thread Anonymouse via Digitalmars-d-learn
On Saturday, 26 September 2020 at 16:05:58 UTC, realhet wrote: Hi, struct S{int a, b, c=9, d, e, f;} Is there a way or a trick to declare an UDA by using a nice struct initializer? It would be nice to be able to use the form: @S{f:42} int a; //or something similar to this. instead of

Struct initializer in UDA

2020-09-26 Thread realhet via Digitalmars-d-learn
Hi, struct S{int a, b, c=9, d, e, f;} Is there a way or a trick to declare an UDA by using a nice struct initializer? It would be nice to be able to use the form: @S{f:42} int a; //or something similar to this. instead of this longer and error-prone way: @S(0, 0, 0, 9, 0, 42) int

Re: conflicting alias in package module

2020-09-26 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/26/20 10:59 AM, 60rntogo wrote: On Saturday, 26 September 2020 at 13:45:21 UTC, Steven Schveighoffer wrote: A selective import is equivalent to aliasing (to the public) the symbol as if it were defined in that scope. You have to label it as private if you want it to be private. Are you

Re: conflicting alias in package module

2020-09-26 Thread 60rntogo via Digitalmars-d-learn
On Saturday, 26 September 2020 at 13:45:21 UTC, Steven Schveighoffer wrote: A selective import is equivalent to aliasing (to the public) the symbol as if it were defined in that scope. You have to label it as private if you want it to be private. Are you saying that I should write this in

Re: conflicting alias in package module

2020-09-26 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/26/20 3:33 AM, 60rntogo wrote: I have a package with the following structure: pack |- foo.d |- bar.d |- package.d and the modules look like this: --- module pack.foo; struct Foo {} --- module pack.bar; import pack : Foo; --- module pack; public import pack.foo, pack.bar; --- and this

Re: Methods for expanding class in another class/struct

2020-09-26 Thread k2aj via Digitalmars-d-learn
On Saturday, 26 September 2020 at 10:26:15 UTC, IGotD- wrote: One thing that struck me looking at the source code of scoped, would scoped work inside a class and not only for stack allocations? It does work, the problem is that scoped returns a Voldemort type, so you have to use

Re: Methods for expanding class in another class/struct

2020-09-26 Thread IGotD- via Digitalmars-d-learn
One thing that struck me looking at the source code of scoped, would scoped work inside a class and not only for stack allocations?

Methods for expanding class in another class/struct

2020-09-26 Thread IGotD- via Digitalmars-d-learn
We know that classes are all reference typed so that classes must be allocated on the heap. However, this memory could be taken from anywhere so basically this memory could be a static array inside the class. This is pretty much what the scoped template does when allocating a class on the

conflicting alias in package module

2020-09-26 Thread 60rntogo via Digitalmars-d-learn
I have a package with the following structure: pack |- foo.d |- bar.d |- package.d and the modules look like this: --- module pack.foo; struct Foo {} --- module pack.bar; import pack : Foo; --- module pack; public import pack.foo, pack.bar; --- and this is an error: "struct pack.foo.Foo at

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

2020-09-26 Thread John Chapman via Digitalmars-d-learn
On Friday, 25 September 2020 at 15:03:56 UTC, Marcone wrote: I need windowsx.d but for I don't know the reason is not in dmd. Someone that have it can send to me? I don't know convert windowsx.h to windowsx.d windowsx.h is mostly a bunch of macros that forward to functions elsewhere in the