C++/ D C struct2 D inner classes, C++ templates/D templates

Bill Baxter dnewsgroup at billbaxter.com
Thu Jul 26 16:36:33 PDT 2007


BLS wrote:
> Hi Chris,
> MANY THANKS.
> Your help is kicking me into the right direction.
> 

> In case that you have time enough:  Here the /templated/ B+Tree Cpp 
> implementation. 
> http://idlebox.net/2007/stx-btree/stx-btree-0.8/include/stx/btree.h.html
> 
> Read it ? Do you see something not doable in D ?
> again, thanks for beeing so gentle and patient
> Bjoern


The tricky thing, as with all STL-type C++, is translating the 
iterators.  The STL standard technique for iterators is to overload 
operator* and operator->, which you can't do in D.  So you need to use 
methods or something for those instead.  Something like iter.value or 
iter.deref or iter.data, etc.  Also there's a lot of passing of 
references here and there in STL code like that.  That's always kinda 
tricky to figure out what to do with.  Are you doing this with D2 or D 
classic?

One issue I ran into trying to translate std::map was the use of the 
idiom   T(val) or T x(val)  to construct objects.  In C++ that works 
fine whether T is an 'int', a class, or a struct.  But in D (AFAIK) 
there's no single expression that can be used to construct either a 
plain value type or a class type with the given initializer.  I didn't 
really think about it too hard though.  I decided it was easier to grab 
ArcLib's RedBlackTree implementation and use that.

--bb


More information about the Digitalmars-d-learn mailing list