Super-dee-duper D features

Sean Kelly sean at f4.ca
Mon Feb 12 10:06:15 PST 2007


Michiel wrote:
>> The C++ version is even *worse* than the C one (for wordiness bother):
>>
>>  for (std::vector<T>::const_iterator i = e.begin(); i != e.end(); i++)
>>  {  T v = *i;
>>  ... }
>>
>> I mean I know the reasons for every bit of the syntax there, and in
>> isolation they make sense, but put it all together and it seems to go
>> backwards.
> 
> Hehe, sure. But that's like the worst possible way to do it. :)
> 
> * Most people make the std namespace public. Or at least the std::vector part.

No, that's the worst possible way to do it :-)

> Of course, the D foreach loop is still much neater (and I love it). But only if
> you really want to visit all elements of an array in a row. However, if you want
> to walk through two AA's at the same time (comparing keys and values, for
> example), how do you do that in D? Maybe there is a way I haven't found yet (I've
> only been working with D for a few weeks), but it looks to me like much more
> bother than with C++ iterators.

For what it's worth (probably not much), C++ does have a for_each 
template.  The problem is that it doesn't accept arbitrary code like the 
D foreach does, which gave rise to Boost's lambda library.


Sean



More information about the Digitalmars-d mailing list