Re: How to unpack template parameters,Or how to forward parameters?

2022-05-05 Thread vit via Digitalmars-d-learn
On Friday, 6 May 2022 at 00:41:18 UTC, zjh wrote: Hello everyone,I have following function: ```d import core.stdc.stdio; void f(int i,int j){ printf("%i,%i",i,j); } ``` I want to forward `int[N]` to `(int i,int j)` etc. How can I write a forwarding function? ```d void ff(alias

Including C sources in a DUB project

2022-05-05 Thread Alexander Zhirov via Digitalmars-d-learn
I'm sure there is such a topic on the forum, but after scrolling through the search, I didn't find anything. The bottom line is that I want to enable compilation of C sources in DUB and then build the project with the connection of libraries. I would like to see an example of such a `dub.json`

Why isn't my dynamic array method doesn't work for this type?

2022-05-05 Thread rempas via Digitalmars-d-learn
I have created a structure that is a actually an array that allocates memory and growths. It is a template and it has worked with a couple of types that I have tried with. It doesn't work with one tho and I cannot understand why. I will list the smallest possible code I could. Keep in mind

Re: Unittests being broken

2022-05-05 Thread René Zwanenburg via Digitalmars-d-learn
On Thursday, 5 May 2022 at 01:44:37 UTC, Ruby The Roobster wrote: Some code I have: (...) What can I do to fix this? I didn't try your code, but opList, funcList, and noTouch are thread-local variables, and you fill them in a shared static this. This means they will remain empty in any

Re: Why isn't my dynamic array method doesn't work for this type?

2022-05-05 Thread vit via Digitalmars-d-learn
On Thursday, 5 May 2022 at 11:49:29 UTC, vit wrote: On Thursday, 5 May 2022 at 10:40:44 UTC, rempas wrote: I have created a structure that is a actually an array that allocates memory and growths. It is a template and it has worked with a couple of types that I have tried with. It doesn't

Re: Including C sources in a DUB project

2022-05-05 Thread Alexander Zhirov via Digitalmars-d-learn
On Thursday, 5 May 2022 at 16:23:18 UTC, H. S. Teoh wrote: I don't know how to do it using dub, but you could use pragma(lib) in one (or more) of your source files as a workaround: pragma(lib, "m"); pragma(lib, "X11"); pragma(lib, "Xrandr"); I remember a long time

Re: Including C sources in a DUB project

2022-05-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 05, 2022 at 06:05:55AM +, Alexander Zhirov via Digitalmars-d-learn wrote: > I'm sure there is such a topic on the forum, but after scrolling > through the search, I didn't find anything. The bottom line is that I > want to enable compilation of C sources in DUB and then build the

Re: Using regular expressions when reading a file

2022-05-05 Thread Alexander Zhirov via Digitalmars-d-learn
On Thursday, 5 May 2022 at 18:58:41 UTC, H. S. Teoh wrote: You don't have to. Just add a `$` to the end of your regex, and it should match the newline. If you put it outside the capture parentheses, it will not be included in the value. In fact, it turned out to be much easier. It was just

Re: Using regular expressions when reading a file

2022-05-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 05, 2022 at 06:50:17PM +, Alexander Zhirov via Digitalmars-d-learn wrote: > On Thursday, 5 May 2022 at 18:15:28 UTC, H. S. Teoh wrote: > > auto m = matchFirst(line, p_property); > > Yes, it looks more attractive. Thanks! I just don't quite understand how > `matchFirst` works.

Re: Using regular expressions when reading a file

2022-05-05 Thread Ali Çehreli via Digitalmars-d-learn
On 5/5/22 12:05, Alexander Zhirov wrote: On Thursday, 5 May 2022 at 18:58:41 UTC, H. S. Teoh wrote: You don't have to. Just add a `$` to the end of your regex, and it should match the newline. If you put it outside the capture parentheses, it will not be included in the value. In fact, it

Re: Using regular expressions when reading a file

2022-05-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 05, 2022 at 05:53:57PM +, Alexander Zhirov via Digitalmars-d-learn wrote: > I want to use a configuration file with external settings. I'm trying > to use regular expressions to read the `Property = Value` settings. I > would like to do it all more beautifully. Is there any way to

Re: Using regular expressions when reading a file

2022-05-05 Thread Alexander Zhirov via Digitalmars-d-learn
On Thursday, 5 May 2022 at 18:15:28 UTC, H. S. Teoh wrote: auto m = matchFirst(line, p_property); Yes, it looks more attractive. Thanks! I just don't quite understand how `matchFirst` works. I seem to have read the [description](https://dlang.org/phobos/std_regex.html#Captures), but

Using regular expressions when reading a file

2022-05-05 Thread Alexander Zhirov via Digitalmars-d-learn
I want to use a configuration file with external settings. I'm trying to use regular expressions to read the `Property = Value` settings. I would like to do it all more beautifully. Is there any way to get rid of the line break character? How much does everything look "right"?

Re: Why isn't my dynamic array method doesn't work for this type?

2022-05-05 Thread vit via Digitalmars-d-learn
On Thursday, 5 May 2022 at 10:40:44 UTC, rempas wrote: I have created a structure that is a actually an array that allocates memory and growths. It is a template and it has worked with a couple of types that I have tried with. It doesn't work with one tho and I cannot understand why. I will

Re: Why isn't my dynamic array method doesn't work for this type?

2022-05-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/5/22 6:40 AM, rempas wrote:   ref My_File opAssign(ref const My_File s) return { return this; } Your assignment operator does nothing. -Steve

Re: Using regular expressions when reading a file

2022-05-05 Thread Alexander Zhirov via Digitalmars-d-learn
On Thursday, 5 May 2022 at 19:19:26 UTC, Ali Çehreli wrote: Couldn't help myself from improving. :) The following regex works in my Linux console. No issues with '\n'. (?) It also allows for leading and trailing spaces: import std.regex; import std.stdio; import std.algorithm; import

Re: Why isn't my dynamic array method doesn't work for this type?

2022-05-05 Thread rempas via Digitalmars-d-learn
On Thursday, 5 May 2022 at 11:49:29 UTC, vit wrote: ```d this.capacity += DEF_VEC_REALLOC_SIZE; //realloc(this.ptr, T.sizeof * DEF_VEC_REALLOC_SIZE); this.ptr = realloc(this.ptr, T.sizeof * this.capacity); //<<-- ``` Oh, right! I forgot to say it. I'm using my own

Re: Why isn't my dynamic array method doesn't work for this type?

2022-05-05 Thread rempas via Digitalmars-d-learn
On Thursday, 5 May 2022 at 14:20:49 UTC, Steven Schveighoffer wrote: Your assignment operator does nothing. -Steve Thanks! That was indeed the problem! In the other data structures, it worked without needing explicitly provide one so I didn't thought about it. Thanks a lot, you're saving

Re: Why isn't my dynamic array method doesn't work for this type?

2022-05-05 Thread colleen camacho via Digitalmars-d-learn
On Thursday, 5 May 2022 at 10:40:44 UTC, rempas wrote: I have created a structure that is a actually an array that allocates memory and growths. It is a template and it has worked with a couple of types that I have tried with. It doesn't work with one tho and I cannot understand why. I will

How to unpack template parameters,Or how to forward parameters?

2022-05-05 Thread zjh via Digitalmars-d-learn
Hello everyone,I have following function: ```d import core.stdc.stdio; void f(int i,int j){ printf("%i,%i",i,j); } ``` I want to forward `int[N]` to `(int i,int j)` etc. How can I write a forwarding function? ```d void ff(alias g,int...I)(int[2]k){ g(k[I]); }//How to unpack template

Re: Google Code Jam 2022

2022-05-05 Thread Siarhei Siamashka via Digitalmars-d-learn
Now all three parts of the round 1 are over and finalized. There's a third-party website, which provides some stats: https://cpjsmith.uk/gcj/year?year=2022 It's interesting that D is one of the least popular programing languages with only a single digit number of users. It never managed to

Re: Using regular expressions when reading a file

2022-05-05 Thread forkit via Digitalmars-d-learn
On Thursday, 5 May 2022 at 17:53:57 UTC, Alexander Zhirov wrote: I want to use a configuration file with external settings. I'm trying to use regular expressions to read the `Property = Value` settings. I would like to do it all more beautifully. Is there any way to get rid of the line break