www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

digitalmars.D.dtl - tree node mixin template

↑ ↓ ← "Andrew Fedoniouk" <news terrainformatica.com> writes:
(ATTN:not tested heavily)

If somebody wants to implement tree alike structure then this (on the clip) 
will help

Beside other features it has three opApply "enumerators":

Node parent = ...;

foreach(Node n; parent.forward) // all children from first to last
foreach(Node n; parent.backward) // all children from last to first
foreach(Node n; parent.deep) // all descendants - children and their 
children

Hope it will be useful.

Andrew Fedoniouk.
http://terrainformatica.com
Mar 12 2005
↑ ↓ Ben Hinkle <Ben_member pathlink.com> writes:
In article <d10nld$1e58$1 digitaldaemon.com>, Andrew Fedoniouk says...
(ATTN:not tested heavily)

If somebody wants to implement tree alike structure then this (on the clip) 
will help

Beside other features it has three opApply "enumerators":

Node parent = ...;

foreach(Node n; parent.forward) // all children from first to last
foreach(Node n; parent.backward) // all children from last to first
foreach(Node n; parent.deep) // all descendants - children and their 
children

Hope it will be useful.

Very nice! I like the nested struct mixin for the custom foreach, too. I think I'll borrow that idea for MinTL (which currently has the structs at the top level).
Mar 13 2005
↑ ↓ → "Andrew Fedoniouk" <news terrainformatica.com> writes:
Yep. That was my initial test drive of mixins.
They are useful indeed.
Assigning names to the "inclusion points" is extremely nice.

"custom foreach" : if I understand Walter idea about structs clearly
then they should work as fast as "plain foreach".

Having defined "forward foreach" I am implicitly defining
visiting order. As far as I can see from D definition
there is no order specified in foreach implementations for
standard collections.

Andrew.


"Ben Hinkle" <Ben_member pathlink.com> wrote in message 
news:d11rlq$2gss$1 digitaldaemon.com...
 In article <d10nld$1e58$1 digitaldaemon.com>, Andrew Fedoniouk says...
(ATTN:not tested heavily)

If somebody wants to implement tree alike structure then this (on the 
clip)
will help

Beside other features it has three opApply "enumerators":

Node parent = ...;

foreach(Node n; parent.forward) // all children from first to last
foreach(Node n; parent.backward) // all children from last to first
foreach(Node n; parent.deep) // all descendants - children and their
children

Hope it will be useful.

Very nice! I like the nested struct mixin for the custom foreach, too. I think I'll borrow that idea for MinTL (which currently has the structs at the top level).

Mar 13 2005