C++11 features

C++11 is a new C++ programming language standard. Before its ratification, C++11 was called C++0x.In addition to the existing C++11 features, new C++11 features are supported in XL C/C++ V12.1.

Note: IBM supports selected features of C++11, known as C++0x before its ratification. IBM will continue to develop and implement the features of this standard. The implementation of the language level is based on IBM's interpretation of the standard. Until IBM's implementation of all the C++11 features is complete, including the support of a new C++11 standard library, the implementation may change from release to release. IBM makes no attempt to maintain compatibility, in source, binary, or listings and other compiler interfaces, with earlier releases of IBM's implementation of the new C++11 features.
The following features are introduced in XL C/C++, V12.1:

You can use the -qlanglvl=extended0x option to enable most of the C++ features and all the currently-supported C++11 features. For details, see -qlanglvl.

Explicit conversion operators

The explicit conversion operators feature supports the explicit function specifier being applied to the definition of a user-defined conversion function. You can use this feature to inhibit implicit conversions from being applied where they might be unintended, and thus program more robust classes with fewer ambiguity errors.

You can use the -qlanglvl=explicitconversionoperators option to enable this feature.

For more information, see Explicit Conversion Operators (C++11).

Generalized constant expressions

The generalized constant expressions feature extends the set of expressions permitted within constant expressions. A constant expression is one that can be evaluated at compile time.

You can use the -qlanglvl=constexpr option to enable this feature.

Note: In XL C/C++ V12.1, this feature is a partial implementation of what is defined in the C++11 standard.

Reference collapsing

With the reference collapsing feature, you can form a reference to a reference type using one of the following contexts:
  • A decltype specifier
  • A typedef name
  • A template type parameter

You can use the -qlanglvl=referencecollapsing option to enable this feature.

For more information, see Reference collapsing (C++11).

Right angle brackets

In the C++ language, two consecutive closing angle brackets (>) must be separated with a white space, because they are otherwise parsed as the bitwise right-shift operator (>>). The right angle bracket feature removes the white space requirement for consecutive right angle brackets, thus making programming more convenient.

You can use the -qlanglvl=rightanglebracket option to enable this feature.

For more information, see "Class templates (C++ only)".

Rvalue references

With the rvalue references feature, you can overload functions based on the value categories of arguments and similarly have lvalueness detected by template argument deduction. You can also have an rvalue bound to an rvalue reference and modify the rvalue through the reference. This enables a programming technique with which you can reuse the resources of expiring objects and therefore improve the performance of your libraries, especially if you use generic code with class types, for example, template data structures. Additionally, the value category can be considered when writing a forwarding function.

You can use the -qlanglvl=rvaluereferences option to enable this feature.

For more information, see Using rvalue references (C++11).

Scoped enumerations

With the scoped enumeration feature, you can get the following benefits:
  • The ability to declare a scoped enumeration type, whose enumerators are declared in the scope of the enumeration.
  • The ability to declare an enumeration without providing the enumerators. The declaration of an enumeration without providing the enumerators is referred to as forward declaration.
  • The ability to specify explicitly the underlying type of an enumeration.
  • Improved type safety with no conversions from the value of an enumerator (or an object of an enumeration type) to an integer.

You can use the -qlanglvl=scopedenum option to enable this feature.

For more information, see "Enumeration".

Trailing return type

The trailing return type feature is useful when declaring the following types of templates and functions:
  • Function templates or member functions of class templates with return types that depend on the types of the function arguments
  • Functions or member functions of classes with complicated return types
  • Perfect forwarding functions

You can use the -qlanglvl=autotypededuction option to enable this feature.

For more information, see Trailing return type (C++11).