Re: Removing elements from dynamic arrays?

2022-04-06 Thread Siarhei Siamashka via Digitalmars-d-learn
On Wednesday, 6 April 2022 at 19:28:53 UTC, Steven Schveighoffer wrote: With `arr.find!(someLambda)`, if the lambda is using data from outside the lambda, it needs a closure, which means it may (probably does) allocate your needed data into a GC heap block that will then become garbage after

Re: Removing elements from dynamic arrays?

2022-04-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/6/22 2:32 PM, Salih Dincer wrote: On Wednesday, 6 April 2022 at 16:54:26 UTC, Steven Schveighoffer wrote: This is almost equivalent, but it requires a lambda and an allocation. So I'm not sure what thing you are trying to do here. **Source Code:**

Re: Looking for a workaround

2022-04-06 Thread Guillaume Piolat via Digitalmars-d-learn
On Wednesday, 6 April 2022 at 18:21:11 UTC, Adam D Ruppe wrote: On Wednesday, 6 April 2022 at 18:10:32 UTC, Guillaume Piolat wrote: Any idea how to workaround that? Works fine if you just use the language instead of the buggy phobos wrappers: --- struct MyUDA { } class A

Re: Removing elements from dynamic arrays?

2022-04-06 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 6 April 2022 at 16:54:26 UTC, Steven Schveighoffer wrote: This is almost equivalent, but it requires a lambda and an allocation. So I'm not sure what thing you are trying to do here. I tried to get these results but it didn't work: abc efg h [0, 3] [4, 7] [8, 9] abcefgh

Re: Looking for a workaround

2022-04-06 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 6 April 2022 at 18:10:32 UTC, Guillaume Piolat wrote: Any idea how to workaround that? Works fine if you just use the language instead of the buggy phobos wrappers: --- struct MyUDA { } class A { @MyUDA int a; } class B : A {

Looking for a workaround

2022-04-06 Thread Guillaume Piolat via Digitalmars-d-learn
This program fails to build: import std.traits: getSymbolsByUDA; struct MyUDA { } class A { @MyUDA int a; } class B : A { @MyUDA int b; } void main() { alias G = getSymbolsByUDA!(B, MyUDA); } Output:

Re: Mixin Templates and Operators

2022-04-06 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 6 April 2022 at 17:33:28 UTC, Steven Schveighoffer wrote: As I mentioned elsewhere, it does work. But the situation I think must be that it's only one mixin template. Probably also you can't have any overloads in the type itself. ooh yeah there's multiple here so the

Re: Mixin Templates and Operators

2022-04-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/6/22 12:52 PM, Adam D Ruppe wrote: On Wednesday, 6 April 2022 at 10:36:04 UTC, francesco.andreetto wrote: Am I doing something wrong or it is impossible to use mixin templates like that? mixin templates can't bring in operator overloads. The spec doesn't really say this I think, but

Re: Mixin Templates and Operators

2022-04-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/6/22 6:36 AM, francesco.andreetto wrote: I have two structs, point and vec, in which I want to implement some arithmetic operations. The operations are: ``` point - point = vec point + vec = point ``` Using mixin templates the code compiles but calling the operations in the main causes

Re: Removing elements from dynamic arrays?

2022-04-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/5/22 11:47 PM, Salih Dincer wrote: On Tuesday, 5 April 2022 at 14:10:44 UTC, Steven Schveighoffer wrote: [...] I'd implement it probably like this (for D2): ```d auto drop(T)(ref T[] arr, T which) {    import std.algorithm, std.range;    auto f = arr.find(which);    debug if(f.empty)

Re: Mixin Templates and Operators

2022-04-06 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 6 April 2022 at 10:36:04 UTC, francesco.andreetto wrote: Am I doing something wrong or it is impossible to use mixin templates like that? mixin templates can't bring in operator overloads. The spec doesn't really say this I think, but that's the way it has been for a long time.

Re: Mixin Templates and Operators

2022-04-06 Thread Tejas via Digitalmars-d-learn
On Wednesday, 6 April 2022 at 10:36:04 UTC, francesco.andreetto wrote: I have two structs, point and vec, in which I want to implement some arithmetic operations. The operations are: ``` point - point = vec point + vec = point ``` Using mixin templates the code compiles but calling the

Re: How to print or check if a string is "\0" (null) terminated in the D programming language?

2022-04-06 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 6 April 2022 at 08:55:43 UTC, BoQsc wrote: I have a feeling that some parts of my code contains unterminated strings and they do overflow into other string [...] If you suspect overflow, you can try string wrapping.

Mixin Templates and Operators

2022-04-06 Thread francesco.andreetto via Digitalmars-d-learn
I have two structs, point and vec, in which I want to implement some arithmetic operations. The operations are: ``` point - point = vec point + vec = point ``` Using mixin templates the code compiles but calling the operations in the main causes an "incompatible type" Error: ```d mixin

Re: How to print or check if a string is "\0" (null) terminated in the D programming language?

2022-04-06 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 6 April 2022 at 08:55:43 UTC, BoQsc wrote: I have a feeling that some parts of my code contains unterminated strings and they do overflow into other string that is to be combined. I'd like to take a look at strings, analyse them manually and see if any of them end up terminated

Re: How to print or check if a string is "\0" (null) terminated in the D programming language?

2022-04-06 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 6 April 2022 at 08:55:43 UTC, BoQsc wrote: I have a feeling that some parts of my code contains unterminated strings and they do overflow into other string that is to be combined. I'd like to take a look at strings, analyse them manually and see if any of them end up terminated

How to print or check if a string is "\0" (null) terminated in the D programming language?

2022-04-06 Thread BoQsc via Digitalmars-d-learn
I have a feeling that some parts of my code contains unterminated strings and they do overflow into other string that is to be combined. I'd like to take a look at strings, analyse them manually and see if any of them end up terminated or not. Please provide any relevant examples of how you