- Overview
-
Table of Contents
- Special Member Functions: Constructors, Destructors, and the Assignment Operator
- Operator Overloading
- Memory Management
- Templates
- Namespaces
- Time and Date Library
- Streams
- Object-Oriented Programming and Design Principles
- The Standard Template Library (STL) and Generic Programming
- Exception Handling
- Runtime Type Information (RTTI)
- Signal Processing
- Creating Persistent Objects
- Bit Fields
- New Cast Operators
- Environment Variables
- Variadic Functions
- Pointers to Functions
- Function Objects
- Pointers to Members
- Lock Files
- Design Patterns
- Dynamic Linking
- Tips and Techniques
- Five Things You Need to Know About C++11 Unions
- A Tour of C99
- A Tour of C1X
- C++0X: The New Face of Standard C++
- C++0x Concurrency
-
The Reflecting Circle
- The Future of Programming
- Characters & Strings, Part I
- Characters & Strings, Part II
- Predictions for 2005
- My Ten Favorite C++ Books, Part I
- My Ten Favorite C++ Books, Part 2
- Aspect Oriented Programming
- 64-Bit Technology: Is It Greek To You?
- Agile Methodologies
- Agile Methodologies, Part 2
- Disaster Recovery, Part I
- Disaster Recovery, Part II
- Predictions for 2006
- Reflections on the delete vs. delete[ ] Split
- Predictions for 2007
- Bubble 2.0, Part I
- Bubble 2.0, Part II
- Time for a New new?
- Time for a New new? Part 2
- Are Variables Objects?
- Green Computing
- -> Whither?
- -> Whither? Part II
- Predictions for 2018, Part I
- Predictions for 2018, Part II
- Inventing New Operators
- Predictions for 2009, Part I
- Predictions for 2009, Part II
- Improved Integration with C Arrays and Strings
- Cloud Computing
- Google's Chrome OS -- Is It Really That Good?
- This Has Been 2009
- A Closer Look at bada
- A Second Look at bada
- A Quick Glance at Objective-C
- The C++0x Standardization Process -- Aiming for an FCD?
- The HipHop for PHP Project
- The HipHop Project FAQ
- Follow Me on Twitter
- C++0x Support in Visual Studio 2010
- The Buzzword Hype Dispelling Guide, Part I: Artificial Intelligence
- The Buzzword Hype Dispelling Guide, Part II: Fuzzy Logic
- The Buzzword Hype Dispelling Guide, Part III: Real-Time
- More on Real-Time Programming
- Black Swans and Gray Swans
- Reflections on <tt>new</tt>
- Reflections on <tt>new</tt>, Part II
- Reflections on <tt>new</tt>, Part III
- C++0x Features That I Like: Defaulted and Deleted Functions
- C++0x Features That I Like: Class Members Initializers
- Invention Wish-List for 2011 and Beyond, Part I
- Invention Wish-List for 2011 and Beyond, Part II
- Doing Less with More, Part I
- Doing Less with More, Part II
- Five Technology Myths and Their Lessons
- A Few Pedagogical Insights about C++ Teaching: Constructors and Destructors
- A Few Pedagogical Insights about C++ Teaching: Public Data Members
- When Bad Code Is Good for You
- Speaking Correct C++
- C++ is Back with a Vengeance
- Can Two Functions Have the Same Address?
- In Memory of Dennis Ritchie
- In Memory of Dennis Ritchie, Part II
- In Memory of Dennis Ritchie, Part III
- Time to Say Goodbye
- We Have Mail
- The Soapbox
- Numeric Types and Arithmetic
- Careers
- Locales and Internationalization
C++0x Support in Visual Studio 2010
Last updated Jan 1, 2003.
Microsoft's Visual Studio is the most popular C++ IDE among Windows C++ developers. Such popularity enables the C++ community to get valuable feedback from independent developers about new features. In the following sections I will outline the major new C++0x features that VS 2010 currently supports.
Core and Library features
The Visual C++ compiler that's embedded in the VS development suit supports six new C++0x features: lambda expressions, auto, decltype rvalue references, static_assert, and nullptr. Additionally, the Standard Library includes several C++0x enhancements such as new algorithms and better support for move semantics. With respect to performance, Microsoft reports that the Visual C++ compiler generates more efficient code and that the linker has also been improved in several aspects. However, I will focus here mostly on the new C++0x features.
Lambda Expressions
Microsoft is among the first vendors to support this feature. Truth be told, I have mixed emotions about lambda expressions. They are simpler to code than handwriting full-blown function objects. However, C++0x lambdas aren't polymorphic and I suspect that they will be over-used (and even misused) because programmers will consider them nifty and trendy. The syntax isn't Elysian bliss either. However, we'll probably have to live with it because lambdas are in the FCD. It seems rather unlikely this feature will undergo major revisions now.
auto and decltype
auto and decltype are probably everyone's favorites C++0x core feature. auto lets you declare objects without stating their types explicitly. The compiler infers the type of the object from its initializer:
auto p = new int; //p is int*
Similarly, decltype returns the type of its argument (an expression, a literal or an object). You can use decltype to automate the return type of a function template, create typedefs and so on:
typedef decltype (5) XTYPE; //XTYPE is synonymous for int, the type of 5 XTYPE x=0;
Rvalue references
Rvalue references were added to C++0x to facilitate move semantics and perfect forwarding. In the original proposal, rvalue references could bind to lvalues. This however led to ambiguities of overloaded functions, and undesirable implicit conversions. Later, the rules were changed (this is known as "rvalues 2.0"). In the current FCD, rvalues cannot bind to an lvalue. VS 2010 implements rvalues 2.0, which allows you to overload a function based on the type of the reference:
void readval(int&& n);
void readval(int& n);
int main()
{
int x;
readval(5); //#1
readval(x);//#2
}
static_assert
You've heard of the #error preprocessor directive, which validates its argument during the preprocessing stage. You surely have seen and used the assert() macro, which is evaluated at runtime. The missing link was a compile-time assertion facility, though. The new keyword static_assert that was recently added to C++0x lets you evaluate a certain condition at compile-time. This feature is mostly useful for validation template arguments.
nullptr
The new keyword nullptr is used instead of the archaic and bug-prone NULL macro. nullptr represents a generic null pointer value. You can use it to initialize, assign or compare any pointer type, including pointers to members, pointers to functions and of course, pointers to data types:
int * n= nullptr;
if (n==nullptr)
{//..
}
int (A::*pmf)(char) =&A::f;
pmf=nullptr;
Standard Library Enhancements
A significant portion of the Visual Studio 2010 Standard Library has been rewritten to support C++0x features, most notable rvalue references. Standard containers such as vector and list now include move constructors and move assignment operators. Thus, vector reallocations now take advantage of move semantics by picking up move constructors of the vector's element type. Similarly, Standard Library algorithms recognize types that have move constructors and move assignment operators.
The new Standard Library also provides a smart pointer called unique_ptr which superseded the deprecated auto_ptr. Unlike the latter, unique_ptr safely implements move semantics so you can use it with STL containers and algorithms.
Finally, various new algorithms were added to the C++0x Standard Library including is_sorted() and iota() (one of my favorite algorithms!). The Visual Studio 2010 Standard Library implements these new algorithms. Here's an example that uses iota() to populate an array of 10 integers with the values 5,6...14:
#include <numeric>
int main()
{
int x[10];
std::iota (x, x+10, 5);//begin, end, initial value
}
