Re: Template + alias + basic type depends on another parameter = broken?

2023-02-22 Thread Paul Backus via Digitalmars-d-learn

On Wednesday, 22 February 2023 at 20:20:46 UTC, Dark Hole wrote:

```d
template Foo(T, alias T[] Array) {
// ...
}
// ...
Bar[] arr;
Foo!(Bar, arr);
```

This is valid D, but it doesn't work. It gives error "Error: 
template instance `Foo!(Bar, arr)` does not match template 
declaration `Foo(T, alias T[] Array)`".


Of course, there is some ways to avoid this error (e.g. check 
Array type in if), but I don't undestand why this code doesn't 
compiles.


Pretty sure this is just a bug. There are a lot of edge-case bugs 
like this where template instantiation doesn't work the way it's 
supposed to.


I've submitted a bug report for this on issues.dlang.org: 
https://issues.dlang.org/show_bug.cgi?id=23733


Template + alias + basic type depends on another parameter = broken?

2023-02-22 Thread Dark Hole via Digitalmars-d-learn
I'm trying to rewrite really old D code. There was fragment like 
that:

```d
template Foo(T, T[] Array) {
// ...
}
// ...
Bar[] arr;
Foo!(Bar, arr);
```

This gives error `can't read arr in compile time`. Small changes:
```d
template Foo(T, alias T[] Array) {
// ...
}
// ...
Bar[] arr;
Foo!(Bar, arr);
```

This is valid D, but it doesn't work. It gives error "Error: 
template instance `Foo!(Bar, arr)` does not match template 
declaration `Foo(T, alias T[] Array)`".


Of course, there is some ways to avoid this error (e.g. check 
Array type in if), but I don't undestand why this code doesn't 
compiles.


Re: importC - how to use more effectively?

2023-02-22 Thread Andrea Fontana via Digitalmars-d-learn

On Wednesday, 22 February 2023 at 15:00:56 UTC, WebFreak001 wrote:
I just first time used importC in a prototype project I just 
worked on. I used it to just import `libevdev.h` on linux to 
register a custom input device / make a simple userspace input 
driver.


A suggestion: try tcc as preprocessor. It works better than gcc 
for importc.


Andrea Fontana


importC - how to use more effectively?

2023-02-22 Thread WebFreak001 via Digitalmars-d-learn
I just first time used importC in a prototype project I just 
worked on. I used it to just import `libevdev.h` on linux to 
register a custom input device / make a simple userspace input 
driver.


Now libevdev comes with two header files: libevdev.h and 
libevdev-uinput.h


Q1) Since libevdev-uinput.h included libevdev.h, I could simply 
import that to get everything. What would I do in more complex 
libraries that are composed of multiple header files though?


I had a small problem: linux/input.h was included, but not found 
/ not properly processed, so I had to manually look that up in 
the correct architecture folder of my linux distro.


What I now did was copy-pasting the files both from libevdev and 
from linux/input.h from my local system into my project 
directory, running `gcc -E` and manually cleaning up things, so 
that stuff like `u8` existed. (using a package in D that I would 
`__import` to include compat things)


Q2) How would I do this without manually copying and editing the 
header files, so that it would work on other people's machines as 
well, using their local headers?


---

I'm quite a fan of how easy it was using importC to get libevdev 
running in my custom program and quickly making a basic custom 
input device, exactly with the same syntax and functions as in C, 
but this only really seems to work inside the prototyping phase. 
What would be the next steps if I wanted to make e.g. a libevdev 
wrapper to put on DUB?


Q3) Would generating D code from importC be possible for this?


Re: How to get only the field name from an alias?

2023-02-22 Thread Elfstone via Digitalmars-d-learn

On Tuesday, 21 February 2023 at 12:32:51 UTC, Adam D Ruppe wrote:

On Tuesday, 21 February 2023 at 02:41:34 UTC, Elfstone wrote:

apparently F.stringof


You almost never want to use .stringof, instead try 
__traits(identifier, F) and see what it gives you.



Alternatively, loop over __traits(allMembers) which gives you 
the member names and pass that down. You can pull all the info 
out of allMembers with getMember and then other things to 
filter it out.


Thanks, Adam! Didn't know such a trait existed and that it could 
work for aliases.