Re: Is it possible to return the subclass from a method of the parent class in dlang?

2018-03-02 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Mar 03, 2018 at 01:13:43AM +0100, Christian Köstlin via Digitalmars-d-learn wrote: > >> class Timer : Thread { > >>    override Timer start() { ... } > >> } > >> > >> https://dlang.org/spec/function.html#virtual-functions > >> > >> (see item 6) > >> > >> -Steve > > Thanks for this. > > It

Re: Is it possible to return the subclass from a method of the parent class in dlang?

2018-03-02 Thread Christian Köstlin via Digitalmars-d-learn
>> class Timer : Thread { >>    override Timer start() { ... } >> } >> >> https://dlang.org/spec/function.html#virtual-functions >> >> (see item 6) >> >> -Steve > Thanks for this. > It works for me only without the override (with override I get > Error: function timer.Timer.start does not override

Re: Is it possible to return the subclass from a method of the parent class in dlang?

2018-03-02 Thread Christian Köstlin via Digitalmars-d-learn
On 02.03.18 21:39, Steven Schveighoffer wrote: > On 3/2/18 3:23 PM, Christian Köstlin wrote: >> To give an example: >> >> class Thread { >>    ... >>    Thread start() {...} >> } >> >> class Timer : Thread { >>    ... >> } >> >> >> void main() { >>    // Timer timer = new Timer().start;  // this

Re: Validity of cast(void*)size_t.max

2018-03-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/2/18 3:26 PM, Nordlöw wrote: On Wednesday, 28 February 2018 at 20:07:50 UTC, Steven Schveighoffer wrote: auto x = cast(Object)((cast(size_t *)null) + 1); Is this preferred performance-wise over `cast(void*)(size_t.max)`? No, it just works, as opposed to, um... not working ;) I think

Re: Is it possible to return the subclass from a method of the parent class in dlang?

2018-03-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/2/18 3:23 PM, Christian Köstlin wrote: To give an example: class Thread { ... Thread start() {...} } class Timer : Thread { ... } void main() { // Timer timer = new Timer().start; // this does not work auto timer = new Timer().start; // because timer is of type Thread }

Re: Validity of cast(void*)size_t.max

2018-03-02 Thread Nordlöw via Digitalmars-d-learn
On Wednesday, 28 February 2018 at 20:07:50 UTC, Steven Schveighoffer wrote: auto x = cast(Object)((cast(size_t *)null) + 1); Is this preferred performance-wise over `cast(void*)(size_t.max)`?

Is it possible to return the subclass from a method of the parent class in dlang?

2018-03-02 Thread Christian Köstlin via Digitalmars-d-learn
To give an example: class Thread { ... Thread start() {...} } class Timer : Thread { ... } void main() { // Timer timer = new Timer().start; // this does not work auto timer = new Timer().start; // because timer is of type Thread } thanks in advance, christian

Re: Spawning a process: Can I "have my cake and eat it too"?

2018-03-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/2/18 9:23 AM, Steven Schveighoffer wrote: On 3/1/18 11:50 PM, Nick Sabalausky (Abscissa) wrote: How could this be accomplished? Is it even possible? You'd have to do this in the parent. You can duplicate the file descriptor, so that writing to either goes to the same spot, but you

Re: Spawning a process: Can I "have my cake and eat it too"?

2018-03-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/1/18 11:50 PM, Nick Sabalausky (Abscissa) wrote: I'd like to include this functionality in Scriptlike, but I don't know if it's even possible: Launch a process (spawnProcess, pipeShell, etc) so the child's stdout/stderr go to the parent's stdout/stderr *without* the possibility of them

Re: Assigning to slice of array

2018-03-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/1/18 5:59 PM, ag0aep6g wrote: On 03/01/2018 11:43 PM, Jamie wrote: So if I do arr[0 .. 1][0] = 3; shouldn't this return [[3, 0, 0], [0, 0, 0]] ? Because I'm taking the slice arr[0 .. 1], or arr[0], which is the first [0, 0, 0]? arr[0 .. 1] is not the same as arr[0]. arr[0 ..

Re: Postblit constructor

2018-03-02 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 28 February 2018 at 18:23:04 UTC, Jiyan wrote: The nodes are only allocated over malloc(). So i have to take care of the initialisation myself. The problem is, that i found out by debugging, that it seems that when i call val.opAssign(op) in constructNodeFrom(), there isn't any

Re: Unexpected behaviour of foreach statement

2018-03-02 Thread Arredondo via Digitalmars-d-learn
On Friday, 2 March 2018 at 10:32:08 UTC, Jonathan M Davis wrote: foreach does not support indices for ranges, only arrays. When you have foreach(e; range) it gets lowered to foreach(auto __range = range; !__range.empty; __range.popFront()) { auto e = __range.front; } There are no

Re: Unexpected behaviour of foreach statement

2018-03-02 Thread Arredondo via Digitalmars-d-learn
On Friday, 2 March 2018 at 10:34:31 UTC, bauss wrote: You can also call "array" from "std.array". auto range = iota(5).array; foreach (i, el; range) { writeln(i, ": ", el); } Thank you. That's how I had it in my original code, I was just trying to avoid gratuitous memory

Re: Postblit constructor

2018-03-02 Thread Eduard Staniloiu via Digitalmars-d-learn
On Wednesday, 28 February 2018 at 18:27:49 UTC, Jiyan wrote: On Wednesday, 28 February 2018 at 18:23:04 UTC, Jiyan wrote: Hey, i thought i had understood postblit, but in my Code the following is happening (simplified): struct C { this(this){/*Do sth*/} list!C; void opAssign(const C c) {

Re: Unexpected behaviour of foreach statement

2018-03-02 Thread Arredondo via Digitalmars-d-learn
On Friday, 2 March 2018 at 10:27:27 UTC, Nicholas Wilson wrote: try https://dlang.org/phobos/std_range.html#enumerate This worked. Thank you!

Re: how to install latest lcd2 for armbain

2018-03-02 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 2 March 2018 at 08:25:51 UTC, dangbinghoo wrote: So, does anyone know how to install latest ldc2 from arm-debain? You can use the dlang install.sh script to download LDC and put it in your home dir: https://dlang.org/install.html -Johan

Re: Unexpected behaviour of foreach statement

2018-03-02 Thread bauss via Digitalmars-d-learn
On Friday, 2 March 2018 at 10:21:39 UTC, Arredondo wrote: Hi, The following works as expected: auto range = [1, 2, 3, 4, 5]; foreach (i, el; range) { writeln(i, ": ", el); } but this slight modification doesn't: auto range = iota(5); foreach (i, el; range) { writeln(i, ": ",

Re: Unexpected behaviour of foreach statement

2018-03-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, March 02, 2018 10:21:39 Arredondo via Digitalmars-d-learn wrote: > Hi, > > The following works as expected: > > auto range = [1, 2, 3, 4, 5]; > foreach (i, el; range) { > writeln(i, ": ", el); > } > > but this slight modification doesn't: > > auto range = iota(5); > foreach (i, el;

Re: Unexpected behaviour of foreach statement

2018-03-02 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 2 March 2018 at 10:21:39 UTC, Arredondo wrote: Hi, The following works as expected: auto range = [1, 2, 3, 4, 5]; foreach (i, el; range) { writeln(i, ": ", el); } but this slight modification doesn't: auto range = iota(5); foreach (i, el; range) { writeln(i, ": ",

Unexpected behaviour of foreach statement

2018-03-02 Thread Arredondo via Digitalmars-d-learn
Hi, The following works as expected: auto range = [1, 2, 3, 4, 5]; foreach (i, el; range) { writeln(i, ": ", el); } but this slight modification doesn't: auto range = iota(5); foreach (i, el; range) { writeln(i, ": ", el); } DMD 2.078.3 says: Error: cannot infer argument

Re: Unexpected behaviour of foreach statement

2018-03-02 Thread rikki cattermole via Digitalmars-d-learn
On 02/03/2018 11:21 PM, Arredondo wrote: Hi, The following works as expected: auto range = [1, 2, 3, 4, 5]; foreach (i, el; range) { writeln(i, ": ", el); } s/range/array/ Arrays have a different foreach syntax than ranges do.

Re: single loop copy in D

2018-03-02 Thread psychoticRabbit via Digitalmars-d-learn
On Friday, 2 March 2018 at 10:08:57 UTC, Simen Kjærås wrote: This is of course only partly true. while ((*dst++ = *src++) != 0) {} works just great, and also better shows what's actually being tested for in the loop. -- Simen That's what I was after. Thanks!

Re: single loop copy in D

2018-03-02 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 2 March 2018 at 10:01:34 UTC, Jonathan M Davis wrote: On Friday, March 02, 2018 09:44:20 psychoticRabbit via Digitalmars-d-learn wrote: trying to do this C code, in D, but getting error: "Error: assignment cannot be used as a condition, perhaps `==` was meant?" any help much

Re: single loop copy in D

2018-03-02 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 2 March 2018 at 09:44:20 UTC, psychoticRabbit wrote: trying to do this C code, in D, but getting error: "Error: assignment cannot be used as a condition, perhaps `==` was meant?" any help much appreciated: -- while ((*dst++ = *src++)) {} -- You can't use this syntax

Re: single loop copy in D

2018-03-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, March 02, 2018 09:44:20 psychoticRabbit via Digitalmars-d-learn wrote: > trying to do this C code, in D, but getting error: > "Error: assignment cannot be used as a condition, perhaps `==` > was meant?" > > any help much appreciated: > > -- > while ((*dst++ = *src++)) {} > --

single loop copy in D

2018-03-02 Thread psychoticRabbit via Digitalmars-d-learn
trying to do this C code, in D, but getting error: "Error: assignment cannot be used as a condition, perhaps `==` was meant?" any help much appreciated: -- while ((*dst++ = *src++)) {} --

Re: Garbage collected pointers?

2018-03-02 Thread Gary Willoughby via Digitalmars-d-learn
On Friday, 2 March 2018 at 08:44:53 UTC, Gary Willoughby wrote: It would be interesting to test whether those methods handle these scenarios. Yeah, it doesn't work. https://dpaste.dzfl.pl/55116efd0c9c

Re: Garbage collected pointers?

2018-03-02 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 1 March 2018 at 12:20:08 UTC, Steven Schveighoffer wrote: On 3/1/18 7:05 AM, Gary Willoughby wrote: On Thursday, 1 March 2018 at 10:10:27 UTC, John Burton wrote: My question is how do I tell if a pointer is "garbage collected" or not? You could try `GC.addrOf()` or `GC.query()`

how to install latest lcd2 for armbain

2018-03-02 Thread dangbinghoo via Digitalmars-d-learn
hi there, I just flased a armbain for nanoPi M3. And, I just installed ldc2-1.2.0 armhf using apt-get. it compiles d code with combination with gcc armhf and compiled program runs great even the arch is aarch64. But I realized that ldc2 is too old, I know that latest ldc2 is 1.8.0. So,