For example, C++:
std::vector<MyCoolType*> myVec;
myVec.push_back(new MyCoolType);
for(std::vector<MyCoolType*>::const_iterator i = myVec.begin(); i != myVec.end(); ++i)
(**i).print();
Versus D:
MyCoolType[] myVec;
myVec ~= new MyCoolType
foreach(i; myVec)
i.print();
First, the differences:
- Every class reference is automatically a pointer (MyCoolType[], not MyCoolType*[])
- Binary operator~ is used for vector concatenation (an object is promoted to a vector of size 1)
- Pointers to structures can use '.' It's obvious that the pointer needs to be dereferenced.
- "foreach" allows automatic const iteration. There is "foreach(ref i; myVec)" for non-const.
I have become inoculated to these problems, partly because the Visual C++ IDE makes it easier (with auto complete). D makes it possible to be productive in Vi again... (not every machine has VStudio)
No comments:
Post a Comment