Re: How to mixin repeated text?

2018-08-27 Thread Kamil Koczurek via Digitalmars-d-learn
On Monday, 27 August 2018 at 11:52:02 UTC, Andrey wrote: Hello again, I have this part of code: ... if(index + 3 >= data.length || data[index + 1][0] == '&' || data[index + 2][0] == '&' || data[index + 3][0] == '&' || data[index + 4][0] == '&') { writeln("Some text..."); } I don't want

Re: weak_ptr alternative

2018-08-05 Thread Kamil Koczurek via Digitalmars-d-learn
On Sunday, 5 August 2018 at 20:57:32 UTC, aliak wrote: On Sunday, 5 August 2018 at 20:10:49 UTC, Kamil Koczurek wrote: Is there a way to keep track of objects without owning them? That is, could I have a smart pointer that behaves somewhat like this: WeakPtr!Class wptr = getSomeInstance();

weak_ptr alternative

2018-08-05 Thread Kamil Koczurek via Digitalmars-d-learn
Is there a way to keep track of objects without owning them? That is, could I have a smart pointer that behaves somewhat like this: WeakPtr!Class wptr = getSomeInstance(); auto obj = wptr.peek; //[1] if(obj !is null) { obj.stuff(); } [1]: If wptr points to something that is still reachable

Debugging compile time memory usage

2018-06-24 Thread Kamil Koczurek via Digitalmars-d-learn
I recently wrote a brainfuck compiler in D, which loads the BF source at compile time, performs some (simple) optimizations, translates everything to D and puts it into the source code with a mixin. I did manage to get some pretty good performance, but for some programs in brainfuck I have

Re: Implementing a tree with recursive Algebraic

2018-06-15 Thread Kamil Koczurek via Digitalmars-d-learn
On Friday, 15 June 2018 at 14:57:33 UTC, Adam D. Ruppe wrote: You can make the tree store a *pointer* to a tree though. That's the traditional way to do it and it works here too. Oh, alright. I changed Tree to be a class instead of a struct and it seems to work just fine now. Thanks a lot!

Implementing a tree with recursive Algebraic

2018-06-15 Thread Kamil Koczurek via Digitalmars-d-learn
Hi, I'm trying to implement a simple tree and this 3-liner was my initial idea: struct Tree(T) { Algebraic!(Tree, T)[] content; } But it doesn't work and I get the following error message: /.../variant.d(...): Error: struct `app.Tree` no size because of forward reference