Re: How to call destroy() in @nogc?

2022-05-23 Thread cc via Digitalmars-d-learn
On Tuesday, 24 May 2022 at 02:55:06 UTC, Tejas wrote: On Tuesday, 24 May 2022 at 02:29:38 UTC, cc wrote: ```d import core.memory; import core.stdc.stdlib : malloc, free; import core.lifetime : emplace; [...] FWIW your code will compile if you add `extern(C++)` to `Foo` Interesting, thanks.

Re: How to call destroy() in @nogc?

2022-05-23 Thread Tejas via Digitalmars-d-learn
On Tuesday, 24 May 2022 at 02:29:38 UTC, cc wrote: ```d import core.memory; import core.stdc.stdlib : malloc, free; import core.lifetime : emplace; [...] FWIW your code will compile if you add `extern(C++)` to `Foo`

How to call destroy() in @nogc?

2022-05-23 Thread cc via Digitalmars-d-learn
```d import core.memory; import core.stdc.stdlib : malloc, free; import core.lifetime : emplace; T NEW(T, Args...)(auto ref Args args) /*@nogc*/ if (is(T == class)) { enum size = __traits(classInstanceSize, T); void* mem = malloc(size); scope(failure) free(mem);

Re: Does D programming language have work steal queue?

2022-05-23 Thread mw via Digitalmars-d-learn
On Monday, 23 May 2022 at 23:07:00 UTC, zoujiaqing wrote: On Sunday, 22 May 2022 at 23:34:19 UTC, mw wrote: On Sunday, 22 May 2022 at 21:07:19 UTC, zoujiaqing wrote: Does D language have task steal queue? The requirements are high-performance, lock-free, and thread-safe. I have a C's liblfds

Re: Does D programming language have work steal queue?

2022-05-23 Thread zoujiaqing via Digitalmars-d-learn
On Sunday, 22 May 2022 at 22:37:43 UTC, Stefan Koch wrote: On Sunday, 22 May 2022 at 21:07:19 UTC, zoujiaqing wrote: Does D language have task steal queue? The requirements are high-performance, lock-free, and thread-safe. I have one called fluffy: https://github.com/UplinkCoder/fluffy I am

Re: Does D programming language have work steal queue?

2022-05-23 Thread zoujiaqing via Digitalmars-d-learn
On Sunday, 22 May 2022 at 23:34:19 UTC, mw wrote: On Sunday, 22 May 2022 at 21:07:19 UTC, zoujiaqing wrote: Does D language have task steal queue? The requirements are high-performance, lock-free, and thread-safe. I have a C's liblfds D wrapper: https://github.com/mw66/liblfdsd right now on

Re: mixin template

2022-05-23 Thread Ali Çehreli via Digitalmars-d-learn
On 5/23/22 08:14, Vindex wrote: > Why? Why can't I have two constructors when I use mixin? And there is an example in Phobos: https://dlang.org/library/std/exception/basic_exception_ctors.html The documentation there mentions the following bug: https://issues.dlang.org/show_bug.cgi?id=115

Re: mixin template

2022-05-23 Thread vit via Digitalmars-d-learn
On Monday, 23 May 2022 at 15:14:53 UTC, Vindex wrote: I have this code: ``` import std.array, std.exception, std.stdio; mixin template RealizeException() { this(string msg, string file = __FILE__, size_t line = __LINE__) { super(msg, file, line); } } class WrongUsage : Except

mixin template

2022-05-23 Thread Vindex via Digitalmars-d-learn
I have this code: ``` import std.array, std.exception, std.stdio; mixin template RealizeException() { this(string msg, string file = __FILE__, size_t line = __LINE__) { super(msg, file, line); } } class WrongUsage : Exception { mixin RealizeException; this(string[] me

Re: How are delegate attributes in fn signature inferred?

2022-05-23 Thread wjoe via Digitalmars-d-learn
On Monday, 23 May 2022 at 13:53:02 UTC, Adam D Ruppe wrote: On Monday, 23 May 2022 at 13:44:53 UTC, wjoe wrote: [...] You can actually make this work with `construct!(int[])` rather than plain `construct`. This is a (really annoying) deficiency in dmd's implementation. (that sdc solved btw

Re: How are delegate attributes in fn signature inferred?

2022-05-23 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 23 May 2022 at 13:44:53 UTC, wjoe wrote: i.construct((ulong i) {return cast(int)(i+i);}).print; You can actually make this work with `construct!(int[])` rather than plain `construct`. This is a (really annoying) deficiency in dmd's implementation. (that sdc solved btw proving it

How are delegate attributes in fn signature inferred?

2022-05-23 Thread wjoe via Digitalmars-d-learn
Hello, Consider this example: ```d module foo; import std.stdio; import std.algorithm; import std.traits; import std.range; void print(R)(R r) { static assert(isIterable!R); r.each!writeln; } auto construct(R)(R r, ElementType!R delegate(ulong i) fn) { static assert(isIterable!R && hasAs

Re: Allocate a string via the GC

2022-05-23 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 23 May 2022 at 12:20:11 UTC, JG wrote: I am writing an interpreter and I needed access to a string via a pointer of type void* I ended up wrapping it in a struct since I needed another value anyway. Seems odd that one can't do it in a less unusual way. OK yeah, that's the main use c

Re: Allocate a string via the GC

2022-05-23 Thread bauss via Digitalmars-d-learn
On Monday, 23 May 2022 at 12:20:11 UTC, JG wrote: On Monday, 23 May 2022 at 11:39:22 UTC, Adam D Ruppe wrote: On Monday, 23 May 2022 at 09:38:07 UTC, JG wrote: Hi, Is there any more standard way to achieve something to the effect of: ```d import std.experimental.allocator; string* name

Re: Allocate a string via the GC

2022-05-23 Thread JG via Digitalmars-d-learn
On Monday, 23 May 2022 at 11:39:22 UTC, Adam D Ruppe wrote: On Monday, 23 May 2022 at 09:38:07 UTC, JG wrote: Hi, Is there any more standard way to achieve something to the effect of: ```d import std.experimental.allocator; string* name = theAllocator.make!string; ``` Why do you want

Re: Allocate a string via the GC

2022-05-23 Thread bauss via Digitalmars-d-learn
On Monday, 23 May 2022 at 12:17:56 UTC, bauss wrote: On Monday, 23 May 2022 at 11:39:22 UTC, Adam D Ruppe wrote: On Monday, 23 May 2022 at 09:38:07 UTC, JG wrote: Hi, Is there any more standard way to achieve something to the effect of: ```d import std.experimental.allocator; string* na

Re: Allocate a string via the GC

2022-05-23 Thread bauss via Digitalmars-d-learn
On Monday, 23 May 2022 at 11:39:22 UTC, Adam D Ruppe wrote: On Monday, 23 May 2022 at 09:38:07 UTC, JG wrote: Hi, Is there any more standard way to achieve something to the effect of: ```d import std.experimental.allocator; string* name = theAllocator.make!string; ``` Why do you want

Re: Allocate a string via the GC

2022-05-23 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Monday, 23 May 2022 at 09:38:07 UTC, JG wrote: Hi, Is there any more standard way to achieve something to the effect of: ```d import std.experimental.allocator; string* name = theAllocator.make!string; ``` Pointers are not used for strings in d. string is an alias for immutable(cha

Re: Allocate a string via the GC

2022-05-23 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 23 May 2022 at 09:38:07 UTC, JG wrote: Hi, Is there any more standard way to achieve something to the effect of: ```d import std.experimental.allocator; string* name = theAllocator.make!string; ``` Why do you want that? Easiest way I know of is to just wrap it in a struct,

Allocate a string via the GC

2022-05-23 Thread JG via Digitalmars-d-learn
Hi, Is there any more standard way to achieve something to the effect of: ```d import std.experimental.allocator; string* name = theAllocator.make!string; ```

Re: Odd construct idea. Splitting arguments inside a parameter list.

2022-05-23 Thread user1234 via Digitalmars-d-learn
On Monday, 23 May 2022 at 08:53:27 UTC, user1234 wrote: On Monday, 23 May 2022 at 08:52:12 UTC, vit wrote: On Monday, 23 May 2022 at 08:34:21 UTC, Chris Katko wrote: D struct pair { float x,y; } [...] This work too: ```d myFunction(taco, p.tupleof, burrito); ``` and you can pass a std.

Re: Odd construct idea. Splitting arguments inside a parameter list.

2022-05-23 Thread user1234 via Digitalmars-d-learn
On Monday, 23 May 2022 at 08:52:12 UTC, vit wrote: On Monday, 23 May 2022 at 08:34:21 UTC, Chris Katko wrote: D struct pair { float x,y; } [...] This work too: ```d myFunction(taco, p.tupleof, burrito); ``` and you can pass a std.typecons.Tuple as well, it will expand x y

Re: Odd construct idea. Splitting arguments inside a parameter list.

2022-05-23 Thread vit via Digitalmars-d-learn
On Monday, 23 May 2022 at 08:34:21 UTC, Chris Katko wrote: D struct pair { float x,y; } [...] This work too: ```d myFunction(taco, p.tupleof, burrito); ```

Re: Odd construct idea. Splitting arguments inside a parameter list.

2022-05-23 Thread Mike Parker via Digitalmars-d-learn
On Monday, 23 May 2022 at 08:34:21 UTC, Chris Katko wrote: D I'm curious if you can pass a struct of values (a 'tuple'?) with the right subfields, as if those fields occupied a function signature. (As I write this and try to explain it, it probably sounds impossible.) Right now you can

Odd construct idea. Splitting arguments inside a parameter list.

2022-05-23 Thread Chris Katko via Digitalmars-d-learn
D struct pair { float x,y; } myFunction(float taco, float x, float y, float burrito) { // stuff } myfunction(_taco, _x, _y, _burrito); // call function // But can we do this? pair p; myfunction(_taco, p; _burrito); // p becomes (x,y) and satisfies the two floats in the signature