Stroustrup talks on V-Next of C++. Do they apply to C#?
For a long time I am out of touch with the C++ world. Amit pointed me to the paper A Brief Look at C++0x which talks about C++0x scheduled to be released in 2009. I loved some of the new features. Some of the changes proposed in C++ brings it closer to C#. Here is a run down with some comparisons with how the new C++ features match up with C#
- You can now use something like template<class T> using Vec = vector<T,My_alloc<T>>;
So aliasing is now supported using the keyword using :). I always had some doubt regarding the benefits of having typedef in C# and now we see C++ extending on it as well. I think I'll post later on why C# does not support typedefs and weird things people do to get around it.... - In the same snippet as above there is a subtle change. I had blogged about it before. You no longer need to have an extra space in between the two >> in nested template definitions as was required before. As I said C++ is getting closer to C#
- The next one is cool. You can now do Vec<double> v = { 2.3, 1.2, 6.7, 4.5 };
So you have collection initializers in C++ as well. C# has this too in its next version (3.0). I blogged about this some time back. Combined with object initializers C# is going to be much more powerfull in this. - Introduction of Concepts. Concept is the type of a type. Using this you can specify what properties a type should have. It is something similar to the generics where clause in C#. The difference is that concepts in C++ is much more powerful than C# since it is not class hierarchy based. However, both use the where clause. Currently Boost libraries have an implementation for this. Read more about it here.
- And you have the dreaded implicit type. In C# you call it var and in C++ auto. In a expression like
for (auto p = v.begin(); p!=v.end(); ++p)
cout << *p << endl;
The type of p is inferred from the return type of v.begin().
Interestingly as Stroustroupe himself says all the new features are targeted for generics development. This is very close to the C#2.0 release which had a huge number of changes targetted for generics.