Visual Studio 2010 CTP with C++0x feature subset released

October 28, 2008 by Tor Brede Vekterli

Microsoft just released a Community Technology Preview (CTP) version of Visual Studio 2010. Of particular interest is the inclusion of a subset of the C++0x spec. (update: now with a massive rvalue reference article) As it turns out, it is a very juicy subset!

Update 23. Oct 2009: My, how time flies! Visual Studio 2010 Beta 2 has been released, adding support for nullptr amongst many bug fixes.

There are four C++0x features that are officially supported in the preview:

  • Lambda expressions! Anonymous functions are finally here! Check out the linked article for the details, because this is some of the most exciting stuff to hit C++ in a long time.
  • Rvalue references, i.e. temporary rvalues can be non-const and thus modified, allowing for move semantics. Returning eg. a std::vector by value from a function would normally incur an allocate-and-copy overhead (given that no return value optimizations are present), but with move semantics the receiving vector in the caller can simply "take over" the buffer pointer (since it knows the source vector is only temporary), leaving the temporary vector empty and reducing the whole operation internally to a couple of std::swaps. Needless to say, this can drastically cut down on temporary allocations and copies, and simply recompiling your code with a C++0x conformant compiler and standard library implementation should theoretically give performance benefits "for free".
  • static_assert. Those of you using Boost (which is hopefully most of you) should already be familiar with the BOOST_STATIC_ASSERT macro, which allows for compile-time assertion checking (as opposed to the standard runtime assert(condition) macro). This simply moves support for this into the compiler itself, also allowing for the inclusion of much welcome descriptive error strings.
  • auto keyword. Anyone who has dealt or regularly deals with template metaprogramming knows that types can get unwieldy fast, and having to explicitly state eg. the type of an expression template when that type's definition spans 10 lines of text is not much fun at all. Luckily, auto is here to save the day, and automatically deduces the type to that of its right-hand side.

The CTP is contained in a Virtual PC 2007 image, compressed to ~7GiB and split over 11 files, and seems like an excellent choice to get some hands-on experience with some of the things that C++0x will offer in the (hopefully near) future!

Update 29-10-2008: Got the chance to play around a little with this thing. Haven't tried much out yet, but the following works like a charm:

std::vector<int> v;

auto lambda = [](int i){ std::cout << i << "\n"; };

std::for_each(v.begin(), v.end(), lambda);

And so does this

[]{[]{[]{[]{[]{[]{ std::cout << "let me out!!"; }();}();}();}();}();}();


Grouchy Old Fartâ„¢ on October 30, 2008

you're still a nerd. :p

also i will argue that the type of an expression template when that type's definition spans 10 lines of text is pretty fun and you're just jealous!! god.

Tor Brede Vekterli on October 30, 2008

This can only be settled by the one true ancient programmer tradition:

Rap-battle at dawn!

Brian Jones on February 14, 2009

Initializer lists for stl containers aren't supported in vs10?

Tor Brede Vekterli on February 14, 2009

According to the post by the VC++ dev team's Jonathan Caves on it would appear that initializer lists, alongside most other C++0x features, will unfortunately not be included in VS2010 (unless something changes between now and the launch).

Personally I was really hoping for variadic template support in VC++, but for experimenting with that there's always GCC with its -std=c++0x flag. No init list support there either yet, though..

BHW on April 14, 2017

I just like the valuable information you provide in your articles.
I will bookmark your weblog and take a look at once more right here frequently.
I am somewhat certain I will be informed a lot of new stuff right right here!

Good luck for the next!

BHW on April 14, 2017

When I initially commented I seem to have clicked on the -Notify
me when new comments are added- checkbox and from now on every time a comment is
added I get 4 emails with the exact same comment.

Perhaps there is a means you are able to remove me from
that service? Appreciate it!

Loving the information on this website, you have done great job on the posts.

Post a comment