Re: Should I worry about this hashOf warning ?

2025-06-26 Thread axricard via Digitalmars-d-learn
On Thursday, 26 June 2025 at 03:55:03 UTC, Jonathan M Davis wrote: [...] Thanks for these wonderful explanations ! A const @safe nothrow toHash indeed solved this.

Should I worry about this hashOf warning ?

2025-06-25 Thread axricard via Digitalmars-d-learn
When trying to use Nullable with a struct containing an overlapping pointer: ```D import std; struct S { union { long foo; int[] bar; } } void main() { Nullable!S s; } ``` I get this warning: ``` /dlang/dmd/linux/bin64/../../src/phobos/std/typecons.d(3820):

Re: interface inference with delegates/functions

2025-02-05 Thread axricard via Digitalmars-d-learn
On Wednesday, 5 February 2025 at 01:20:07 UTC, Jonathan M Davis wrote: Note that it talks about the "initial inferred return type", whereas your function doesn't have an initial inferred return type, because it fails to compile when determining the return type. So, while the spec doesn't expand

interface inference with delegates/functions

2025-02-04 Thread axricard via Digitalmars-d-learn
Basically the same question than https://forum.dlang.org/post/aoltazzfmnztsyatf...@forum.dlang.org but with functions/delegates and inferred return types: ``` D interface I { bool check(); } class A : I { bool check() =>true; } class B : I { bool check() =>false; } void

Copying file to /dev/null

2025-01-24 Thread axricard via Digitalmars-d-learn
``` D import std; void main() { auto sourceName = deleteme ~ "source"; auto source = File(sourceName, "w"); source.write("source"); copy(sourceName, "/dev/null"); } ``` The copy to /dev/null fails : `std.file.FileException@std/file.d(4348): /dev/null: Invalid argument`, which

Re: meson unittest

2025-01-08 Thread axricard via Digitalmars-d-learn
On Tuesday, 7 January 2025 at 17:55:50 UTC, sfp wrote: File `meson.build`: ``` project('unittest', 'd') mainlib = library('mainlib', ['blah.d']) executable('maintest', ['main.d'], link_with: [mainlib], d_unittest: true) ``` Your first version is indeed wrong because the library is not comp

Re: meson unittest

2025-01-07 Thread axricard via Digitalmars-d-learn
On Sunday, 5 January 2025 at 23:52:24 UTC, sfp wrote: Anyone have a good way of yanking out all `unittest { ... }` blocks from a library compiled using Meson? It would be nice to approximate what dub does. Meson has mentions this trick in its help docs (https://mesonbuild.com/D.html#using-emb

Partial application on Nth argument

2024-12-04 Thread axricard via Digitalmars-d-learn
Hello I believe std.functional.partial can only apply to the first argument. Is there an equivalent for the Nth argument ? Something like : ``` D int fun(int a, int b) { return a - b; } // create a function with the argument n°1 being equal to 5 // fun5 = fun(a, 5); alias fun5 = partialN!(fu

Re: Pick a class at random

2024-01-04 Thread axricard via Digitalmars-d-learn
On Wednesday, 3 January 2024 at 17:44:00 UTC, H. S. Teoh wrote: On Wed, Jan 03, 2024 at 04:50:57PM +, axricard via Digitalmars-d-learn wrote: I have an interface that is implemented by many classes, and I want to pick one of these implementations at random. There are two more constraints

Pick a class at random

2024-01-03 Thread axricard via Digitalmars-d-learn
I have an interface that is implemented by many classes, and I want to pick one of these implementations at random. There are two more constraints : first the distribution is not uniform, all classes can define the chance they have to be picked (this is reflected by the function 'weight()' belo

Re: GC doesn't collect where expected

2023-06-19 Thread axricard via Digitalmars-d-learn
On Monday, 19 June 2023 at 16:43:30 UTC, Steven Schveighoffer wrote: In general, the language does not guarantee when the GC will collect your item. In this specific case, most likely it's a stale register or stack reference. One way I usually use to ensure such things is to call a function

Re: GC doesn't collect where expected

2023-06-19 Thread axricard via Digitalmars-d-learn
On Monday, 19 June 2023 at 16:43:30 UTC, Steven Schveighoffer wrote: In general, the language does not guarantee when the GC will collect your item. In this specific case, most likely it's a stale register or stack reference. One way I usually use to ensure such things is to call a function t

GC doesn't collect where expected

2023-06-19 Thread axricard via Digitalmars-d-learn
I'm doing some experiments with ldc2 GC, by instrumenting it and printing basic information (what is allocated and freed) My first tests are made on this sample : ``` cat test2.d import core.memory; class Bar { int bar; } class Foo { this() { this.bar = new Bar; } Bar bar; }