Re: Class qualifier vs struct qualifier

2018-06-14 Thread RazvanN via Digitalmars-d-learn
Honestly, from what I understand of how this works, what I find weird is the struct case. immutable on classes does _not_ make the class itself immutable. It just makes all of its members immutable - hence the error about trying to allocate new Foo instead of new immutable Foo. So, that is exac

Re: Static Array Idiom not working anymore.

2018-06-14 Thread Guillaume Piolat via Digitalmars-d-learn
On Tuesday, 12 June 2018 at 15:35:42 UTC, Steven Schveighoffer wrote: No, that's not what I mean. What I mean is: int[] arr = [1,2,3].s; int[] arr2 = [4,5,6].s; Legally, the compiler is allowed to reuse the stack memory allocated for arr for arr2. The lifetime of the arr data is over. -Ste

foreach DFS/BFS for tree data-structure?

2018-06-14 Thread Robert M. Münch via Digitalmars-d-learn
I have a simple tree C data-structure that looks like this: node { node parent: vector[node] children; } I would like to create two foreach algorthims, one follwing the breadth first search pattern and one the depth first search pattern. Is this possible? I read about Inputran

Re: foreach DFS/BFS for tree data-structure?

2018-06-14 Thread rikki cattermole via Digitalmars-d-learn
On 14/06/2018 11:31 PM, Robert M. Münch wrote: I have a simple tree C data-structure that looks like this: node { struct Node { node parent: Node* parent; vector[node] children; Node[] children; } I would like to create two foreach algorthims, one follwing the breadth fir

Re: foreach DFS/BFS for tree data-structure?

2018-06-14 Thread Dennis via Digitalmars-d-learn
On Thursday, 14 June 2018 at 11:31:50 UTC, Robert M. Münch wrote: Is this possible? I read about Inputranges, took a look at the RBTree code etc. but don't relly know/understand where to start. You can also use opApply to iterate over a tree using foreach, see: https://tour.dlang.org/tour/en/

Re: foreach DFS/BFS for tree data-structure?

2018-06-14 Thread Robert M. Münch via Digitalmars-d-learn
On 2018-06-14 11:46:04 +, Dennis said: On Thursday, 14 June 2018 at 11:31:50 UTC, Robert M. Münch wrote: Is this possible? I read about Inputranges, took a look at the RBTree code etc. but don't relly know/understand where to start. You can also use opApply to iterate over a tree using fo

Re: Static Array Idiom not working anymore.

2018-06-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/14/18 7:07 AM, Guillaume Piolat wrote: On Tuesday, 12 June 2018 at 15:35:42 UTC, Steven Schveighoffer wrote: No, that's not what I mean. What I mean is: int[] arr = [1,2,3].s; int[] arr2 = [4,5,6].s; Legally, the compiler is allowed to reuse the stack memory allocated for arr for arr2.

Re: foreach DFS/BFS for tree data-structure?

2018-06-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/14/18 8:35 AM, Robert M. Münch wrote: On 2018-06-14 11:46:04 +, Dennis said: On Thursday, 14 June 2018 at 11:31:50 UTC, Robert M. Münch wrote: Is this possible? I read about Inputranges, took a look at the RBTree code etc. but don't relly know/understand where to start. You can also

Re: foreach DFS/BFS for tree data-structure?

2018-06-14 Thread Meta via Digitalmars-d-learn
On Thursday, 14 June 2018 at 11:31:50 UTC, Robert M. Münch wrote: I have a simple tree C data-structure that looks like this: node { node parent: vector[node] children; } I would like to create two foreach algorthims, one follwing the breadth first search pattern and one the de

Re: Class qualifier vs struct qualifier

2018-06-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, June 14, 2018 08:39:48 RazvanN via Digitalmars-d-learn wrote: > > Honestly, from what I understand of how this works, what I find > > weird is the struct case. immutable on classes does _not_ make > > the class itself immutable. It just makes all of its members > > immutable - hence th

Re: Static Array Idiom not working anymore.

2018-06-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, June 14, 2018 08:40:10 Steven Schveighoffer via Digitalmars-d- learn wrote: > On 6/14/18 7:07 AM, Guillaume Piolat wrote: > > On Tuesday, 12 June 2018 at 15:35:42 UTC, Steven Schveighoffer wrote: > >> No, that's not what I mean. What I mean is: > >> > >> int[] arr = [1,2,3].s; > >> int

Re: What is the point of nothrow?

2018-06-14 Thread wjoe via Digitalmars-d-learn
On Wednesday, 13 June 2018 at 20:08:06 UTC, Jonathan M Davis wrote: On Wednesday, June 13, 2018 10:56:41 wjoe via Digitalmars-d-learn wrote: On Wednesday, 13 June 2018 at 03:14:33 UTC, Jonathan M Davis > regardless of whether the decision to treat failed memory > allocations as an Error was a g

Re: What is the point of nothrow?

2018-06-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, June 14, 2018 18:11:20 wjoe via Digitalmars-d-learn wrote: > On Wednesday, 13 June 2018 at 20:08:06 UTC, Jonathan M Davis > wrote: > > On Wednesday, June 13, 2018 10:56:41 wjoe via > > The idea is that because your program is in an invalid state, > > attempting a graceful shutdown is u

Create an Algebraic type at compile time and more

2018-06-14 Thread uknys via Digitalmars-d-learn
Hello, I wanted to know if such code was possible : alias Operation = Algebraic!(/* All type that implements X UDA */) struct X { int opcode; Operation h; } @X(0x01, Hello(3)) @X(0x02, Hello(4)) struct Hello { int Hello; } @X(0x03, Toto(5)) @X(0x05, Toto(6)) struct Toto { int A

Re: What is the point of nothrow?

2018-06-14 Thread bauss via Digitalmars-d-learn
On Thursday, 14 June 2018 at 19:06:07 UTC, Jonathan M Davis wrote: As I said, personally, I think that the program shut just print and terminate rather than throwing an Error. Walter seems to It makes perfectly sense for it to throw an error and not just print and terminate. This is especial

Re: Class qualifier vs struct qualifier

2018-06-14 Thread David Bennett via Digitalmars-d-learn
On Wednesday, 13 June 2018 at 07:35:25 UTC, RazvanN wrote: Hello, I'm having a hard time understanding whether this inconsistency is a bug or intended behavior: immutable class Foo {} immutable struct Bar {} void main() { import std.stdio : writeln; Foo a; Bar b; writeln("ty