Re: Is there an easy way to mimic generics with an accept method of a visitor pattern?

2021-02-18 Thread vitamin via Digitalmars-d-learn
On Thursday, 18 February 2021 at 15:11:44 UTC, Paul Backus wrote: On Thursday, 18 February 2021 at 14:51:09 UTC, vitamin wrote: On Thursday, 18 February 2021 at 14:43:43 UTC, Paul Backus wrote: I don't see what this buys you compared to sticking with one or the other, but you are correct that

Re: Is there an easy way to mimic generics with an accept method of a visitor pattern?

2021-02-18 Thread vitamin via Digitalmars-d-learn
On Thursday, 18 February 2021 at 14:43:43 UTC, Paul Backus wrote: On Thursday, 18 February 2021 at 14:26:37 UTC, vitamin wrote: Or combination of discriminate uninons and classes: /+dub.sdl: dependency "sumtype" version="~>0.10.0" +/ import std.stdio; import sumtype; alias Expression = SumTy

Re: Is there an easy way to mimic generics with an accept method of a visitor pattern?

2021-02-18 Thread vitamin via Digitalmars-d-learn
On Thursday, 18 February 2021 at 13:53:19 UTC, Paul Backus wrote: On Thursday, 18 February 2021 at 11:14:05 UTC, Mina wrote: I'm following along with the crafting interpreters book (https://craftinginterpreters.com) and it goes into implementing a visitor pattern that returns generic types, so

Re: Struct delegate access corruption

2021-02-18 Thread vitamin via Digitalmars-d-learn
On Thursday, 18 February 2021 at 08:29:48 UTC, kinke wrote: On Wednesday, 17 February 2021 at 20:44:46 UTC, tsbockman wrote: On Wednesday, 17 February 2021 at 20:18:53 UTC, Paul Backus wrote: [...] That bug is about postblits, this(this), not copy constructors: this(ref typeof(this)). Copy c

Re: GC.addRange in pure function

2021-02-12 Thread vitamin via Digitalmars-d-learn
On Wednesday, 10 February 2021 at 16:25:44 UTC, Petar Kirov [ZombineDev] wrote: On Wednesday, 10 February 2021 at 13:44:53 UTC, vit wrote: [...] TL;DR Yes, you can, but it depends on what "without problem" means for you :P [...] Thanks, Yes, I am implementing container (ref counted point

GC.addRange in pure function

2021-02-07 Thread vitamin via Digitalmars-d-learn
Why using 'new' is allowed in pure functions but calling GC.addRange or GC.removeRange isn't allowed?

GC.addRange multiple times

2021-02-03 Thread vitamin via Digitalmars-d-learn
Is it valid if I call GC.addRange with same or overlaping range? Example: https://run.dlang.io/is/a5a0Ag import core.memory; import std.experimental.allocator.mallocator; import core.lifetime; class Bar{ } struct Foo{ Bar bar; this(Bar bar){ this.bar = bar; } } void main

Re: core.atomic for ldc.

2021-01-31 Thread vitamin via Digitalmars-d-learn
On Monday, 1 February 2021 at 06:38:16 UTC, Basile B. wrote: On Monday, 1 February 2021 at 06:12:59 UTC, vitamin wrote: On Monday, 1 February 2021 at 05:23:52 UTC, rikki cattermole wrote: The only difference between dmd, ldc and gdc (in effect) is the backend. While druntime and Phobos will be

Re: core.atomic for ldc.

2021-01-31 Thread vitamin via Digitalmars-d-learn
On Monday, 1 February 2021 at 05:23:52 UTC, rikki cattermole wrote: The only difference between dmd, ldc and gdc (in effect) is the backend. While druntime and Phobos will be patched for other platform targets, over all its the same library. The same goes for core.atomic. You should not need t

Re: core.atomic for ldc.

2021-01-31 Thread vitamin via Digitalmars-d-learn
On Sunday, 31 January 2021 at 12:51:57 UTC, vitamin wrote: Exists for LDC library like core.atomic? It look like that dub compile with ldc but use dmd runtime and module core.internal.atomic has version only for dmd and gdc. How to make ldc use ldc runtime?

core.atomic for ldc.

2021-01-31 Thread vitamin via Digitalmars-d-learn
Exists for LDC library like core.atomic?

Re: Bit rotation question/challenge

2021-01-30 Thread vitamin via Digitalmars-d-learn
On Saturday, 30 January 2021 at 14:56:14 UTC, burt wrote: On Saturday, 30 January 2021 at 14:41:59 UTC, Afgdr wrote: On Saturday, 30 January 2021 at 14:40:49 UTC, Afgdr wrote: On Saturday, 30 January 2021 at 13:30:49 UTC, burt wrote: [...] cast as uint and shift. cast the result as ubyte[4].

Re: emplace doesn't forward aeguments

2021-01-30 Thread vitamin via Digitalmars-d-learn
On Thursday, 28 January 2021 at 23:18:21 UTC, kinke wrote: On Thursday, 28 January 2021 at 21:15:49 UTC, vitamin wrote: Is there reason why std.conv.emplace doesn't forward arguments to __ctor? Yeah, a bug in the emplace() version for classes, some missing `forward!args` in there (it works wh

emplace doesn't forward aeguments

2021-01-28 Thread vitamin via Digitalmars-d-learn
Is there reason why std.conv.emplace doesn't forward arguments to __ctor? this doesn't work: import std.conv : emplace; import std.functional : forward; struct Bar{ @disable this(const ref typeof(this) rhs)pure nothrow @safe @nogc; } class Foo{ Bar bar; this(Bar bar){

Re: Can I set the base class like this?

2021-01-26 Thread vitamin via Digitalmars-d-learn
On Tuesday, 26 January 2021 at 04:39:07 UTC, Jack wrote: Can I pass the base class type thought template parameter? something like this: [...] You have it almost right: class C(alias T) // Template is not type but symbol.

Re: F*cked by memory corruption after assiging value to associative array

2021-01-25 Thread vitamin via Digitalmars-d-learn
On Monday, 25 January 2021 at 16:44:40 UTC, frame wrote: On Monday, 25 January 2021 at 16:14:05 UTC, vitamin wrote: [...] Yes with simple new operator. Forgot to mention: the DLL itself calls a DLL. [...] If there are separated GCs for DLLs, then you must call GC.addRoot() from DLL where

Re: std.expreimantal.allocator deallocate

2021-01-25 Thread vitamin via Digitalmars-d-learn
On Monday, 25 January 2021 at 10:28:11 UTC, Jacob Carlborg wrote: On Sunday, 24 January 2021 at 11:00:17 UTC, vitamin wrote: void destruct(Base base){ void[] x = (cast(void*)base)[0 .. __traits(classInstanceSize, Base)]; writeln("deallocate: ", x.length); theAllocator.deallocate(x

Re: F*cked by memory corruption after assiging value to associative array

2021-01-25 Thread vitamin via Digitalmars-d-learn
On Monday, 25 January 2021 at 15:46:15 UTC, frame wrote: On Monday, 25 January 2021 at 14:34:23 UTC, vitamin wrote: Is the object returned from dll GC allocated? The object is created on the default way. No alternating allocation. Before the object is returned it's added to GC.addRoot() whi

Re: F*cked by memory corruption after assiging value to associative array

2021-01-25 Thread vitamin via Digitalmars-d-learn
On Monday, 25 January 2021 at 13:44:52 UTC, frame wrote: On Monday, 25 January 2021 at 11:25:56 UTC, FeepingCreature wrote: I suspect the memory used by the original data got reused for the associative array somehow. But if the GC is off from program start, that should really not occur. Do yo

Re: std.expreimantal.allocator deallocate

2021-01-25 Thread vitamin via Digitalmars-d-learn
On Sunday, 24 January 2021 at 18:38:42 UTC, Petar Kirov [ZombineDev] wrote: On Sunday, 24 January 2021 at 14:56:25 UTC, Paul Backus wrote: [...] To add to that, if an allocator defines `resolveInternalPointer` [0][1] you could be able to get the original slice that was allocated (and then pa

Re: std.expreimantal.allocator deallocate

2021-01-24 Thread vitamin via Digitalmars-d-learn
On Sunday, 24 January 2021 at 14:56:25 UTC, Paul Backus wrote: On Sunday, 24 January 2021 at 11:00:17 UTC, vitamin wrote: It is Ok when I call deallocate with smaller slice or I need track exact lengtht? It depends on the specific allocator, but in general, it is only guaranteed to work corre

std.expreimantal.allocator deallocate

2021-01-24 Thread vitamin via Digitalmars-d-learn
Allocators from std.expreimantal.allocator allocate memory and return slice void[] to allocated memory. Method deallocate has as parameter void[] slice to allocated memory. It is Ok when I call deallocate with smaller slice or I need track exact lengtht? Example: import std.experimental.allo

Re: foreach, RefCounted and non-copyable range

2021-01-18 Thread vitamin via Digitalmars-d-learn
On Sunday, 17 January 2021 at 12:15:00 UTC, Fynn Schröder wrote: I'm puzzled why RefCounted and foreach do not work well together, i.e.: ``` auto range = refCounted(nonCopyableRange); // ok foreach(e; range) // Error: struct is not copyable because it is annotated with @disable // do some

struct constructor with rvalue param of same struct type

2021-01-18 Thread vitamin via Digitalmars-d-learn
Hello, is it possible to create constructor which initialize 'ptr3' with const rvalue of same type? struct Foo{} static struct Ptr{ void* impl; //ctor 1 this(ref const typeof(this) x)pure nothrow @trusted @nogc{/*...*/} //ctor 2 this(const Foo foo)pure nothrow @trusted @

Re: scope front vs [0]

2020-11-11 Thread vitamin via Digitalmars-d-learn
Or similar problem: class Foo{} struct Slice{ Foo[] data; this(return scope Foo[] data)@safe { this.data = data; } Slice opSlice()@safe return scope{ return Slice(data); } Foo opIndex(size_t i)@safe return scope{ return data[i]; } } void main

scope front vs [0]

2020-11-11 Thread vitamin via Digitalmars-d-learn
Hello, Why does expression 'foo = bars[][0].foo' work but 'foo = bars[].front.foo' doesn't? example: class Foo{} struct Bar{ Foo foo; } void main()@safe{ import std; Foo foo; scope Bar[] bars = [Bar.init]; foo = bars[][0].foo;//OK, WHY? foo