https://en.wikipedia.org/w/api.php?action=feedcontributions&feedformat=atom&user=Code-structure Wikipedia - User contributions [en] 2025-06-24T10:13:19Z User contributions MediaWiki 1.45.0-wmf.6 https://en.wikipedia.org/w/index.php?title=C%2B%2B11&diff=518428394 C++11 2012-10-18T01:37:30Z <p>Code-structure: Natural order of definitions with constructors first.</p> <hr /> <div>{{ multiple issues<br /> | refimprove = July 2012<br /> | lead too short = July 2012<br /> }}<br /> {{manual|date=July 2012}}<br /> <br /> '''C++11''' (formerly known as '''C++0x'''&lt;ref&gt;http://video.google.com/videoplay?docid=5262479012306588324#&lt;/ref&gt;) is the most recent version of the standard of the [[C++ programming language]]. It was approved by [[International Organization for Standardization|ISO]] on 12 August 2011, replacing [[C++03]].&lt;ref&gt;{{cite web|title=We have an international standard: C++0x is unanimously approved|url=http://herbsutter.com/2011/08/12/we-have-an-international-standard-c0x-is-unanimously-approved/| accessdate=12 August 2011}}&lt;/ref&gt; The name is derived from the tradition of naming language versions by the year of the specification's publication.<br /> <br /> C++11 includes several additions to the [[core language]] and extends the [[C++ standard library]], incorporating most of the [[C++ Technical Report 1]] (TR1) [[Library (computer science)|libraries]] — with the exception of the library of mathematical special functions.&lt;ref&gt;{{cite web|title=Bjarne Stroustrup: A C++0x overview|url=http://www.research.ibm.com/arl/seminar/media/stroustrup.pdf| accessdate=30 June 2011}}&lt;/ref&gt; C++11 was published as ''ISO/IEC 14882:2011''&lt;ref&gt;{{ cite web | authorlink = ISO | title = ISO/IEC 14882:2011 | publisher = ISO | date = 2 September 2011 | url = http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=50372 | accessdate =3 September 2011 }}&lt;/ref&gt; in September 2011 and is available for a fee. The working draft most similar to the published C++11 standard is N3337, dated 12 January 2012;&lt;ref&gt;[http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf]&lt;/ref&gt; it has only editorial corrections from the C++11 standard.&lt;ref&gt;http://stackoverflow.com/a/4653479/734069&lt;/ref&gt;<br /> <br /> ==Changes from the previous version of the standard==<br /> The modifications for C++ involve both the core language and the standard library.<br /> <br /> In the development of every utility of the 2011 standard, the committee has applied some directives:<br /> * Maintain stability and compatibility with [[ISO/IEC 14882|C++98]] and possibly with [[C (programming language)|C]];<br /> * Prefer introduction of new features through the standard library, rather than extending the core language;<br /> * Prefer changes that can evolve programming technique;<br /> * Improve C++ to facilitate systems and library design, rather than to introduce new features useful only to specific applications;<br /> * Increase type safety by providing safer alternatives to earlier unsafe techniques;<br /> * Increase performance and the ability to work directly with hardware;<br /> * Provide proper solutions for real-world problems;<br /> * Implement “zero-overhead” principle (additional support required by some utilities must be used only if the utility is used);<br /> * Make C++ easy to teach and to learn without removing any utility needed by expert programmers.<br /> <br /> Attention to beginners is considered important, because they will always compose the majority of computer programmers, and because many beginners would not intend to extend their knowledge of {{nowrap|C++}}, limiting themselves to operate in the aspects of the language in which they are specialized.{{Ref|web-strou-brief}}<br /> <br /> ==Extensions to the C++ core language==<br /> One function of the C++ committee is the development of the language core. Areas of the core language that were significantly improved include [[Thread (computer science)|multithreading]] support, [[generic programming]] support, uniform initialization, and performance enhancements.<br /> <br /> For the purposes of this article, core language features and changes are grouped into four general sections: run-time performance enhancements, build-time performance enhancements, usability enhancements, and new functionality. Some features could fall into multiple groups, but they are mentioned only in the group that primarily represents that feature.<br /> <br /> ==Core language runtime performance enhancements==<br /> These language features primarily exist to provide some kind of performance benefit, either of memory or of computational speed.<br /> <br /> ===Rvalue references and move constructors===<br /> In C++03 (and before), temporaries (termed &quot;[[value (computer science)|rvalue]]s&quot;, as they often lie on the right side of an assignment) were intended to never be modifiable — just as in C — and were considered to be indistinguishable from &lt;code&gt;const T&amp;amp;&lt;/code&gt; types; nevertheless, in some cases, temporaries could have been modified, a behavior that was even considered to be a useful loophole (for the former, see &lt;ref name=&quot;Sutter_Alexandrescu&quot;&gt;Sutter, Alexandrescu &quot;C++ coding standards&quot; #15&lt;/ref&gt;). C++11 adds a new non-const reference type called an {{visible anchor|rvalue reference}}, identified by &lt;code&gt;T&amp;amp;&amp;amp;&lt;/code&gt;. This refers to temporaries that are permitted to be modified after they are initialized, for the purpose of allowing &quot;move semantics&quot;.<br /> <br /> A chronic performance problem with C++03 is the costly and unnecessary deep copies that can happen implicitly when objects are passed by value. To illustrate the issue, consider that a &lt;code&gt;std::vector&amp;lt;T&amp;gt;&lt;/code&gt; is, internally, a wrapper around a C-style array with a size. If a &lt;code&gt;std::vector&amp;lt;T&amp;gt;&lt;/code&gt; temporary is created or returned from a function, it can be stored only by creating a new &lt;code&gt;std::vector&amp;lt;T&amp;gt;&lt;/code&gt; and copying all of the rvalue's data into it. Then the temporary and all its memory is destroyed. (For simplicity, this discussion neglects the [[return value optimization]]).<br /> <br /> In C++11, a [[b:More C++ Idioms/Move Constructor|{{visible anchor|move constructor}}]] of &lt;code&gt;std::vector&amp;lt;T&amp;gt;&lt;/code&gt; that takes an rvalue reference to a &lt;code&gt;std::vector&amp;lt;T&amp;gt;&lt;/code&gt; can copy the pointer to the internal C-style array out of the rvalue into the new &lt;code&gt;std::vector&amp;lt;T&amp;gt;&lt;/code&gt;, then set the pointer inside the rvalue to null. Since the temporary will never again be used, no code will try to access the null pointer, and because the pointer is null, its memory is not deleted when it goes out of scope. Hence, the operation not only forgoes the expense of a deep copy, but is safe and invisible.<br /> <br /> Rvalue references can provide performance benefits to existing code without needing to make any changes outside the standard library. The type of the returned value of a function returning a &lt;code&gt;std::vector&amp;lt;T&amp;gt;&lt;/code&gt; temporary does not need to be changed explicitly to &lt;code&gt;std::vector&amp;lt;T&amp;gt; &amp;amp;&amp;amp;&lt;/code&gt; to invoke the move constructor, as temporaries are considered rvalues automatically. (However, if &lt;code&gt;std::vector&amp;lt;T&amp;gt;&lt;/code&gt; is a C++03 version without a move constructor, then the copy constructor will be invoked with a &lt;code&gt;const std::vector&amp;lt;T&amp;gt;&amp;amp;&lt;/code&gt;, incurring a significant memory allocation.)<br /> <br /> For safety reasons, some restrictions are imposed. A named variable will never be considered to be an rvalue even if it is declared as such; in order to get an rvalue, the function template &lt;code&gt;std::move&amp;lt;T&amp;gt;()&lt;/code&gt; should be used. Rvalue references can also be modified only under certain circumstances, being intended to be used primarily with move constructors.<br /> <br /> Due to the nature of the wording of rvalue references, and to some modification to the wording for lvalue references (regular references), rvalue references allow developers to provide perfect function forwarding. When combined with [[#Variadic_templates|variadic templates]], this ability allows for function templates that can perfectly forward arguments to another function that takes those particular arguments. This is most useful for forwarding constructor parameters, to create factory functions that will automatically call the correct constructor for those particular arguments. This is seen in the [http://en.cppreference.com/w/cpp/container/vector/emplace_back emplace_back] set of the C++ standard library methods.<br /> <br /> ===constexpr - Generalized constant expressions===<br /> C++ has always had the concept of constant expressions. These are expressions such as &lt;code&gt;3+4&lt;/code&gt; that will always yield the same results, at compile time and at run time. Constant expressions are optimization opportunities for compilers, and compilers frequently execute them at compile time and hardcode the results in the program. Also, there are a number of places where the C++ specification requires the use of constant expressions. Defining an array requires a constant expression, and enumerator values must be constant expressions.<br /> <br /> However, a constant expression has never been allowed to contain a function call or object constructor. So a piece of code as simple as this is illegal:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> int get_five() {return 5;}<br /> <br /> int some_value[get_five() + 7]; // Create an array of 12 integers. Ill-formed C++<br /> &lt;/source&gt;<br /> <br /> This was not legal in C++03, because &lt;code&gt;get_five() + 7&lt;/code&gt; is not a constant expression. A C++03 compiler has no way of knowing if &lt;code&gt;get_five()&lt;/code&gt; actually is constant at runtime. In theory, this function could affect a global variable, call other non-runtime constant functions, etc.<br /> <br /> C++11 introduced the keyword &lt;code&gt;constexpr&lt;/code&gt;, which allows the user to guarantee that a function or object constructor is a compile-time constant.&lt;ref&gt;{{cite web|url=http://www.stroustrup.com/sac10-constexpr.pdf|title=General Constant Expressions for System Programming Languages, Proceedings SAC ’10 | author=Gabriel Dos Reis and Bjarne Stroustrup |date=22 March 2010}}&lt;/ref&gt; The above example can be rewritten as follows:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> constexpr int get_five() {return 5;}<br /> <br /> int some_value[get_five() + 7]; // Create an array of 12 integers. Legal C++11<br /> &lt;/source&gt;<br /> <br /> This allows the compiler to understand, and verify, that &lt;code&gt;get_five&lt;/code&gt; is a compile-time constant.<br /> <br /> The use of &lt;code&gt;constexpr&lt;/code&gt; on a function imposes some limitations on what that function can do. First, the function must have a non-void return type. Second, the function body cannot declare variables or define new types. Third, the body may contain only declarations, null statements and a single return statement. There must exist argument values such that, after argument substitution, the expression in the return statement produces a constant expression.<br /> <br /> Prior to C++11, the values of variables could be used in constant expressions only if the variables are declared const, have an initializer which is a constant expression, and are of integral or enumeration type. C++11 removes the restriction that the variables must be of integral or enumeration type if they are defined with the &lt;code&gt;constexpr&lt;/code&gt; keyword:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> constexpr double earth_gravitational_acceleration = 9.8;<br /> constexpr double moon_gravitational_acceleration = earth_gravitational_acceleration / 6.0;<br /> &lt;/source&gt;<br /> <br /> Such data variables are implicitly const, and must have an initializer which must be a constant expression.<br /> <br /> In order to construct constant expression data values from user-defined types, constructors can also be declared with &lt;code&gt;constexpr&lt;/code&gt;. A &lt;code&gt;constexpr&lt;/code&gt; constructor's function body can contain only declarations and null statements, and cannot declare variables or define types, as with a &lt;code&gt;constexpr&lt;/code&gt; function. There must exist argument values such that, after argument substitution, it initializes the class's members with constant expressions. The destructors for such types must be trivial.<br /> <br /> The copy constructor for a type with any &lt;code&gt;constexpr&lt;/code&gt; constructors should usually also be defined as a &lt;code&gt;constexpr&lt;/code&gt; constructor, in order to allow objects of the type to be returned by value from a constexpr function. Any member function of a class, such as copy constructors, operator overloads, etc., can be declared as &lt;code&gt;constexpr&lt;/code&gt;, so long as they meet the requirements for constexpr functions. This allows the compiler to copy classes at compile time, perform operations on them, etc.<br /> <br /> If a constexpr function or constructor is called with arguments which aren't constant expressions, the call behaves as if the function were not constexpr, and the resulting value is not a constant expression. Likewise, if the expression in the return statement of a constexpr function does not evaluate to a constant expression for a particular invocation, the result is not a constant expression.<br /> <br /> ===Modification to the definition of plain old data===<br /> In C++03, a class or struct must follow a number of rules in order for it to be considered a [[Plain Old Data Structures|plain old data]] (POD) type. Types that fit this definition produce object layouts that are compatible with C, and they could also be initialized statically. However, the definition in C++03 is unnecessarily strict{{citation needed|date=April 2012}} and there are good reasons{{clarify|date=April 2012}} for allowing more types to fit the POD definition{{citation needed|date=April 2012}}.<br /> <br /> C++11 relaxed several of the POD rules, by dividing the POD concept into two separate concepts: ''trivial'' and ''standard-layout''.<br /> <br /> A type that is ''trivial'' can be statically initialized. It also means that it is legal to copy data around via &lt;code&gt;memcpy&lt;/code&gt;, rather than having to use a copy constructor. The lifetime of a ''trivial'' type begins when its storage is defined, not when a constructor completes.<br /> <br /> A trivial class or struct is defined as one that:<br /> <br /> # Has a trivial default constructor. This may use the [[#Explicitly defaulted and deleted special member functions|default constructor syntax]] (&lt;code&gt;SomeConstructor() = default;&lt;/code&gt;).<br /> # Has trivial copy and move constructors, which may use the default syntax.<br /> # Has trivial copy and move assignment operators, which may use the default syntax.<br /> # Has a trivial destructor, which must not be virtual.<br /> <br /> Constructors are trivial only if there are no virtual member functions of the class and no virtual base classes. Copy/move operations also require that all of the non-static data members be trivial.<br /> <br /> A type that is ''standard-layout'' means that it orders and packs its members in a way that is compatible with C. A class or struct is standard-layout, by definition, provided:<br /> <br /> # It has no virtual functions<br /> # It has no virtual base classes<br /> # All its non-static data members have the same access control (public, private, protected)<br /> # All its non-static data members, including any in its base classes, are in the same one class in the hierarchy<br /> # The above rules also apply to all the base classes and to all non-static data members in the class hierarchy<br /> # It has no base classes of the same type as the first defined non-static data member<br /> <br /> A class/struct/union is considered POD if it is trivial, standard-layout, and all of its non-static data members and base classes are PODs.<br /> <br /> By separating these concepts, it becomes possible to give up one without losing the other. A class with complex move and copy constructors may not be trivial, but it could be standard-layout and thus interop with C. Similarly, a class with public and private non-static data members would not be standard-layout, but it would be trivial and thus &lt;code&gt;memcpy&lt;/code&gt;-able.<br /> <br /> ==Core language build time performance enhancements==<br /> <br /> ===Extern template===<br /> In C++03, the compiler must instantiate a template whenever a fully specified template is encountered in a translation unit. If the template is instantiated with the same types in many translation units, this can dramatically increase compile times. There is no way to prevent this in C++03, so C++11 introduced extern template declarations, analogous to extern data declarations.<br /> <br /> C++03 has this syntax to oblige the compiler to instantiate a template:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template class std::vector&lt;MyClass&gt;;<br /> &lt;/source&gt;<br /> <br /> C++11 now provides this syntax:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> extern template class std::vector&lt;MyClass&gt;;<br /> &lt;/source&gt;<br /> <br /> which tells the compiler ''not'' to instantiate the template in this translation unit.<br /> <br /> ==Core language usability enhancements==<br /> These features exist for the primary purpose of making the language easier to use. These can improve type safety, minimize code repetition, make erroneous code less likely, etc.<br /> <br /> ===Initializer lists===<br /> C++03 inherited the initializer-list feature from C. A struct or array is given a list of arguments in curly brackets, in the order of the members' definitions in the struct. These initializer-lists are recursive, so an array of structs or struct containing other structs can use them.<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct Object<br /> {<br /> float first;<br /> int second;<br /> };<br /> <br /> Object scalar = {0.43f, 10}; //One Object, with first=0.43f and second=10<br /> Object anArray[] = {{13.4f, 3}, {43.28f, 29}, {5.934f, 17}}; //An array of three Objects<br /> &lt;/source&gt;<br /> <br /> This is very useful for static lists or just for initializing a struct to a particular value. C++ also provides constructors to initialize an object, but they are often not as convenient as the initializer list. However C++03 allows initializer-lists only on structs and classes that conform to the Plain Old Data (POD) definition; C++11 extends initializer-lists, so they can be used for all classes including standard containers like &lt;code&gt;std::vector&lt;/code&gt;.<br /> <br /> C++11 binds the concept to a template, called &lt;code&gt;std::initializer_list&lt;/code&gt;. This allows constructors and other functions to take initializer-lists as parameters. For example:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> class SequenceClass {<br /> public:<br /> SequenceClass(std::initializer_list&lt;int&gt; list);<br /> };<br /> &lt;/source&gt;<br /> <br /> This allows &lt;code&gt;SequenceClass&lt;/code&gt; to be constructed from a sequence of integers, as such:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> SequenceClass some_var = {1, 4, 5, 6};<br /> &lt;/source&gt;<br /> <br /> This constructor is a special kind of constructor, called an initializer-list-constructor. Classes with such a constructor are treated specially during uniform initialization (see [[#Uniform_initialization|below]])<br /> <br /> The class &lt;code&gt;std::initializer_list&amp;lt;&amp;gt;&lt;/code&gt; is a first-class C++11 standard library type. However, they can be initially constructed statically by the C++11 compiler only through the use of the {} syntax. The list can be copied once constructed, though this is only a copy-by-reference. An initializer list is constant; its members cannot be changed once the initializer list is created, nor can the data in those members be changed.<br /> <br /> Because initializer_list is a real type, it can be used in other places besides class constructors. Regular functions can take typed initializer lists as arguments. For example:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> void function_name(std::initializer_list&lt;float&gt; list);<br /> <br /> function_name({1.0f, -3.45f, -0.4f});<br /> &lt;/source&gt;<br /> <br /> Standard containers can also be initialized in the following ways:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> std::vector&lt;std::string&gt; v = { &quot;xyzzy&quot;, &quot;plugh&quot;, &quot;abracadabra&quot; };<br /> std::vector&lt;std::string&gt; v({ &quot;xyzzy&quot;, &quot;plugh&quot;, &quot;abracadabra&quot; });<br /> std::vector&lt;std::string&gt; v{ &quot;xyzzy&quot;, &quot;plugh&quot;, &quot;abracadabra&quot; }; // see &quot;Uniform initialization&quot; below<br /> &lt;/source&gt;<br /> <br /> ===Uniform initialization===<br /> C++03 has a number of problems with initializing types. There are several ways to initialize types, and they do not all produce the same results when interchanged. The traditional constructor syntax, for example, can look like a function declaration, and steps must be taken to ensure that the compiler's [[most vexing parse]] rule will not mistake it for such. Only aggregates and POD types can be initialized with aggregate initializers (using &lt;code&gt;SomeType var = {/*stuff*/};&lt;/code&gt;).<br /> <br /> C++11 provides a syntax that allows for fully uniform type initialization that works on any object. It expands on the initializer list syntax:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct BasicStruct {<br /> int x;<br /> double y;<br /> };<br /> <br /> struct AltStruct {<br /> AltStruct(int x, double y) : x_{x}, y_{y} {}<br /> <br /> private:<br /> int x_;<br /> double y_;<br /> };<br /> <br /> BasicStruct var1{5, 3.2};<br /> AltStruct var2{2, 4.3};<br /> &lt;/source&gt;<br /> <br /> The initialization of &lt;code&gt;var1&lt;/code&gt; behaves exactly as though it were aggregate-initialization. That is, each data member of an object, in turn, will be copy-initialized with the corresponding value from the initializer-list. Implicit type conversion will be used where necessary. If no conversion exists, or only a narrowing conversion exists, the program is ill-formed. The initialization of &lt;code&gt;var2&lt;/code&gt; invokes the constructor.<br /> <br /> One is also able to do the following:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> <br /> struct IdString {<br /> std::string name;<br /> int identifier;<br /> };<br /> <br /> IdString get_string()<br /> {<br /> return {&quot;foo&quot;, 42}; //Note the lack of explicit type.<br /> }<br /> &lt;/source&gt;<br /> <br /> Uniform initialization does not replace constructor syntax. There are still times when constructor syntax is required. If a class has an initializer list constructor (&lt;code&gt;TypeName(initializer_list&lt;SomeType&gt;);&lt;/code&gt;), then it takes priority over other forms of construction, provided that the initializer list conforms to the sequence constructor's type. The C++11 version of &lt;code&gt;std::vector&lt;/code&gt; has an initializer list constructor for its template type. This means that the following code:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> std::vector&lt;int&gt; the_vec{4};<br /> &lt;/source&gt;<br /> <br /> will call the initializer list constructor, not the constructor of &lt;code&gt;std::vector&lt;/code&gt; that takes a single size parameter and creates the vector with that size. To access the latter constructor, the user will need to use the standard constructor syntax directly.<br /> <br /> ===Type inference===<br /> In C++03 (and C), the type of a variable must be explicitly specified in order to use it. However, with the advent of template types and template metaprogramming techniques, the type of something, particularly the well-defined return value of a function, may not be easily expressed. Therefore, storing intermediates in variables is difficult, possibly requiring knowledge of the internals of a particular metaprogramming library.<br /> <br /> C++11 allows this to be mitigated in two ways. First, the definition of a variable with an explicit initialization can use the &lt;code&gt;auto&lt;/code&gt; keyword. This creates a variable of the specific type of the initializer:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> auto some_strange_callable_type = boost::bind(&amp;some_function, _2, _1, some_object);<br /> auto other_variable = 5;<br /> &lt;/source&gt;<br /> <br /> The type of &lt;code&gt;some_strange_callable_type&lt;/code&gt; is simply whatever the particular template function override of &lt;code&gt;boost::bind&lt;/code&gt; returns for those particular arguments. This type is easily determined procedurally by the compiler as part of its semantic analysis duties, but is not easy for the user to determine upon inspection.<br /> <br /> The type of &lt;code&gt;other_variable&lt;/code&gt; is also well-defined, but it is easier for the user to determine. It is an &lt;code&gt;int&lt;/code&gt;, which is the same type as the integer literal.<br /> <br /> Additionally, the keyword &lt;code&gt;[[decltype]]&lt;/code&gt; can be used to determine the type of an expression at compile-time. For example:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> int some_int;<br /> decltype(some_int) other_integer_variable = 5;<br /> &lt;/source&gt;<br /> <br /> This is more useful in conjunction with &lt;code&gt;auto&lt;/code&gt;, since the type of an auto variable is known only to the compiler. However, &lt;code&gt;decltype&lt;/code&gt; can also be very useful for expressions in code that makes heavy use of operator overloading and specialized types.<br /> <br /> &lt;code&gt;auto&lt;/code&gt; is also useful for reducing the verbosity of the code. For instance, instead of writing<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> for (std::vector&lt;int&gt;::const_iterator itr = myvec.cbegin(); itr != myvec.cend(); ++itr)<br /> &lt;/source&gt;<br /> the programmer can use the shorter<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> for (auto itr = myvec.cbegin(); itr != myvec.cend(); ++itr)<br /> &lt;/source&gt;<br /> <br /> This difference grows as the programmer begins to nest containers, though in such cases &lt;code&gt;typedef&lt;/code&gt;s are a good way to decrease the amount of code.<br /> <br /> The type denoted by &lt;code&gt;decltype&lt;/code&gt; can be different from the type deduced by &lt;code&gt;auto&lt;/code&gt;.<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> #include &lt;vector&gt;<br /> int main()<br /> {<br /> const std::vector&lt;int&gt; v(1);<br /> auto a = v[0]; // a has type int<br /> decltype(v[0]) b = 1; // b has type const int&amp;, the return type of<br /> // std::vector&lt;int&gt;::operator[](size_type) const<br /> auto c = 0; // c has type int<br /> auto d = c; // d has type int<br /> decltype(c) e; // e has type int, the type of the entity named by c<br /> decltype((c)) f = c; // f has type int&amp;, because (c) is an lvalue<br /> decltype(0) g; // g has type int, because 0 is an rvalue<br /> }<br /> &lt;/source&gt;<br /> <br /> ===Range-based for-loop===<br /> In C++03, iterating over the elements of a list requires a lot of code. Other languages have implemented support for [[syntactic sugar]] that allow the programmer to write a simple “foreach” statement that automatically traverses items in a list.<br /> One of those languages is the [[Java (programming language)|Java]] programming language, which received support for what has been defined as enhanced for loops in [[Java version history#J2SE 5.0 .28September_30.2C_2004.29|Java 5.0]].&lt;ref&gt;{{cite web|url=http://docs.oracle.com/javase/1.5.0/docs/guide/language/index.html |title=Java Programming Language: Enhancements in JDK 5 |publisher=Oracle.com}}&lt;/ref&gt;<br /> <br /> C++11 added a similar feature. The statement &lt;code&gt;for&lt;/code&gt; allows for easy iteration over a list of elements:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> int my_array[5] = {1, 2, 3, 4, 5};<br /> for (int &amp;x : my_array) {<br /> x *= 2;<br /> }<br /> &lt;/source&gt;<br /> <br /> This form of &lt;code&gt;for&lt;/code&gt;, called the “range-based for”, will iterate over each element in the list. It will work for C-style arrays, initializer lists, and any type that has &lt;code&gt;begin()&lt;/code&gt; and &lt;code&gt;end()&lt;/code&gt; functions defined for it that return iterators. All of the standard library containers that have begin/end pairs will work with the range-based for statement.<br /> <br /> ===Lambda functions and expressions===<br /> {{main|Anonymous function#C++}}<br /> <br /> C++11 provides the ability to create [[anonymous function]]s, called lambda functions.&lt;ref&gt;<br /> {{cite web<br /> |url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1968.pdf<br /> |title=Document no: N1968=06-0038- Lambda expressions and closures for C++<br /> |publisher=Open Standards<br /> }}&lt;/ref&gt;<br /> These are defined as follows:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> [](int x, int y) { return x + y; }<br /> &lt;/source&gt;<br /> <br /> The return type is implicit; it returns the type of the return expression (&lt;code&gt;decltype(x+y)&lt;/code&gt;). The return type of a lambda can be omitted as long as all &lt;code&gt;return&lt;/code&gt; expressions return the same type.<br /> A lambda can optionally be a [[Closure (computer science)|closure]].<br /> <br /> ===Alternative function syntax===<br /> [[C (programming language)|Standard C]] function declaration syntax was perfectly adequate for the feature set of the C language. As C++ evolved from C, it kept the basic syntax and extended it where necessary. However, as C++ became more complicated, it exposed a number of limitations, particularly with regard to template function declarations. The following, for example, is not allowed in C++03:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template&lt;class Lhs, class Rhs&gt;<br /> Ret adding_func(const Lhs &amp;lhs, const Rhs &amp;rhs) {return lhs + rhs;} //Ret must be the type of lhs+rhs<br /> &lt;/source&gt;<br /> <br /> The type &lt;code&gt;Ret&lt;/code&gt; is whatever the addition of types &lt;code&gt;Lhs&lt;/code&gt; and &lt;code&gt;Rhs&lt;/code&gt; will produce. Even with the aforementioned C++11 functionality of &lt;code&gt;decltype&lt;/code&gt;, this is not possible:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template&lt;class Lhs, class Rhs&gt;<br /> decltype(lhs+rhs) adding_func(const Lhs &amp;lhs, const Rhs &amp;rhs) {return lhs + rhs;} //Not legal C++11<br /> &lt;/source&gt;<br /> <br /> This is not legal C++ because &lt;code&gt;lhs&lt;/code&gt; and &lt;code&gt;rhs&lt;/code&gt; have not yet been defined; they will not be valid identifiers until after the parser has parsed the rest of the function prototype.<br /> <br /> To work around this, C++11 introduced a new function declaration syntax, with a ''trailing-return-type'':<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template&lt;class Lhs, class Rhs&gt;<br /> auto adding_func(const Lhs &amp;lhs, const Rhs &amp;rhs) -&gt; decltype(lhs+rhs) {return lhs + rhs;}<br /> &lt;/source&gt;<br /> <br /> This syntax can be used for more mundane function declarations and definitions:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct SomeStruct {<br /> auto func_name(int x, int y) -&gt; int;<br /> };<br /> <br /> auto SomeStruct::func_name(int x, int y) -&gt; int {<br /> return x + y;<br /> }<br /> &lt;/source&gt;<br /> <br /> The use of the keyword “auto” in this case means something different from its use in automatic type deduction.<br /> <br /> ===Object construction improvement===<br /> In C++03, constructors of a class are not allowed to call other constructors of that class; each constructor must construct all of its class members itself or call a common member function, like these,<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> class SomeType {<br /> int number;<br /> <br /> public:<br /> SomeType(int new_number) : number(new_number) {}<br /> SomeType() : number(42) {}<br /> };<br /> &lt;/source&gt;<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> class SomeType {<br /> int number;<br /> <br /> private:<br /> void Construct(int new_number) { number = new_number; }<br /> public:<br /> SomeType(int new_number) { Construct(new_number); }<br /> SomeType() { Construct(42); }<br /> };<br /> &lt;/source&gt;<br /> <br /> Constructors for base classes cannot be directly exposed to derived classes; each derived class must implement constructors even if a base class constructor would be appropriate. Non-constant data members of classes cannot be initialized at the site of the declaration of those members. They can be initialized only in a constructor.<br /> <br /> C++11 provides solutions to all of these problems.<br /> <br /> C++11 allows constructors to call other peer constructors (known as [[Delegation (programming)|delegation]]). This allows constructors to utilize another constructor's behavior with a minimum of added code. Examples of other languages similar to C++ that provide delegation are [[Java (programming language)|Java]], [[C Sharp (programming language)|C#]], and [[D (programming language)|D]].<br /> <br /> This syntax is as follows:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> class SomeType {<br /> int number;<br /> <br /> public:<br /> SomeType(int new_number) : number(new_number) {}<br /> SomeType() : SomeType(42) {}<br /> };<br /> &lt;/source&gt;<br /> <br /> Notice that, in this case, the same effect could have been achieved by making new_number a defaulting parameter. The new syntax, however, allows the default value (42) to be expressed in the implementation rather than the interface &amp;mdash; a benefit to maintainers of library code since default values for function parameters are “baked in” to call sites, whereas constructor delegation allows the value to be changed without recompilation of the code using the library.<br /> <br /> This comes with a caveat: C++03 considers an object to be constructed when its constructor finishes executing, but C++11 considers an object constructed once ''any'' constructor finishes execution. Since multiple constructors will be allowed to execute, this will mean that each delegate constructor will be executing on a fully constructed object of its own type. Derived class constructors will execute after all delegation in their base classes is complete.<br /> <br /> For base-class constructors, C++11 allows a class to specify that base class constructors will be inherited. This means that the C++11 compiler will generate code to perform the inheritance, the forwarding of the derived class to the base class. Note that this is an all-or-nothing feature; either all of that base class's constructors are forwarded or none of them are. Also, note that there are restrictions for multiple inheritance, such that class constructors cannot be inherited from two classes that use constructors with the same signature. Nor can a constructor in the derived class exist that matches a signature in the inherited base class.<br /> <br /> The syntax is as follows:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> class BaseClass {<br /> public:<br /> BaseClass(int value);<br /> };<br /> <br /> class DerivedClass : public BaseClass {<br /> public:<br /> using BaseClass::BaseClass;<br /> };<br /> &lt;/source&gt;<br /> <br /> For member initialization, C++11 allows the following syntax:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> class SomeClass {<br /> public:<br /> SomeClass() {}<br /> explicit SomeClass(int new_value) : value(new_value) {}<br /> <br /> private:<br /> int value = 5;<br /> };<br /> &lt;/source&gt;<br /> <br /> Any constructor of the class will initialize &lt;code&gt;value&lt;/code&gt; with 5, if the constructor does not override the initialization with its own. So the above empty constructor will initialize &lt;code&gt;value&lt;/code&gt; as the class definition states, but the constructor that takes an int will initialize it to the given parameter.<br /> <br /> It can also use constructor or uniform initialization, instead of the equality initialization shown above.<br /> <br /> ===Explicit overrides and final===<br /> In C++03, it is possible to accidentally create a new virtual function, when one intended to override a base class function. For example:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct Base {<br /> virtual void some_func(float);<br /> };<br /> <br /> struct Derived : Base {<br /> virtual void some_func(int);<br /> };<br /> &lt;/source&gt;<br /> <br /> The &lt;code&gt;Derived::some_func&lt;/code&gt; is intended to replace the base class version. But because it has a different interface, it creates a second virtual function. This is a common problem, particularly when a user goes to modify the base class.<br /> <br /> C++11 provides syntax to solve this problem.<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct Base {<br /> virtual void some_func(float);<br /> };<br /> <br /> struct Derived : Base {<br /> virtual void some_func(int) override; // ill-formed because it doesn't override a base class method<br /> };<br /> &lt;/source&gt;<br /> <br /> The &lt;code&gt;override&lt;/code&gt; special identifier means that the compiler will check the base class(es) to see if there is a virtual function with this exact signature. And if there is not, the compiler will error out.<br /> <br /> C++11 also adds the ability to prevent inheriting from classes or simply preventing overriding methods in derived classes. This is done with the special identifier &lt;code&gt;final&lt;/code&gt;. For example:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct Base1 final { };<br /> <br /> struct Derived1 : Base1 { }; // ill-formed because the class Base1 has been marked final<br /> <br /> struct Base2 {<br /> virtual void f() final;<br /> };<br /> <br /> struct Derived2 : Base2 {<br /> void f(); // ill-formed because the virtual function Base2::f has been marked final<br /> };<br /> &lt;/source&gt;<br /> <br /> In this example, the &lt;code&gt;virtual void f() final;&lt;/code&gt; statement declares a new virtual function, but it also prevents derived classes from overriding it. It also has the effect of preventing derived classes from using that particular function name and parameter combination.<br /> <br /> Note that neither &lt;code&gt;override&lt;/code&gt; nor &lt;code&gt;final&lt;/code&gt; are language keywords. They are technically identifiers; they gain special meaning only when used in those specific contexts. In any other location, they can be valid identifiers.<br /> <br /> ===Null pointer constant===<br /> For the purposes of this section and this section alone, every occurrence of “&lt;code&gt;0&lt;/code&gt;” is meant as “a constant expression which evaluates to &lt;code&gt;0&lt;/code&gt;, which is of type int”. In reality, the constant expression can be of any integral type.<br /> <br /> Since the dawn of C in 1972, the constant &lt;code&gt;[[0 (number)|0]]&lt;/code&gt; has had the double role of constant integer and null pointer constant. The ambiguity inherent in the double meaning of &lt;code&gt;0&lt;/code&gt; was dealt with in C by the use of the preprocessor macro &lt;code&gt;NULL&lt;/code&gt;, which commonly expands to either &lt;code&gt;((void*)0)&lt;/code&gt; or &lt;code&gt;0&lt;/code&gt;. C++ didn't adopt the same behavior, allowing only &lt;code&gt;0&lt;/code&gt; as a null pointer constant. This interacts poorly with function overloading:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> void foo(char *);<br /> void foo(int);<br /> &lt;/source&gt;<br /> <br /> If &lt;code&gt;NULL&lt;/code&gt; is defined as &lt;code&gt;0&lt;/code&gt; (which is usually the case in C++), the statement &lt;code&gt;foo(NULL);&lt;/code&gt; will call &lt;code&gt;foo(int)&lt;/code&gt;, which is almost certainly not what the programmer intended, and not what a superficial reading of the code suggests.<br /> <br /> C++11 corrects this by introducing a new keyword to serve as a distinguished null pointer constant: &lt;code&gt;nullptr&lt;/code&gt;. It is of type &lt;code&gt;nullptr_t&lt;/code&gt;, which is implicitly convertible and comparable to any pointer type or pointer-to-member type. It is not implicitly convertible or comparable to integral types, except for &lt;code&gt;bool&lt;/code&gt;. While the original proposal specified that an rvalue of type &lt;code&gt;nullptr&lt;/code&gt; should not be convertible to &lt;code&gt;bool&lt;/code&gt;, the core language working group decided that such a conversion would be desirable, for consistency with regular pointer types. The proposed wording changes were unanimously voted into the Working Paper in June 2008.{{Ref|n2697}}<br /> <br /> For backwards compatibility reasons, &lt;code&gt;0&lt;/code&gt; remains a valid null pointer constant.<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> char *pc = nullptr; // OK<br /> int *pi = nullptr; // OK<br /> bool b = nullptr; // OK. b is false.<br /> int i = nullptr; // error<br /> <br /> foo(nullptr); // calls foo(char *), not foo(int);<br /> &lt;/source&gt;<br /> <br /> ===Strongly typed enumerations===<br /> In C++03, enumerations are not type-safe. They are effectively integers, even when the enumeration types are distinct. This allows the comparison between two enum values of different enumeration types. The only safety that C++03 provides is that an integer or a value of one enum type does not convert implicitly to another enum type. Additionally, the underlying integral type is implementation-defined; code that depends on the size of the enumeration is therefore non-portable. Lastly, enumeration values are scoped to the enclosing scope. Thus, it is not possible for two separate enumerations to have matching member names.<br /> <br /> C++11 allows a special classification of enumeration that has none of these issues. This is expressed using the &lt;code&gt;enum class&lt;/code&gt; (&lt;code&gt;enum struct&lt;/code&gt; is also accepted as a synonym) declaration:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> enum class Enumeration {<br /> Val1,<br /> Val2,<br /> Val3 = 100,<br /> Val4 // = 101<br /> };<br /> &lt;/source&gt;<br /> <br /> This enumeration is type-safe. Enum class values are not implicitly converted to integers; therefore, they cannot be compared to integers either (the expression &lt;code&gt;Enumeration::Val4 == 101&lt;/code&gt; gives a compiler error).<br /> <br /> The underlying type of enum classes is always known. The default type is &lt;code&gt;int&lt;/code&gt;; this can be overridden to a different integral type as can be seen in the following example:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> enum class Enum2 : unsigned int {Val1, Val2};<br /> &lt;/source&gt;<br /> <br /> With old-style enumerations the values are placed in the outer scope. With new-style enumerations they are placed within the scope of the enum class name. So in the above example, &lt;code&gt;Val1&lt;/code&gt; is undefined, but &lt;code&gt;Enum2::Val1&lt;/code&gt; is defined.<br /> <br /> There is also a transitional syntax to allow old-style enumerations to provide explicit scoping as well as the definition of the underlying type:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> enum Enum3 : unsigned long {Val1 = 1, Val2};<br /> &lt;/source&gt;<br /> <br /> In this case the enumerator names are defined in the enumeration's scope (&lt;code&gt;Enum3::Val1&lt;/code&gt;), but for backwards compatibility they are also placed in the enclosing scope.<br /> <br /> Forward-declaring enums is also possible in C++11. Previously, enum types could not be forward-declared because the size of the enumeration depends on the definition of its members. As long as the size of the enumeration is specified either implicitly or explicitly, it can be forward-declared:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> enum Enum1; // Illegal in C++03 and C++11; the underlying type cannot be determined.<br /> enum Enum2 : unsigned int; // Legal in C++11, the underlying type is explicitly specified.<br /> enum class Enum3; // Legal in C++11, the underlying type is int.<br /> enum class Enum4 : unsigned int; // Legal in C++11.<br /> enum Enum2 : unsigned short; // Illegal in C++11, because Enum2 was previously declared with a different underlying type.<br /> &lt;/source&gt;<br /> <br /> ===Right angle bracket===<br /> C++03's parser defines “&lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt;” as the right shift operator in all cases. However, with nested template declarations, there is a tendency for the programmer to neglect to place a space between the two right angle brackets, thus causing a compiler syntax error.<br /> <br /> C++11 improves the specification of the parser so that multiple right angle brackets will be interpreted as closing the template argument list where it is reasonable. This can be overridden by using parentheses:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template&lt;bool Test&gt; class SomeType;<br /> std::vector&lt;SomeType&lt;1&gt;2&gt;&gt; x1; // Interpreted as a std::vector of SomeType&lt;true&gt; 2&gt;,<br /> // which is not legal syntax. 1 is true.<br /> std::vector&lt;SomeType&lt;(1&gt;2)&gt;&gt; x1; // Interpreted as std::vector of SomeType&lt;false&gt;,<br /> // which is legal C++11 syntax. (1&gt;2) is false.<br /> &lt;/source&gt;<br /> <br /> ===Explicit conversion operators===<br /> C++98 added the &lt;code&gt;explicit&lt;/code&gt; keyword as a modifier on constructors to prevent single-argument constructors from being used as implicit type conversion operators. However, this does nothing for actual conversion operators. For example, a smart pointer class may have an &lt;code&gt;operator bool()&lt;/code&gt; to allow it to act more like a primitive pointer: if it includes this conversion, it can be tested with &lt;code&gt;if (smart_ptr_variable)&lt;/code&gt; (which would be true if the pointer was non-null and false otherwise). However, this allows other, unintended conversions as well. Because C++ &lt;code&gt;bool&lt;/code&gt; is defined as an arithmetic type, it can be implicitly converted to integral or even floating-point types, which allows for mathematical operations that are not intended by the user.<br /> <br /> In C++11, the &lt;code&gt;explicit&lt;/code&gt; keyword can now be applied to conversion operators. As with constructors, it prevents the use of those conversion functions in implicit conversions. However, language contexts that specifically require a boolean value (the conditions of if-statements and loops, as well as operands to the logical operators) count as explicit conversions and can thus use a bool conversion operator.<br /> <br /> ===Alias templates===<br /> <br /> In C++03, it is possible to define a typedef only as a synonym for another type, including a synonym for a template specialization with all actual template arguments specified. It is not possible to create a typedef template. For example:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template &lt;typename First, typename Second, int Third&gt;<br /> class SomeType;<br /> <br /> template &lt;typename Second&gt;<br /> typedef SomeType&lt;OtherType, Second, 5&gt; TypedefName; //Illegal in C++03<br /> &lt;/source&gt;<br /> <br /> This will not compile.<br /> <br /> C++11 adds this ability with the following syntax:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template &lt;typename First, typename Second, int Third&gt;<br /> class SomeType;<br /> <br /> template &lt;typename Second&gt;<br /> using TypedefName = SomeType&lt;OtherType, Second, 5&gt;;<br /> &lt;/source&gt;<br /> <br /> The &lt;code&gt;using&lt;/code&gt; syntax can be also used as type aliasing in C++11:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> typedef void (*Type)(double); // Old style<br /> using OtherType = void (*)(double); // New introduced syntax<br /> &lt;/source&gt;<br /> <br /> ===Unrestricted unions===<br /> In C++03, there are restrictions on what types of objects can be members of a &lt;code&gt;union&lt;/code&gt;. For example, unions cannot contain any objects that define a non-trivial constructor. C++11 lifts some of these restrictions.{{Ref|n2544}}<br /> <br /> * Unions can now contain objects that have a non-trivial constructor.<br /> * If so, the implicit default constructor of the union is deleted, forcing a manual definition.<br /> <br /> This is a simple example of a union permitted in C++11:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> #include &lt;new&gt; // Required for placement 'new'.<br /> //<br /> struct Point {<br /> Point() {}<br /> Point(int x, int y): x_(x), y_(y) {}<br /> int x_, y_;<br /> };<br /> //<br /> union U {<br /> int z;<br /> double w;<br /> Point p; // Illegal in C++03; legal in C++11.<br /> //<br /> // Due to the Point member, a constructor definition is now required.<br /> //<br /> U() {new(&amp;p) Point();} <br /> };<br /> &lt;/source&gt;<br /> <br /> The changes will not break any existing code since they only relax current rules.<br /> <br /> ==Core language functionality improvements==<br /> These features allow the language to do things that were previously impossible, exceedingly verbose, or required non-portable libraries.<br /> <br /> ===Variadic templates===<br /> {{main|variadic templates}}<br /> <br /> In C++11, templates can take variable numbers of template parameters. This also allows the definition of type-safe [[variadic function]]s.<br /> <br /> ===New string literals===<br /> C++03 offers two kinds of string literals. The first kind, contained within double quotes, produces a null-terminated array of type &lt;code&gt;const char&lt;/code&gt;. The second kind, defined as &lt;code&gt;L&quot;&quot;&lt;/code&gt;, produces a null-terminated array of type &lt;code&gt;const wchar_t&lt;/code&gt;, where &lt;code&gt;wchar_t&lt;/code&gt; is a wide-character of undefined size and semantics. Neither literal type offers support for string literals with [[UTF-8]], [[UTF-16]], or any other kind of [[Unicode]] [[Comparison of Unicode encodings|encodings]].<br /> <br /> For the purpose of enhancing support for Unicode in C++ compilers, the definition of the type &lt;code&gt;char&lt;/code&gt; has been modified to be both at least the size necessary to store an eight-bit coding of [[UTF-8]] and large enough to contain any member of the compiler's basic execution character set. It was previously defined as only the latter.<br /> <br /> There are three Unicode encodings that C++11 will support: [[UTF-8]], [[UTF-16]], and [[UTF-32]]. In addition to the previously noted changes to the definition of &lt;code&gt;char&lt;/code&gt;, C++11 adds two new character types: &lt;code&gt;char16_t&lt;/code&gt; and &lt;code&gt;char32_t&lt;/code&gt;. These are designed to store UTF-16 and UTF-32 respectively.<br /> <br /> The following shows how to create string literals for each of these encodings:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> u8&quot;I'm a UTF-8 string.&quot;<br /> u&quot;This is a UTF-16 string.&quot;<br /> U&quot;This is a UTF-32 string.&quot;<br /> &lt;/source&gt;<br /> <br /> The type of the first string is the usual &lt;code&gt;const char[]&lt;/code&gt;. The type of the second string is &lt;code&gt;const char16_t[]&lt;/code&gt;. The type of the third string is &lt;code&gt;const char32_t[]&lt;/code&gt;.<br /> <br /> When building Unicode string literals, it is often useful to insert Unicode codepoints directly into the string. To do this, C++11 allows the following syntax:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> u8&quot;This is a Unicode Character: \u2018.&quot;<br /> u&quot;This is a bigger Unicode Character: \u2018.&quot;<br /> U&quot;This is a Unicode Character: \u2018.&quot;<br /> &lt;/source&gt;<br /> <br /> The number after the &lt;code&gt;\u&lt;/code&gt; is a hexadecimal number; it does not need the usual &lt;code&gt;0x&lt;/code&gt; prefix. The identifier &lt;code&gt;\u&lt;/code&gt; represents a 16-bit Unicode codepoint; to enter a 32-bit codepoint, use &lt;code&gt;\U&lt;/code&gt; and a 32-bit hexadecimal number. Only valid Unicode codepoints can be entered. For example, codepoints on the range U+D800–U+DFFF are forbidden, as they are reserved for surrogate pairs in UTF-16 encodings.<br /> <br /> It is also sometimes useful to avoid escaping strings manually, particularly for using literals of [[XML]] files, scripting languages, or regular expressions. C++11 provides a raw string literal:<br /> <br /> &lt;pre&gt;<br /> R&quot;(The String Data \ Stuff &quot; )&quot;<br /> R&quot;delimiter(The String Data \ Stuff &quot; )delimiter&quot;<br /> &lt;/pre&gt;<br /> <br /> In the first case, everything between the &lt;code&gt;&quot;(&lt;/code&gt; and the &lt;code&gt;)&quot;&lt;/code&gt; is part of the string. The &lt;code&gt;&quot;&lt;/code&gt; and &lt;code&gt;\&lt;/code&gt; characters do not need to be escaped. In the second case, the &lt;code&gt;&quot;delimiter(&lt;/code&gt; starts the string, and it ends only when &lt;code&gt;)delimiter&quot;&lt;/code&gt; is reached. The string &lt;code&gt;delimiter&lt;/code&gt; can be any string up to 16 characters in length, including the empty string. This string cannot contain spaces, control characters, '&lt;code&gt;(&lt;/code&gt;', '&lt;code&gt;)&lt;/code&gt;', or the '&lt;code&gt;\&lt;/code&gt;' character. The use of this delimiter string allows the user to have &quot;&lt;code&gt;)&lt;/code&gt;&quot; characters within raw string literals. For example, &lt;code&gt;R&quot;delimiter((a-z))delimiter&quot;&lt;/code&gt; is equivalent to &lt;code&gt;&quot;(a-z)&quot;&lt;/code&gt;.{{Ref|n3000}}<br /> <br /> Raw string literals can be combined with the wide literal or any of the Unicode literal prefixes:<br /> <br /> &lt;pre&gt;<br /> u8R&quot;XXX(I'm a &quot;raw UTF-8&quot; string.)XXX&quot;<br /> uR&quot;*(This is a &quot;raw UTF-16&quot; string.)*&quot;<br /> UR&quot;(This is a &quot;raw UTF-32&quot; string.)&quot;<br /> &lt;/pre&gt;<br /> <br /> ===User-defined literals===<br /> C++03 provides a number of literals. The characters “&lt;code&gt;12.5&lt;/code&gt;” are a literal that is resolved by the compiler as a type &lt;code&gt;double&lt;/code&gt; with the value of 12.5. However, the addition of the suffix “&lt;code&gt;f&lt;/code&gt;”, as in “&lt;code&gt;12.5f&lt;/code&gt;”, creates a value of type &lt;code&gt;float&lt;/code&gt; that contains the value 12.5. The suffix modifiers for literals are fixed by the C++ specification, and C++ code cannot create new literal modifiers.<br /> <br /> C++11 also includes the ability for the user to define new kinds of literal modifiers that will construct objects based on the string of characters that the literal modifies.<br /> <br /> Literals transformation is redefined into two distinct phases: raw and cooked. A raw literal is a sequence of characters of some specific type, while the cooked literal is of a separate type. The C++ literal &lt;code&gt;1234&lt;/code&gt;, as a raw literal, is this sequence of characters &lt;code&gt;'1'&lt;/code&gt;, &lt;code&gt;'2'&lt;/code&gt;, &lt;code&gt;'3'&lt;/code&gt;, &lt;code&gt;'4'&lt;/code&gt;. As a cooked literal, it is the integer 1234. The C++ literal &lt;code&gt;0xA&lt;/code&gt; in raw form is &lt;code&gt;'0'&lt;/code&gt;, &lt;code&gt;'x'&lt;/code&gt;, &lt;code&gt;'A'&lt;/code&gt;, while in cooked form it is the integer 10.<br /> <br /> Literals can be extended in both raw and cooked forms, with the exception of string literals, which can be processed only in cooked form. This exception is due to the fact that strings have prefixes that affect the specific meaning and type of the characters in question.<br /> <br /> All user-defined literals are suffixes; defining prefix literals is not possible.<br /> <br /> User-defined literals processing the raw form of the literal are defined as follows:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> OutputType operator &quot;&quot; _suffix(const char * literal_string);<br /> <br /> OutputType some_variable = 1234_suffix;<br /> &lt;/source&gt;<br /> <br /> The second statement executes the code defined by the user-defined literal function. This function is passed &lt;code&gt;&quot;1234&quot;&lt;/code&gt; as a C-style string, so it has a null terminator.<br /> <br /> An alternative mechanism for processing integer and floating point raw literals is through a [[variadic template]]:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template&lt;char...&gt; OutputType operator &quot;&quot; _suffix();<br /> <br /> OutputType some_variable = 1234_suffix;<br /> OutputType another_variable = 2.17_suffix;<br /> &lt;/source&gt;<br /> <br /> This instantiates the literal processing function as &lt;code&gt;operator &quot;&quot; _suffix&lt;'1', '2', '3', '4'&gt;()&lt;/code&gt;. In this form, there is no terminating null character to the string. The main purpose to doing this is to use C++11's &lt;code&gt;constexpr&lt;/code&gt; keyword and the compiler to allow the literal to be transformed entirely at compile time, assuming &lt;code&gt;OutputType&lt;/code&gt; is a constexpr-constructable and copyable type, and the literal processing function is a &lt;code&gt;constexpr&lt;/code&gt; function.<br /> <br /> For numeric literals, the type of the cooked literal is either &lt;code&gt;unsigned long long&lt;/code&gt; for integral literals or &lt;code&gt;long double&lt;/code&gt; for floating point literals. (Note: There is no need for signed integral types because a sign-prefixed literal is parsed as an expression containing the sign as a unary prefix operator and the unsigned number.) There is no alternative template form:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> OutputType operator &quot;&quot; _suffix(unsigned long long);<br /> OutputType operator &quot;&quot; _suffix(long double);<br /> <br /> OutputType some_variable = 1234_suffix; // Uses the 'unsigned long long' overload.<br /> OutputType another_variable = 3.1416_suffix; // Uses the 'long double' overload.<br /> &lt;/source&gt;<br /> <br /> For string literals, the following are used, in accordance with the previously mentioned new string prefixes:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> OutputType operator &quot;&quot; _suffix(const char * string_values, size_t num_chars);<br /> OutputType operator &quot;&quot; _suffix(const wchar_t * string_values, size_t num_chars);<br /> OutputType operator &quot;&quot; _suffix(const char16_t * string_values, size_t num_chars);<br /> OutputType operator &quot;&quot; _suffix(const char32_t * string_values, size_t num_chars);<br /> <br /> OutputType some_variable = &quot;1234&quot;_suffix; // Uses the 'const char *' overload.<br /> OutputType some_variable = u8&quot;1234&quot;_suffix; // Uses the 'const char *' overload.<br /> OutputType some_variable = L&quot;1234&quot;_suffix; // Uses the 'const wchar_t *' overload.<br /> OutputType some_variable = u&quot;1234&quot;_suffix; // Uses the 'const char16_t *' overload.<br /> OutputType some_variable = U&quot;1234&quot;_suffix; // Uses the 'const char32_t *' overload.<br /> &lt;/source&gt;<br /> <br /> There is no alternative template form. Character literals are defined similarly.<br /> <br /> ===Multithreading memory model===<br /> {{See also|Memory model (computing)}}<br /> The C++11 standardizes support for [[Thread (computer science)|multithreaded programming]].<br /> <br /> There are two parts involved: a memory model which allows multiple threads to co-exist in a program and library support for interaction between threads. (See this article's section on [[#Threading facilities|threading facilities]].)<br /> <br /> The memory model defines when multiple threads may access the same memory location, and specifies when updates by one thread become visible to other threads.<br /> <br /> ===Thread-local storage===<br /> In a multi-threaded environment, it is common for every thread to have some unique [[Variable (programming)|variables]]. This already happens for the local variables of a function, but it does not happen for global and static variables.<br /> <br /> A new [[Thread-Local Storage|''thread-local'']] storage duration (in addition to the existing ''static'', ''dynamic'' and ''automatic'') is indicated by the storage specifier &lt;code&gt;thread_local&lt;/code&gt;.<br /> <br /> Any object which could have static storage duration (i.e., lifetime spanning the entire execution of the program) may be given thread-local duration instead. The intent is that like any other static-duration variable, a thread-local object can be initialized using a constructor and destroyed using a destructor.<br /> <br /> ===Explicitly defaulted and deleted special member functions===<br /> In C++03, the compiler provides, for classes that do not provide them for themselves, a default constructor, a copy constructor, a copy assignment operator (&lt;code&gt;operator=&lt;/code&gt;), and a destructor. The programmer can override these defaults by defining custom versions. C++ also defines several global operators (such as &lt;code&gt;operator=&lt;/code&gt; and &lt;code&gt;operator new&lt;/code&gt;) that work on all classes, which the programmer can override.<br /> <br /> However, there is very little control over the creation of these defaults. Making a class inherently non-copyable, for example, requires declaring a private copy constructor and copy assignment operator and not defining them. Attempting to use these functions is a violation of the [[One Definition Rule]] (ODR). While a diagnostic message is not required,&lt;ref name=&quot;C++03 3.2/3&quot;&gt;[[ISO]]/[[International Electrotechnical Commission|IEC]] (2003). ''[[ISO/IEC 14882|ISO/IEC 14882:2003(E): Programming Languages - C++]] §3.2 One definition rule [basic.def.odr]'' para. 3&lt;/ref&gt; this typically results in a linker error.{{Citation needed|date=June 2009}}<br /> <br /> In the case of the default constructor, the compiler will not generate a default constructor if a class is defined with ''any'' constructors. This is useful in many cases, but it is also useful to be able to have both specialized constructors and the compiler-generated default.<br /> <br /> C++11 allows the explicit defaulting and deleting of these special member functions. For example, the following type explicitly declares that it is using the default constructor:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct SomeType {<br /> SomeType() = default; //The default constructor is explicitly stated.<br /> SomeType(OtherType value);<br /> };<br /> &lt;/source&gt;<br /> <br /> Alternatively, certain features can be explicitly disabled. For example, the following type is non-copyable:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct NonCopyable {<br /> NonCopyable() = default;<br /> NonCopyable(const NonCopyable&amp;) = delete;<br /> NonCopyable &amp; operator=(const NonCopyable&amp;) = delete;<br /> };<br /> &lt;/source&gt;<br /> <br /> The &lt;code&gt;= delete&lt;/code&gt; specifier can be used to prohibit calling any function, which can be used to disallow calling a member function with particular parameters. For example:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct NoInt {<br /> void f(double i);<br /> void f(int) = delete;<br /> };<br /> &lt;/source&gt;<br /> <br /> An attempt to call &lt;code&gt;f()&lt;/code&gt; with an &lt;code&gt;int&lt;/code&gt; will be rejected by the compiler, instead of performing a silent conversion to &lt;code&gt;double&lt;/code&gt;. This can be generalized to disallow calling the function with any type other than &lt;code&gt;double&lt;/code&gt; as follows:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct OnlyDouble {<br /> void f(double d);<br /> template&lt;class T&gt; void f(T) = delete;<br /> };<br /> &lt;/source&gt;<br /> <br /> ===Type &lt;code&gt;long long int&lt;/code&gt;===<br /> In C++03, the largest integer type is &lt;code&gt;long int&lt;/code&gt;. It is guaranteed to have at least as many usable bits as &lt;code&gt;int&lt;/code&gt;. This resulted in &lt;code&gt;long int&lt;/code&gt; having size of 64 bits on some popular implementations and 32 bits on others. C++11 adds a new integer type &lt;code&gt;long long int&lt;/code&gt; to address this issue. It is guaranteed to be at least as large as a &lt;code&gt;long int&lt;/code&gt;, and have no fewer than 64 bits. The type was originally introduced by [[C99]] to the standard C, and most C++ compilers support it as an extension already.&lt;ref&gt;http://gcc.gnu.org/onlinedocs/gcc/Long-Long.html&lt;/ref&gt;&lt;ref&gt;http://msdn.microsoft.com/en-us/library/s3f49ktz(VS.80).aspx&lt;/ref&gt;<br /> <br /> ===Static assertions===<br /> C++03 provides two methods to test [[Assertion (computing)|assertions]]: the macro &lt;code&gt;assert&lt;/code&gt; and the preprocessor directive &lt;code&gt;#error&lt;/code&gt;. However, neither is appropriate for use in templates: the macro tests the assertion at execution-time, while the preprocessor directive tests the assertion during preprocessing, which happens before instantiation of templates. Neither is appropriate for testing properties that are dependent on template parameters.<br /> <br /> The new utility introduces a new way to test assertions at compile-time, using the new keyword &lt;code&gt;static_assert&lt;/code&gt;.<br /> The declaration assumes the following form:<br /> static_assert (''constant-expression'', ''error-message'');<br /> <br /> Here are some examples of how &lt;code&gt;static_assert&lt;/code&gt; can be used:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> static_assert((GREEKPI &gt; 3.14) &amp;&amp; (GREEKPI &lt; 3.15), &quot;GREEKPI is inaccurate!&quot;);<br /> &lt;/source&gt;<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template&lt;class T&gt;<br /> struct Check {<br /> static_assert(sizeof(int) &lt;= sizeof(T), &quot;T is not big enough!&quot;);<br /> };<br /> &lt;/source&gt;<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template&lt;class Integral&gt;<br /> Integral foo(Integral x, Integral y) {<br /> static_assert(std::is_integral&lt;Integral&gt;::value, &quot;foo() parameter must be an integral type.&quot;);<br /> }<br /> &lt;/source&gt;<br /> <br /> When the constant expression is &lt;code&gt;false&lt;/code&gt; the compiler produces an error message. The first example represents an alternative to the preprocessor directive &lt;code&gt;#error&lt;/code&gt;, in contrast in the second example the assertion is checked at every instantiation of the template class &lt;code&gt;Check&lt;/code&gt;.<br /> <br /> Static assertions are useful outside of templates as well. For instance, a particular implementation of an algorithm might depend on the size of a &lt;code&gt;long long&lt;/code&gt; being larger than an &lt;code&gt;int&lt;/code&gt;, something the standard does not guarantee. Such an assumption is valid on most systems and compilers, but not all.<br /> <br /> ===Allow &lt;code&gt;sizeof&lt;/code&gt; to work on members of classes without an explicit object===<br /> In C++03, the &lt;code&gt;sizeof&lt;/code&gt; operator can be used on types and objects. But it cannot be used to do the following:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct SomeType { OtherType member; };<br /> <br /> sizeof(SomeType::member); //Does not work with C++03. Okay with C++11<br /> &lt;/source&gt;<br /> <br /> This should return the size of &lt;code&gt;OtherType&lt;/code&gt;. C++03 does not allow this, so it is a compile error. C++11 does allow it.<br /> <br /> ===Control and query object alignment===<br /> C++11 allows variable alignment to be queried and controlled with &lt;code&gt;alignof&lt;/code&gt; and &lt;code&gt;alignas&lt;/code&gt;.<br /> <br /> The &lt;code&gt;alignof&lt;/code&gt; operator takes a type and returns the power of 2 byte boundary on which the type instances must be allocated (as a &lt;code&gt;std::size_t&lt;/code&gt;). When given a reference type &lt;code&gt;alignof&lt;/code&gt; returns the referenced type's alignment; for arrays it returns the element type's alignment.<br /> <br /> The &lt;code&gt;alignas&lt;/code&gt; specifier controls the memory alignment for a variable. The specifier takes a constant or a type; when supplied a type &lt;code&gt;alignas(T)&lt;/code&gt; is short hand for &lt;code&gt;alignas(alignof(T))&lt;/code&gt;. For example, to specify that a char array should be properly aligned to hold a float:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> alignas(float) unsigned char c[sizeof(float)]<br /> &lt;/source&gt;<br /> <br /> ===Allow garbage collected implementations===<br /> In previous C++ standards, a conforming implementation could not collect objects even if no pointer to the object remained because pointers might still exist in some encoded form (e.g., as strings). C++11 changes language semantics to make garbage collection possible. {{citation needed|date=August 2012}} It is still implementation-defined whether unreachable dynamically allocated objects actually are automatically reclaimed.<br /> <br /> ==C++ standard library changes==<br /> A number of new features were introduced in the C++11 standard library. Many of these could have been implemented under the old standard, but some rely (to a greater or lesser extent) on new C++11 core features.<br /> <br /> A large part of the new [[Library (computer science)|libraries]] was defined in the document ''[[Technical Report 1|C++ Standards Committee's Library Technical Report]]'' (called TR1), which was published in 2005. Various full and partial implementations of TR1 are currently available using the namespace &lt;code&gt;std::tr1&lt;/code&gt;. For C++11 they were moved to namespace &lt;code&gt;std&lt;/code&gt;. However, as TR1 features were brought into the C++11 standard library, they were upgraded where appropriate with C++11 language features that were not available in the initial TR1 version. Also, they may have been enhanced with features that were possible under C++03, but were not part of the original TR1 specification.<br /> <br /> The committee intends to create a second technical report (called TR2) now that standardization of C++11 is complete. Library proposals which were not ready in time for C++11 will be put into TR2 or further technical reports.<br /> <br /> ===Upgrades to standard library components===<br /> C++11 offers a number of new language features that the currently existing standard library components can benefit from. For example, most standard library containers can benefit from Rvalue reference based move constructor support, both for quickly moving heavy containers around and for moving the contents of those containers to new memory locations. The standard library components were upgraded with new C++11 language features where appropriate. These include, but are not necessarily limited to:<br /> <br /> * Rvalue references and the associated move support<br /> * Support for the UTF-16 encoding unit, and UTF-32 encoding unit Unicode character types<br /> * [[Variadic templates]] (coupled with Rvalue references to allow for perfect forwarding)<br /> * Compile-time constant expressions<br /> * &lt;code&gt;[[decltype]]&lt;/code&gt;<br /> * &lt;code&gt;explicit&lt;/code&gt; conversion operators<br /> * &lt;code&gt;default&lt;/code&gt;/&lt;code&gt;delete&lt;/code&gt;d functions<br /> <br /> Additionally, much time has passed since the previous C++ standard. A great deal of code using the standard library has been written; this has revealed portions of the standard libraries that could use some improvement. Among the many areas of improvement considered were standard library [[Allocator (C++)|allocator]]s. A new scope-based model of allocators was included in C++11 to supplement the previous model.<br /> <br /> ===Threading facilities===<br /> While the C++11 language provides a memory model that supports threading, the primary support for actually using threading comes with the C++11 standard library.<br /> <br /> A thread class (&lt;code&gt;std::thread&lt;/code&gt;) is provided which takes a [[function object]] — and an optional series of arguments to pass to it — to run in the new thread. It is possible to cause a thread to halt until another executing thread completes, providing thread joining support through the &lt;code&gt;std::thread::join()&lt;/code&gt; member function. Access is provided, where feasible, to the underlying native thread object(s) for [[Platform (computing)|platform]] specific operations by the &lt;code&gt;std::thread::native_handle()&lt;/code&gt; member function.<br /> <br /> For synchronization between threads, appropriate [[Mutual exclusion|mutexes]] (&lt;code&gt;std::mutex&lt;/code&gt;, &lt;code&gt;std::recursive_mutex&lt;/code&gt;, etc.) and [[Monitor (synchronization)|condition variables]] (&lt;code&gt;std::condition_variable&lt;/code&gt; and &lt;code&gt;std::condition_variable_any&lt;/code&gt;) are added to the library. These are accessible through [[Resource Acquisition Is Initialization|RAII]] locks (&lt;code&gt;std::lock_guard&lt;/code&gt; and &lt;code&gt;std::unique_lock&lt;/code&gt;) and locking algorithms for easy use.<br /> <br /> For high-performance, low-level work, it is sometimes necessary to communicate between threads without the overhead of mutexes. This is achieved using [[atomic operation]]s on memory locations. These can optionally specify the minimum memory visibility constraints required for an operation. Explicit [[memory barrier]]s may also be used for this purpose.<br /> <br /> The C++11 thread library also includes [[futures and promises]] for passing asynchronous results between threads, and &lt;code&gt;std::packaged_task&lt;/code&gt; for wrapping up a function call that can generate such an asynchronous result. The futures proposal was criticized because it lacks a way to combine futures and check for the completion of one promise inside a set of promises.&lt;ref&gt;{{Cite web<br /> | last = Milewski<br /> | first = Bartosz<br /> | title = Broken promises–C++0x futures<br /> | date = 3 March 2009<br /> | url = http://bartoszmilewski.wordpress.com/2009/03/03/broken-promises-c0x-futures/<br /> | accessdate =24 January 2010}}&lt;/ref&gt;<br /> <br /> Further high-level threading facilities such as [[thread pool]]s have been remanded to a future C++ [[Technical Report 1|technical report]]. They are not part of C++11, but their eventual implementation is expected to be built entirely on top of the thread library features.<br /> <br /> The new &lt;code&gt;std::async&lt;/code&gt; facility provides a convenient method of running tasks and tying them to a &lt;code&gt;std::future&lt;/code&gt;. The user can choose whether the task is to be run asynchronously on a separate thread or synchronously on a thread that waits for the value. By default, the implementation can choose, which provides an easy way to take advantage of hardware concurrency without oversubscription, and provides some of the advantages of a thread pool for simple usages.<br /> <br /> ===Tuple types===<br /> [[Tuples]] are collections composed of heterogeneous objects of pre-arranged dimensions. A tuple can be considered a generalization of a struct's member variables.<br /> <br /> The C++11 version of the TR1 tuple type benefited from C++11 features like [[#Variadic templates|variadic templates]]. The TR1 version required an implementation-defined maximum number of contained types, and required substantial macro trickery to implement reasonably. By contrast, the implementation of the C++11 version requires no explicit implementation-defined maximum number of types. Though compilers will have an internal maximum recursion depth for template instantiation (which is normal), the C++11 version of tuples will not expose this value to the user.<br /> <br /> Using [[variadic templates]], the declaration of the tuple class looks as follows:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template &lt;class ...Types&gt; class tuple;<br /> &lt;/source&gt;<br /> <br /> An example of definition and use of the tuple type:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> typedef std::tuple &lt;int, double, long &amp;, const char *&gt; test_tuple;<br /> long lengthy = 12;<br /> test_tuple proof (18, 6.5, lengthy, &quot;Ciao!&quot;);<br /> <br /> lengthy = std::get&lt;0&gt;(proof); // Assign to 'lengthy' the value 18.<br /> std::get&lt;3&gt;(proof) = &quot; Beautiful!&quot;; // Modify the tuple’s fourth element.<br /> &lt;/source&gt;<br /> <br /> It’s possible to create the tuple &lt;code&gt;proof&lt;/code&gt; without defining its contents, but only if the tuple elements' types possess default constructors. Moreover, it’s possible to assign a tuple to another tuple: if the two tuples’ types are the same, it is necessary that each element type possesses a copy constructor; otherwise, it is necessary that each element type of the right-side tuple is convertible to that of the corresponding element type of the left-side tuple or that the corresponding element type of the left-side tuple has a suitable constructor.<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> typedef std::tuple &lt;int , double, string &gt; tuple_1 t1;<br /> typedef std::tuple &lt;char, short , const char * &gt; tuple_2 t2 ('X', 2, &quot;Hola!&quot;);<br /> t1 = t2 ; // Ok, first two elements can be converted,<br /> // the third one can be constructed from a 'const char *'.<br /> &lt;/source&gt;<br /> <br /> Relational operators are available (among tuples with the same number of elements), and two expressions are available to check a tuple’s characteristics (only during compilation):<br /> *&lt;code&gt;std::tuple_size&lt;nowiki&gt;&lt;T&gt;&lt;/nowiki&gt;::value&lt;/code&gt; returns the number of elements in the tuple &lt;code&gt;T&lt;/code&gt;,<br /> *&lt;code&gt;std::tuple_element&lt;nowiki&gt;&lt;I, T&gt;&lt;/nowiki&gt;::type&lt;/code&gt; returns the type of the object number &lt;code&gt;I&lt;/code&gt; of the tuple &lt;code&gt;T&lt;/code&gt;.<br /> <br /> ===Hash tables===<br /> Including [[hash tables]] (unordered associative containers) in the C++ standard library is one of the most recurring requests. It was not adopted in C++03 due to time constraints only. Although hash tables are less efficient than a balanced tree in the worst case (in the presence of many collisions), they perform better in many real applications.<br /> <br /> Collisions are managed only through ''[[Hash tables#Separate chaining|linear chaining]]'' because the committee didn't consider opportune to standardize solutions of ''[[open addressing]]'' that introduce quite a lot of intrinsic problems (above all when erasure of elements is admitted). To avoid name clashes with non-standard libraries that developed their own hash table implementations, the prefix “unordered” was used instead of “hash”.<br /> <br /> The new library has four types of hash tables, differentiated by whether or not they accept elements with the same key (unique keys or equivalent keys), and whether they map each key to an associated value. They correspond to the four existing binary-search-tree-based associative containers, with an &lt;tt&gt;unordered_&lt;/tt&gt; prefix.<br /> <br /> {| class=&quot;wikitable&quot; style=&quot;text-align: center&quot;<br /> ! Type of hash table !! Associated values !! Equivalent keys<br /> |-<br /> | style=&quot;text-align: left&quot; | &lt;code&gt;[[Unordered associative containers (C++)|std::unordered_set]]&lt;/code&gt; || {{no}} || {{no}}<br /> |-<br /> | style=&quot;text-align: left&quot; | &lt;code&gt;[[Unordered associative containers (C++)|std::unordered_multiset]]&lt;/code&gt; || {{no}} || {{yes}}<br /> |-<br /> | style=&quot;text-align: left&quot; | &lt;code&gt;[[Unordered associative containers (C++)|std::unordered_map]]&lt;/code&gt; || {{yes}} || {{no}}<br /> |-<br /> | style=&quot;text-align: left&quot; | &lt;code&gt;[[Unordered associative containers (C++)|std::unordered_multimap]]&lt;/code&gt; || {{yes}} || {{yes}}<br /> |}<br /> <br /> New classes fulfill all the requirements of a [[Standard Template Library#Containers|container class]], and have all the methods necessary to access elements: &lt;code&gt;insert&lt;/code&gt;, &lt;code&gt;erase&lt;/code&gt;, &lt;code&gt;begin&lt;/code&gt;, &lt;code&gt;end&lt;/code&gt;.<br /> <br /> This new feature didn't need any C++ language core extensions (though implementations will take advantage of various C++11 language features), only a small extension of the header &lt;code&gt;&lt;nowiki&gt;&lt;functional&gt;&lt;/nowiki&gt;&lt;/code&gt; and the introduction of headers &lt;code&gt;&lt;nowiki&gt;&lt;unordered_set&gt;&lt;/nowiki&gt;&lt;/code&gt; and &lt;code&gt;&lt;nowiki&gt;&lt;unordered_map&gt;&lt;/nowiki&gt;&lt;/code&gt;. No other changes to any existing standard classes were needed, and it doesn’t depend on any other extensions of the standard library.<br /> <br /> ===Regular expressions===<br /> <br /> The new library, defined in the new header &lt;code&gt;&lt;nowiki&gt;&lt;regex&gt;&lt;/nowiki&gt;&lt;/code&gt;, is made of a couple of new classes:<br /> *[[regular expressions]] are represented by instance of the template class &lt;code&gt;std::regex&lt;/code&gt;;<br /> *occurrences are represented by instance of the template class &lt;code&gt;std::match_results&lt;/code&gt;.<br /> The function &lt;code&gt;std::regex_search&lt;/code&gt; is used for searching, while for ‘search and replace’ the function &lt;code&gt;std::regex_replace&lt;/code&gt; is used which returns a new string.<br /> The algorithms &lt;code&gt;std::regex_search&lt;/code&gt; and &lt;code&gt;std::regex_replace&lt;/code&gt; take a regular expression and a string and write the occurrences found in the struct &lt;code&gt;std::match_results&lt;/code&gt;.<br /> <br /> Here is an example of the use of &lt;code&gt;std::match_results&lt;/code&gt;:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> const char *reg_esp = &quot;[ ,.\\t\\n;:]&quot;; // List of separator characters.<br /> <br /> // this can be done using raw string literals:<br /> // const char *reg_esp = R&quot;([ ,.\t\n;:])&quot;;<br /> <br /> std::regex rgx(reg_esp); // 'regex' is an instance of the template class<br /> // 'basic_regex' with argument of type 'char'.<br /> std::cmatch match; // 'cmatch' is an instance of the template class<br /> // 'match_results' with argument of type 'const char *'.<br /> const char *target = &quot;Unseen University - Ankh-Morpork&quot;;<br /> <br /> // Identifies all words of 'target' separated by characters of 'reg_esp'.<br /> if( std::regex_search( target, match, rgx ) ) {<br /> // If words separated by specified characters are present.<br /> <br /> const size_t n = match.size();<br /> for( size_t a = 0; a &lt; n; a++ ) {<br /> std::string str( match[a].first, match[a].second );<br /> std::cout &lt;&lt; str &lt;&lt; &quot;\n&quot;;<br /> }<br /> }<br /> &lt;/source&gt;<br /> <br /> Note the use of double [[backslash]]es, because C++ uses backslash as an escape character. The C++11 [[#New_string_literals|raw string]] feature could be used to avoid the problem.<br /> <br /> The library &lt;code&gt;&lt;nowiki&gt;&lt;regex&gt;&lt;/nowiki&gt;&lt;/code&gt; requires neither alteration of any existing header (though it will use them where appropriate) nor an extension of the core language.<br /> <br /> ===General-purpose smart pointers===<br /> {{main|Smart_pointer|l1=C++ Smart Pointers}}<br /> C++11 provides {{code|std::unique_ptr}}, as well as improvements to {{code|std::shared_ptr}} and {{code|std::weak_ptr}} from TR1. {{code|std::auto_ptr}} is deprecated.<br /> <br /> ===Extensible random number facility===<br /> The C standard library provides the ability to generate [[pseudorandom numbers]] through the function &lt;code&gt;rand&lt;/code&gt;. However, the algorithm is delegated entirely to the library vendor. C++ inherited this functionality with no changes, but C++11 will provide a new method for generating pseudorandom numbers.<br /> <br /> C++11's random number functionality is split into two parts: a generator engine that contains the random number generator's state and produces the pseudorandom numbers; and a distribution, which determines the range and [[Distribution (mathematics)|mathematical distribution]] of the outcome. These two are combined to form a random number generator object.<br /> <br /> Unlike the C standard &lt;code&gt;rand&lt;/code&gt;, the C++11 mechanism will come with three base generator engine algorithms:<br /> * &lt;code&gt;[[Linear congruential generator|linear_congruential_engine]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Subtract with carry|subtract_with_carry_engine]]&lt;/code&gt;, and<br /> * &lt;code&gt;[[Mersenne twister|mersenne_twister_engine]]&lt;/code&gt;.<br /> <br /> C++11 will also provide a number of standard distributions:<br /> * &lt;code&gt;[[Uniform distribution (discrete)|uniform_int_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Uniform distribution (continuous)|uniform_real_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Bernoulli distribution|bernoulli_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Binomial distribution|binomial_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Geometric distribution|geometric_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Negative binomial distribution|negative_binomial_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Poisson distribution|poisson_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Exponential distribution|exponential_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Gamma distribution|gamma_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Weibull distribution|weibull_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Generalized extreme value distribution|extreme_value_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Normal distribution|normal_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Lognormal distribution|lognormal_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Chi squared distribution|chi_squared_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Cauchy distribution|cauchy_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[F-distribution|fisher_f_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Student's t-distribution|student_t_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Discrete_distribution#Discrete_probability_distribution|discrete_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Step function|piecewise_constant_distribution]]&lt;/code&gt; and<br /> * &lt;code&gt;[[Piecewise linear function|piecewise_linear_distribution]]&lt;/code&gt;.<br /> <br /> The generator and distributions are combined as in the following example:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> #include &lt;random&gt;<br /> #include &lt;functional&gt;<br /> <br /> std::uniform_int_distribution&lt;int&gt; distribution(0, 99);<br /> std::mt19937 engine; // Mersenne twister MT19937<br /> auto generator = std::bind(distribution, engine);<br /> int random = generator(); // Generate a uniform integral variate between 0 and 99.<br /> int random2 = distribution(engine); // Generate another sample directly using the distribution and the engine objects.<br /> &lt;/source&gt;<br /> <br /> ===Wrapper reference===<br /> A [[Adapter pattern|wrapper]] reference is obtained from an instance of the template class &lt;code&gt;reference_wrapper&lt;/code&gt;. Wrapper references are similar to normal references (‘&lt;code&gt;&amp;amp;&lt;/code&gt;’) of the C++ language. To obtain a wrapper reference from any object the function template &lt;code&gt;ref&lt;/code&gt; is used (for a constant reference &lt;code&gt;cref&lt;/code&gt; is used).<br /> <br /> Wrapper references are useful above all for function templates, where references to parameters rather than copies are needed:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> // This function will obtain a reference to the parameter 'r' and increment it.<br /> void func (int &amp;r) { r++; }<br /> <br /> // Template function.<br /> template&lt;class F, class P&gt; void g (F f, P t) { f(t); }<br /> <br /> int main()<br /> {<br /> int i = 0 ;<br /> g (func, i) ; // 'g&lt;void (int &amp;r), int&gt;' is instantiated<br /> // then 'i' will not be modified.<br /> std::cout &lt;&lt; i &lt;&lt; std::endl; // Output -&gt; 0<br /> <br /> g (func, std::ref(i)); // 'g&lt;void(int &amp;r),reference_wrapper&lt;int&gt;&gt;' is instantiated<br /> // then 'i' will be modified.<br /> std::cout &lt;&lt; i &lt;&lt; std::endl; // Output -&gt; 1<br /> }<br /> &lt;/source&gt;<br /> <br /> This new utility was added to the existing &lt;code&gt;&lt;nowiki&gt;&lt;utility&gt;&lt;/nowiki&gt;&lt;/code&gt; header and didn't need further extensions of the C++ language.<br /> <br /> ===Polymorphic wrappers for function objects===<br /> [[Type polymorphism|Polymorphic]] [[Adapter pattern|wrappers]] for [[function objects]] are similar to [[function pointers]] in semantics and syntax, but are less tightly bound and can indiscriminately refer to anything which can be called (function pointers, member function pointers, or functors) whose arguments are compatible with those of the wrapper.<br /> <br /> Through the example it is possible to understand its characteristics:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> std::function&lt;int (int, int)&gt; func; // Wrapper creation using<br /> // template class 'function'.<br /> std::plus&lt;int&gt; add; // 'plus' is declared as 'template&lt;class T&gt; T plus( T, T ) ;'<br /> // then 'add' is type 'int add( int x, int y )'.<br /> func = add; // OK - Parameters and return types are the same.<br /> <br /> int a = func (1, 2); // NOTE: if the wrapper 'func' does not refer to any function,<br /> // the exception 'std::bad_function_call' is thrown.<br /> <br /> std::function&lt;bool (short, short)&gt; func2 ;<br /> if(!func2) { // True because 'func2' has not yet been assigned a function.<br /> <br /> bool adjacent(long x, long y);<br /> func2 = &amp;adjacent ; // OK - Parameters and return types are convertible.<br /> <br /> struct Test {<br /> bool operator()(short x, short y);<br /> };<br /> Test car;<br /> func = std::ref(car); // 'std::ref' is a template function that returns the wrapper<br /> // of member function 'operator()' of struct 'car'.<br /> }<br /> func = func2; // OK - Parameters and return types are convertible.<br /> &lt;/source&gt;<br /> <br /> The template class &lt;code&gt;function&lt;/code&gt; was defined inside the header &lt;code&gt;&lt;nowiki&gt;&lt;functional&gt;&lt;/nowiki&gt;&lt;/code&gt;, and didn't require any changes to the C++ language.<br /> <br /> ===Type traits for metaprogramming===<br /> [[Metaprogramming]] consists of creating a program that creates or modifies another program (or itself). This can happen during compilation or during execution. The [[C++ Standards Committee]] has decided to introduce a library that allows metaprogramming during compilation through templates.<br /> <br /> Here is an example of a meta-program, using the current C++03 standard: a [[recursion]] of template instances for calculating integer exponents:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template&lt;int B, int N&gt;<br /> struct Pow {<br /> // recursive call and recombination.<br /> enum{ value = B*Pow&lt;B, N-1&gt;::value };<br /> };<br /> <br /> template&lt; int B &gt;<br /> struct Pow&lt;B, 0&gt; {<br /> // ''N == 0'' condition of termination.<br /> enum{ value = 1 };<br /> };<br /> int quartic_of_three = Pow&lt;3, 4&gt;::value;<br /> &lt;/source&gt;<br /> <br /> Many algorithms can operate on different types of data; C++'s [[Template (programming)|template]]s support [[generic programming]] and make code more compact and useful. Nevertheless it is common for algorithms to need information on the data types being used. This information can be extracted during instantiation of a template class using '''type traits'''.<br /> <br /> '''Type traits''' can identify the category of an object and all the characteristics of a class (or of a struct). They are defined in the new header &lt;code&gt;&lt;nowiki&gt;&lt;type_traits&gt;&lt;/nowiki&gt;&lt;/code&gt;.<br /> <br /> In the next example there is the template function ‘elaborate’ that, depending on the given data types, will instantiate one of the two proposed algorithms (&lt;code&gt;algorithm.do_it&lt;/code&gt;).<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> // First way of operating.<br /> template&lt; bool B &gt; struct Algorithm {<br /> template&lt;class T1, class T2&gt; static int do_it (T1 &amp;, T2 &amp;) { /*...*/ }<br /> };<br /> <br /> // Second way of operating.<br /> template&lt;&gt; struct Algorithm&lt;true&gt; {<br /> template&lt;class T1, class T2&gt; static int do_it (T1, T2) { /*...*/ }<br /> };<br /> <br /> // Instantiating 'elaborate' will automatically instantiate the correct way to operate.<br /> template&lt;class T1, class T2&gt;<br /> int elaborate (T1 A, T2 B)<br /> {<br /> // Use the second way only if 'T1' is an integer and if 'T2' is<br /> // in floating point, otherwise use the first way.<br /> return Algorithm&lt;std::is_integral&lt;T1&gt;::value &amp;&amp; std::is_floating_point&lt;T2&gt;::value&gt;::do_it( A, B ) ;<br /> }<br /> &lt;/source&gt;<br /> <br /> Through '''type traits''', defined in header &lt;code&gt;&lt;nowiki&gt;&lt;type_transform&gt;&lt;/nowiki&gt;&lt;/code&gt;, it’s also possible to create type transformation operations (&lt;code&gt;static_cast&lt;/code&gt; and &lt;code&gt;const_cast&lt;/code&gt; are insufficient inside a template).<br /> <br /> This type of programming produces elegant and concise code; however the weak point of these techniques is the debugging: uncomfortable during compilation and very difficult during program execution.<br /> <br /> ===Uniform method for computing the return type of function objects===<br /> Determining the return type of a template function object at compile-time is not intuitive, particularly if the return value depends on the parameters of the function. As an example:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct Clear {<br /> int operator()(int) const; // The parameter type is<br /> double operator()(double) const; // equal to the return type.<br /> };<br /> <br /> template &lt;class Obj&gt;<br /> class Calculus {<br /> public:<br /> template&lt;class Arg&gt; Arg operator()(Arg&amp; a) const<br /> {<br /> return member(a);<br /> }<br /> private:<br /> Obj member;<br /> };<br /> &lt;/source&gt;<br /> <br /> Instantiating the class template &lt;code&gt;Calculus&lt;nowiki&gt;&lt;Clear&gt;&lt;/nowiki&gt;&lt;/code&gt;, the function object of &lt;code&gt;calculus&lt;/code&gt; will have always the same return type as the function object of &lt;code&gt;Clear&lt;/code&gt;. However, given class &lt;code&gt;Confused&lt;/code&gt; below:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct Confused {<br /> double operator()(int) const; // The parameter type is not<br /> int operator()(double) const; // equal to the return type.<br /> };<br /> &lt;/source&gt;<br /> Attempting to instantiate &lt;code&gt;Calculus&lt;nowiki&gt;&lt;Confused&gt;&lt;/nowiki&gt;&lt;/code&gt; will cause the return type of &lt;code&gt;Calculus&lt;/code&gt; to not be the same as that of class &lt;code&gt;Confused&lt;/code&gt;. The compiler may generate warnings about the conversion from &lt;code&gt;int&lt;/code&gt; to &lt;code&gt;double&lt;/code&gt; and vice-versa.<br /> <br /> TR1 introduces, and C++11 adopts, the template class &lt;code&gt;std::result_of&lt;/code&gt; that allows one to determine and use the return type of a function object for every declaration. The object &lt;code&gt;CalculusVer2&lt;/code&gt; uses the &lt;code&gt;std::result_of&lt;/code&gt; object to derive the return type of the function object:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template&lt; class Obj &gt;<br /> class CalculusVer2 {<br /> public:<br /> template&lt;class Arg&gt;<br /> typename std::result_of&lt;Obj(Arg)&gt;::type operator()(Arg&amp; a) const<br /> {<br /> return member(a);<br /> }<br /> private:<br /> Obj member;<br /> };<br /> &lt;/source&gt;<br /> In this way in instances of function object of &lt;code&gt;CalculusVer2&lt;nowiki&gt;&lt;Confused&gt;&lt;/nowiki&gt;&lt;/code&gt; there are no conversions, warnings, or errors.<br /> <br /> The only change from the TR1 version of &lt;code&gt;std::result_of&lt;/code&gt; is that the TR1 version allowed an implementation to fail to be able to determine the result type of a function call. Due to changes to C++ for supporting &lt;code&gt;[[#Type inference|decltype]]&lt;/code&gt;, the C++11 version of &lt;code&gt;std::result_of&lt;/code&gt; no longer needs these special cases; implementations are required to compute a type in all cases.<br /> <br /> ==Features originally planned but removed or not included==<br /> Heading for a separate TR:<br /> * [http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3347.pdf Modules]<br /> * Decimal Types<br /> * Math Special Functions<br /> Postponed:<br /> * [[Concepts (C++)|Concepts]]<br /> * More complete or required garbage collection support<br /> * Reflection<br /> * Macro Scopes<br /> <br /> ==Features removed or deprecated==<br /> * The term [[sequence point]], which is being replaced by specifying that either one operation is sequenced before another, or that two operations are unsequenced.&lt;ref&gt;{{cite web|url=http://blogs.msdn.com/b/vcblog/archive/2007/06/04/update-on-the-c-0x-language-standard.aspx|title=Update on the C++-0x Language Standard|last=Caves|first=Jonathan|date=4 June 2007|accessdate=25 May 2010}}&lt;/ref&gt;<br /> * &lt;code&gt;[[export (C++)|export]]&lt;/code&gt;&lt;ref name=&quot;sutter0310&quot;&gt;{{cite web|url=http://herbsutter.com/2010/03/13/trip-report-march-2010-iso-c-standards-meeting/|title=Trip Report: March 2010 ISO C++ Standards Meeting|last=Sutter|first=Herb|authorlink=Herb Sutter|date=3 March 2010|accessdate=24 March 2010}}&lt;/ref&gt;: Its current use is ''removed'', but the keyword itself is still reserved, for potential future use.<br /> * dynamic [[exception specification]]s&lt;ref name=&quot;sutter0310&quot;/&gt; are deprecated. Compile time specification of non-exception throwing functions is available with the &lt;code&gt;noexcept&lt;/code&gt; keyword (useful for optimization)<br /> * &lt;code&gt;[[auto ptr|std::auto_ptr]]&lt;/code&gt; is deprecated. Superseded by &lt;code&gt;std::unique_ptr&lt;/code&gt;<br /> * Function object base classes (&lt;code&gt;std::unary_function&lt;/code&gt;, &lt;code&gt;std::binary_function&lt;/code&gt;), adapters to pointers to functions and adapters to pointers to members, binder classes; these are all deprecated.<br /> <br /> ==See also==<br /> <br /> *[[C++ Technical Report 1]]<br /> *[[C99]]<br /> *[[C11_(C_standard_revision)|C11]]<br /> <br /> ==References==<br /> <br /> {{reflist}}<br /> <br /> == External links ==<br /> * [http://www.open-std.org/jtc1/sc22/wg21/ The C++ Standards Committee]<br /> * [http://www.informit.com/guides/content.aspx?g=cplusplus&amp;seqNum=216 C++0X: The New Face of Standard C++]<br /> * [http://herbsutter.wordpress.com/ Herb Sutter's blog coverage of C++11]<br /> * [http://www.justsoftwaresolutions.co.uk/cplusplus/ Anthony Williams' blog coverage of C++11]<br /> * [http://www.csclub.uwaterloo.ca/media/C++0x%20-%20An%20Overview.html A talk on C++0x given by Bjarne Stroustrup at the University of Waterloo]<br /> * [http://www.devx.com/SpecialReports/Article/38813/0/page/1 The State of the Language: An Interview with Bjarne Stroustrup (15 August 2008)]<br /> * [http://wiki.apache.org/stdcxx/C++0xCompilerSupport Wiki page to help keep track of C++ 0x core language features and their availability in compilers]<br /> * [http://en.cppreference.com Online C++11 standard library reference]<br /> <br /> {{CProLang}}<br /> <br /> [[Category:C++]]<br /> [[Category:Computer standards]]<br /> [[Category:Articles with example C++ code]]<br /> <br /> [[es:C++11]]<br /> [[fr:C++11]]<br /> [[ko:C++11]]<br /> [[it:C++11]]<br /> [[ja:C++11]]<br /> [[pl:C++11]]<br /> [[pt:C++11]]<br /> [[ru:C++11]]<br /> [[sr:Нацрт C++0x од марта 2010.]]<br /> [[fi:C++11]]<br /> [[sv:C++#Historia]]<br /> [[th:ภาษาซีพลัสพลัสโอเอกซ์]]<br /> [[uk:C++11]]<br /> [[vi:C++11]]<br /> [[zh:C++11]]</div> Code-structure https://en.wikipedia.org/w/index.php?title=AST&diff=518030767 AST 2012-10-16T00:41:34Z <p>Code-structure: Changing the layout of the page to make it similar to CST page.</p> <hr /> <div>{{Wiktionary|AST|Ast|ast}}<br /> '''AST''' is a [[three letter acronym|three-letter abbreviation]] that stands for different things.<br /> <br /> ==Science and technology==<br /> * [[Abstract syntax tree]], a finite, labeled, directed tree used in computer science<br /> * [[Andrew S. Tanenbaum]], a computer scientist (often uses this acronym as his identifier)<br /> * [[Asynchronous System Trap]]s, a mechanism used in several computer operating systems<br /> <br /> ==Medicine==<br /> * [[Aspartate transaminase]] ([[wikt:AKA|aka]] SGOT), an enzyme associated with liver parenchymal cells. AST values are checked in [[blood test]]s<br /> * Agitated saline test ([[agitated saline contrast test]]), a diagnostic heart procedure<br /> <br /> ==Mathematics==<br /> * [[Alternating series test]], a method used to prove that infinite series of terms converge<br /> * [[Alternative set theory]], an alternative mathematical approach to the concept of set<br /> <br /> ==Organisations and companies==<br /> * [[Allied Security Trust]], a [[patent holding company]]<br /> * [[AST Research]], a defunct personal computer manufacturer<br /> * [[Association for Software Testing]], a nonprofit organization dedicated to advancing software testing<br /> * [[AST (publisher)]]<br /> * AST, American Sensor Technologies, Inc., A sensor manufacturing company<br /> * AST, Airborne Surveillance Technician aboard the USAF E-3, Cooks food and delivers water to USAF crewmembers.<br /> <br /> ==Education==<br /> * [http://www.astkorea.org Association of School Teachers], a national English teachers' service provider. Non for Profit Organization. TESOL program.<br /> * [[Ameson Scholastic Test]], originally designed for Chinese students applying to the University of Cambridge in the UK, and now used by a handful of UK and Australian universities<br /> * [[ACT Scaling Test]], a series of aptitude tests taken by Year 12 students in ACT, Australia<br /> * [[Alpha Sigma Tau]], a national collegiate sorority of the United States<br /> * [[Atlantic School of Theology]], an ecumenical university in Atlantic Canada<br /> * [[Conroe ISD Academy of Science and Technology]], a specialized magnet school of science and technology in Conroe, Texas<br /> * [[Avalanche Skills Training]], a standardized form of avalanche training in Canada<br /> * [[American School of Tegucigalpa]]<br /> * [[Advanced Skills Teacher]] - a specific type of teaching role in England and Wales<br /> * Associate in Specialized Technology, a type of [[Associate's degree]]<br /> <br /> ==Politics and government==<br /> * [[Office of Commercial Space Transportation]], a branch of the US Federal Aviation Administration<br /> * [[Aviation Survival Technician]], a United States Coast Guard rating<br /> * [[Alaska State Troopers]], the state police force for the State of Alaska<br /> * [[Chadian Social Action]] (Action Sociale Tchadienne), a defunct Chadian political party<br /> <br /> ==Transport==<br /> * [[Astoria Regional Airport]], a public airport of Clatsop County, Oregon, USA (FAA Identifier: AST)<br /> * [[Aston railway station]], a railway station in Aston in Birmingham, England (National Rail code: AST)<br /> <br /> ==Time zones==<br /> * [[Atlantic Standard Time]] — [[UTC-4]]<br /> * [[Alaska Standard Time]] — [[UTC-9]]<br /> * [[Arabia Standard Time]] — [[UTC+3]]<br /> <br /> ==Other==<br /> * [[Assured shorthold tenancy]], a form of Assured tenancy with limited security of tenure<br /> * [[Asturian language]], a Romance language spoken in Asturias, Spain (ISO 639 alpha-3, ast)<br /> * [[Arsenal Supporters' Trust]], London, UK. Arsenal FC's critical friend of supporters and shareholders<br /> * [[Athlitikos Syllogos Trikala 2000 BC]], a top tier Greek basketball team<br /> * [[Astana Team]], the UCI code for the professional road bicycle racing team<br /> * Anti Structure Tandem, a type of [[tandem-charge]] where the second charge can be delayed so that it explodes deep inside the structure<br /> <br /> {{disambiguation}}<br /> [[Category:Initialisms]]<br /> <br /> [[de:Ast (Begriffsklärung)]]<br /> [[es:AST]]<br /> [[eo:AST]]<br /> [[fa:AST]]<br /> [[fr:AST]]<br /> [[ko:AST]]<br /> [[it:AST]]<br /> [[nl:AST]]<br /> [[ja:AST]]<br /> [[pl:AST]]<br /> [[pt:AST]]<br /> [[ru:АСТ]]<br /> [[sv:AST]]</div> Code-structure https://en.wikipedia.org/w/index.php?title=Memory_ordering&diff=517866229 Memory ordering 2012-10-15T04:31:35Z <p>Code-structure: Explanation of abbreviation.</p> <hr /> <div>{{Merge|Memory barrier|date=April 2010|discuss=Talk:Memory ordering}}<br /> {{Cleanup|date=November 2009}}<br /> <br /> '''Memory ordering''' is a group of properties of the modern [[microprocessor]]s, characterising their possibilities in memory operations reordering. It is a type of [[out-of-order execution]]. Memory reordering can be used to fully utilize different [[CPU cache#Cache Entries|cache]] and [[memory bank]]s.<br /> <br /> On most modern uniprocessors memory operations are not executed in the order specified by the program code. But in singlethreaded programs from the programmer's point of view, all operations appear to have been executed in the order specified, with all inconsistencies hidden by hardware.<br /> <br /> &lt;!-- == In compilers == <br /> Compilers can also reorder operations (when?) to hide memory latencies. There are memory barriers, which prevent compiler to move memory operations around it.--&gt;<br /> <br /> == In Symmetric multiprocessing (SMP) microprocessor systems ==<br /> <br /> There are several memory-consistency models for [[Symmetric multiprocessing|SMP]] systems:<br /> *sequential consistency (All reads and all writes are in-order)<br /> *relaxed consistency (Some types of reordering are allowed)<br /> ** Loads can be reordered after Loads (for better working of cache coherency, better scaling)<br /> ** Loads can be reordered after Stores<br /> ** Stores can be reordered after Stores<br /> ** Stores can be reordered after Loads<br /> *weak consistency (Reads and Writes are arbitrarily reordered, limited only by explicit [[memory barrier]]s)<br /> <br /> On some CPUs<br /> * [[atomic operation]]s can be reordered with Loads and Stores.<br /> * there can be incoherent instruction cache pipeline, which prevent [[self-modifying code]] to be executed without special ICache flush/reload instructions.<br /> * dependent loads can be reordered (this is unique for Alpha). If the processor fetches a pointer to some data after this reordering, it might not fetch the data itself but use stale data which it has already cached and not yet invalidated. Allowing this relaxation makes cache hardware simpler and faster but leads to the requirement of memory barriers for readers and writers.&lt;ref&gt;[http://www.cs.umd.edu/~pugh/java/memoryModel/AlphaReordering.html Reordering on an Alpha processor by Kourosh Gharachorloo]&lt;/ref&gt;<br /> <br /> {|class=wikitable<br /> |+ Memory ordering in some architectures &lt;ref name=&quot;mem_ord_pdf&quot;&gt;[http://www.rdrop.com/users/paulmck/scalability/paper/ordering.2007.09.19a.pdf Memory Ordering in Modern Microprocessors by Paul McKenney]&lt;/ref&gt;&lt;ref name=&quot;mem_bar&quot;&gt;[http://www.rdrop.com/users/paulmck/scalability/paper/whymb.2010.06.07c.pdf Memory Barriers: a Hardware View for Software Hackers], Figure 5 on Page 16&lt;/ref&gt;<br /> ! Type <br /> ! Alpha !! ARMv7 !! PA-RISC !! POWER !! SPARC RMO !! SPARC PSO !! SPARC TSO !! x86 !! x86 oostore !! AMD64 !! IA64 !! zSeries<br /> |-<br /> | Loads reordered after Loads<br /> | Y || Y || Y || Y || Y || || || || Y || || Y ||<br /> |-<br /> | Loads reordered after Stores<br /> | Y || Y || Y || Y || Y || || || || Y || || Y || <br /> |-<br /> | Stores reordered after Stores<br /> | Y || Y || Y || Y || Y || Y || || || Y || || Y ||<br /> |-<br /> | Stores reordered after Loads<br /> | Y || Y || Y || Y || Y || Y || Y || Y || Y || Y || Y || Y<br /> |-<br /> | Atomic reordered with Loads<br /> | Y || Y || || Y || Y || || || || || || Y ||<br /> |-<br /> | Atomic reordered with Stores<br /> | Y || Y || || Y || Y || Y || || || || || Y ||<br /> |-<br /> | Dependent Loads reordered<br /> | Y || || || || || || || || || || ||<br /> |-<br /> | Incoherent Instruction cache pipeline<br /> | Y || Y || || Y || Y || Y || Y || Y || Y || || Y || Y<br /> |}<br /> <br /> Some older x86 and AMD systems have weaker memory ordering&lt;ref name=&quot;table&quot;&gt;[http://www.linuxjournal.com/files/linuxjournal.com/linuxjournal/articles/082/8211/8211t1.inline.png Table 1. Summary of Memory Ordering], from &quot;Memory Ordering in Modern Microprocessors, Part I&quot;&lt;/ref&gt;<br /> <br /> SPARC memory ordering modes:<br /> * SPARC TSO = total-store order (default)<br /> * SPARC RMO = relaxed-memory order (not supported on recent CPUs)<br /> * SPARC PSO = partial store order (not supported on recent CPUs)<br /> <br /> == Memory barrier types ==<br /> {{See also|Memory barrier}}<br /> <br /> === Compiler memory barrier ===<br /> <br /> These barriers prevent a compiler from reordering instructions, they do not prevent reordering by CPU.<br /> <br /> * The GNU inline assembler statement<br /> asm volatile(&quot;&quot; ::: &quot;memory&quot;);<br /> or even<br /> __asm__ __volatile__ (&quot;&quot; ::: &quot;memory&quot;);<br /> forbids [[GNU Compiler Collection|GCC]] compiler to reorder read and write commands around it.&lt;ref&gt;[http://lxr.linux.no/linux+v2.6.31/include/linux/compiler-gcc.h#L12 GCC compiler-gcc.h]&lt;/ref&gt;<br /> <br /> *[[Intel C++ Compiler|Intel ECC compiler]] uses &quot;full compiler fence&quot;<br /> __memory_barrier()<br /> intrinsics.&lt;ref&gt;[http://lxr.linux.no/linux+v2.6.31/include/linux/compiler-intel.h#L16 ECC compiler-intel.h]&lt;/ref&gt;&lt;ref&gt;[http://software.intel.com/file/6373 Intel(R) C++ Compiler Intrinsics Reference]<br /> &lt;blockquote&gt;Creates a barrier across which the compiler will not schedule any data access instruction. The compiler may allocate local data in registers across a memory barrier, but not global data.&lt;/blockquote&gt;&lt;/ref&gt;<br /> <br /> * [[Microsoft Visual C++]] Compiler:&lt;ref&gt;Visual C++ Language Reference [http://msdn.microsoft.com/en-us/library/f20w0x5e(VS.80).aspx _ReadWriteBarrier]&lt;/ref&gt;<br /> _ReadWriteBarrier()<br /> <br /> === Hardware memory barrier ===<br /> Many architectures with SMP support have special hardware instruction for flushing reads and writes.<br /> <br /> *[[x86]], [[x86-64]]<br /> lfence (asm), void_mm_lfence(void)<br /> sfence (asm), void_mm_sfence(void) &lt;ref name=&quot;vtune-sfence&quot;&gt;[http://www.softeng.rl.ac.uk/st/archive/SoftEng/SESP/html/SoftwareTools/vtune/users_guide/mergedProjects/analyzer_ec/mergedProjects/reference_olh/mergedProjects/instructions/instruct32_hh/vc287.htm SFENCE &amp;mdash; Store Fence]&lt;/ref&gt;<br /> mfence (asm), void_mm_mfence(void) &lt;ref name=&quot;vtune-mfence&quot;&gt;[http://www.softeng.rl.ac.uk/st/archive/SoftEng/SESP/html/SoftwareTools/vtune/users_guide/mergedProjects/analyzer_ec/mergedProjects/reference_olh/mergedProjects/instructions/instruct32_hh/vc172.htm MFENCE &amp;mdash; Memory Fence]&lt;/ref&gt;<br /> <br /> *[[PowerPC]]<br /> sync (asm)<br /> <br /> *[[IBM POWER|POWER]]<br /> dcs (asm)<br /> <br /> *[[ARMv7]]<br /> dmb (asm)<br /> <br /> === Compiler support for hardware memory barriers ===<br /> Some compilers support [[intrinsic function|builtins]] that emit hardware memory barrier instructions:<br /> <br /> *[[GNU Compiler Collection|GCC]]&lt;ref&gt;[http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html Atomic Builtins]&lt;/ref&gt;, version 4.4.0 and later&lt;ref&gt;http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36793&lt;/ref&gt;, has &lt;code&gt;__sync_synchronize&lt;/code&gt;.<br /> *The [[Microsoft Visual C++]] compiler&lt;ref&gt;[http://msdn.microsoft.com/en-us/library/windows/desktop/ms684208(v=vs.85).aspx MemoryBarrier macro]&lt;/ref&gt; has &lt;code&gt;MemoryBarrier()&lt;/code&gt;.<br /> *[[Sun Studio Compiler Suite]]&lt;ref&gt;Handling Memory Ordering in Multithreaded Applications with Oracle Solaris Studio 12 Update 2: Part 2, Memory Barriers and Memory Fence [http://www.oracle.com/technetwork/server-storage/solarisstudio/documentation/oss-memory-barriers-fences-176056.pdf]&lt;/ref&gt; has &lt;code&gt;__machine_r_barrier&lt;/code&gt;, &lt;code&gt;__machine_w_barrier&lt;/code&gt; and &lt;code&gt;__machine_rw_barrier&lt;/code&gt;.<br /> <br /> ==See also ==<br /> * [[Memory model (programming)]]<br /> * [[Memory barrier]]<br /> <br /> == References ==<br /> &lt;references/&gt;<br /> <br /> == Further reading ==<br /> * ''Computer Architecture &amp;mdash; A quantitative approach''. 4th edition. J Hennessy, D Patterson, 2007. Chapter 4.6<br /> * Sarita V. Adve, Kourosh Gharachorloo, [http://www.cs.uiuc.edu/class/sp08/cs533/reading_list/adve95shared.pdf Shared Memory Consistency Models: A Tutorial]<br /> * [http://www.intel.com/products/processor/manuals/318147.pdf Intel 64 Architecture Memory Ordering White Paper]<br /> * [http://www.linuxjournal.com/article/8211 Memory ordering in Modern Microprocessors part 1]<br /> * [http://www.linuxjournal.com/article/8212 Memory ordering in Modern Microprocessors part 2]<br /> * {{YouTube|id=WUfvvFD5tAA|title=IA (Intel Architecture) Memory Ordering}} - [[AtGoogleTalks|Google Tech Talk]]<br /> <br /> [[Category:Computer architecture]]<br /> [[Category:Computer memory]]<br /> [[Category:Consistency models]]<br /> [[Category:Compiler construction]]<br /> [[Category:Programming language design]]<br /> [[Category:Run-time systems]]<br /> [[Category:Concurrency (computer science)]]</div> Code-structure https://en.wikipedia.org/w/index.php?title=User:Code-structure/sandbox&diff=517856729 User:Code-structure/sandbox 2012-10-15T03:20:45Z <p>Code-structure: </p> <hr /> <div>&lt;!-- EDIT BELOW THIS LINE --&gt;<br /> Grammar of the '''C++''' language is available as part of the standard.<br /> <br /> abra-cadabra before [[Image:Wikipedia-Redirect-HelpScreenShot-01.jpg|alt=Redirect help|Dummy caption]] abra-cadabra after<br /> <br /> Some text line1.<br /> Some text line2.<br /> Some text line3.<br /> <br /> [[File:Wikipedia-Redirect-HelpScreenShot-01.jpg|thumb|Little caption.]]<br /> <br /> <br /> [[User:Code-structure/sandbox/conflicts resolution]]<br /> <br /> '''Fragment''' **Frag**<br /> <br /> ''gggg'' //Frag//<br /> <br /> |=|=table|=header|<br /> |a|123|qqq|</div> Code-structure https://en.wikipedia.org/w/index.php?title=User:Code-structure/sandbox&diff=517856371 User:Code-structure/sandbox 2012-10-15T03:18:29Z <p>Code-structure: </p> <hr /> <div>&lt;!-- EDIT BELOW THIS LINE --&gt;<br /> Grammar of the '''C++''' language is available as part of the standard.<br /> <br /> abra-cadabra before [[File:Wikipedia-Redirect-HelpScreenShot-01.jpg|alt=Redirect help|Dummy caption]] abra-cadabra after<br /> <br /> Some text.<br /> <br /> [[File:Wikipedia-Redirect-HelpScreenShot-01.jpg|thumb|Little caption.]]<br /> <br /> <br /> [[User:Code-structure/sandbox/conflicts resolution]]<br /> <br /> '''Fragment''' **Frag**<br /> <br /> ''gggg'' //Frag//<br /> <br /> |=|=table|=header|<br /> |a|123|qqq|</div> Code-structure https://en.wikipedia.org/w/index.php?title=User:Code-structure/sandbox&diff=517856202 User:Code-structure/sandbox 2012-10-15T03:17:22Z <p>Code-structure: </p> <hr /> <div>&lt;!-- EDIT BELOW THIS LINE --&gt;<br /> Grammar of the '''C++''' language is available as part of the standard.<br /> <br /> abra-cadabra before [[File:Wikipedia-Redirect-HelpScreenShot-01.jpg|alt=Redirect help|Dummy caption]] abra-cadabra after<br /> <br /> Some text.<br /> <br /> [[File:Wikipedia-Redirect-HelpScreenShot-01.jpg|thumb]]<br /> <br /> <br /> [[User:Code-structure/sandbox/conflicts resolution]]<br /> <br /> '''Fragment''' **Frag**<br /> <br /> ''gggg'' //Frag//<br /> <br /> |=|=table|=header|<br /> |a|123|qqq|</div> Code-structure https://en.wikipedia.org/w/index.php?title=User:Code-structure/sandbox&diff=517855886 User:Code-structure/sandbox 2012-10-15T03:15:22Z <p>Code-structure: </p> <hr /> <div>&lt;!-- EDIT BELOW THIS LINE --&gt;<br /> Grammar of the '''C++''' language is available as part of the standard.<br /> <br /> abra-cadabra before [[File:Wikipedia-Redirect-HelpScreenShot-01.jpg]] abra-cadabra after<br /> <br /> Some text.<br /> <br /> [[File:Wikipedia-Redirect-HelpScreenShot-01.jpg|thumb]]<br /> <br /> <br /> [[User:Code-structure/sandbox/conflicts resolution]]<br /> <br /> '''Fragment''' **Frag**<br /> <br /> ''gggg'' //Frag//<br /> <br /> |=|=table|=header|<br /> |a|123|qqq|</div> Code-structure https://en.wikipedia.org/w/index.php?title=User:Code-structure/sandbox&diff=517855788 User:Code-structure/sandbox 2012-10-15T03:14:41Z <p>Code-structure: </p> <hr /> <div>&lt;!-- EDIT BELOW THIS LINE --&gt;<br /> Grammar of the '''C++''' language is available as part of the standard.<br /> <br /> abra-cadabra before [[File:Wikipedia-Redirect-HelpScreenShot-01.jpg]] abra-cadabra after<br /> <br /> [[User:Code-structure/sandbox/conflicts resolution]]<br /> <br /> '''Fragment''' **Frag**<br /> <br /> ''gggg'' //Frag//<br /> <br /> |=|=table|=header|<br /> |a|123|qqq|</div> Code-structure https://en.wikipedia.org/w/index.php?title=User:Code-structure/sandbox&diff=517855694 User:Code-structure/sandbox 2012-10-15T03:14:08Z <p>Code-structure: </p> <hr /> <div>&lt;!-- EDIT BELOW THIS LINE --&gt;<br /> Grammar of the '''C++''' language is available as part of the standard.<br /> <br /> [[File:Wikipedia-Redirect-HelpScreenShot-01.jpg]]<br /> <br /> [[User:Code-structure/sandbox/conflicts resolution]]<br /> <br /> '''Fragment''' **Frag**<br /> <br /> ''gggg'' //Frag//<br /> <br /> |=|=table|=header|<br /> |a|123|qqq|</div> Code-structure https://en.wikipedia.org/w/index.php?title=User:Code-structure/sandbox&diff=517854134 User:Code-structure/sandbox 2012-10-15T03:04:10Z <p>Code-structure: </p> <hr /> <div>&lt;!-- EDIT BELOW THIS LINE --&gt;<br /> Grammar of the '''C++''' language is available as part of the standard.<br /> <br /> [[File::Wikipedia-Redirect-HelpScreenShot-01.jpg|thumbnail]]<br /> <br /> [[User:Code-structure/sandbox/conflicts resolution]]<br /> <br /> '''Fragment''' **Frag**<br /> <br /> ''gggg'' //Frag//<br /> <br /> |=|=table|=header|<br /> |a|123|qqq|</div> Code-structure https://en.wikipedia.org/w/index.php?title=File:Wikipedia-Redirect-HelpScreenShot-01.jpg&diff=517852689 File:Wikipedia-Redirect-HelpScreenShot-01.jpg 2012-10-15T02:53:58Z <p>Code-structure: Simple screen shot from the screen of my PC to improve the Wikipedia help page.</p> <hr /> <div>== Summary ==<br /> Simple screen shot from the screen of my PC to improve the Wikipedia help page.<br /> == Licensing ==<br /> {{PD-text}}</div> Code-structure https://en.wikipedia.org/w/index.php?title=Template:Db-u1/doc&diff=517847073 Template:Db-u1/doc 2012-10-15T02:13:42Z <p>Code-structure: Dot at the end.</p> <hr /> <div>{{Documentation subpage}}<br /> &lt;!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE. --&gt;<br /> {{Speedy deletion templates}}<br /> {{Twinkle standard installation}}<br /> {{template shortcut|db-u1|db-userreq}}<br /> <br /> This template is used to tag pages for speedy deletion under the [[Wikipedia:Criteria for speedy deletion|speedy deletion criteria]], specifically [[Wikipedia:Criteria for speedy deletion#U1|CSD U1]]. There is a separate template for each criterion &amp;ndash; see the table to the right.<br /> <br /> This template places the page into the categories: [[:Category:Candidates for speedy deletion|Candidates for speedy deletion]], and [[:Category:Candidates for speedy deletion by user|Candidates for speedy deletion by user]].<br /> <br /> == Usage ==<br /> The template should be placed at the top of the page to be deleted.<br /> <br /> ===Parameters===<br /> &lt;tt&gt;&lt;nowiki&gt;{{&lt;/nowiki&gt;db-u1&lt;nowiki&gt;}}&lt;/nowiki&gt;&lt;/tt&gt;<br /> <br /> :This is the most basic form of the template.<br /> <br /> &lt;tt&gt;&lt;nowiki&gt;{{&lt;/nowiki&gt;db-u1&lt;nowiki&gt;|bot=ExampleBot&lt;/nowiki&gt;&lt;nowiki&gt;}}&lt;/nowiki&gt;&lt;/tt&gt;<br /> <br /> :[[WP:BOT|Bot accounts]] will specify the &lt;code&gt;&lt;nowiki&gt;|bot=&lt;/nowiki&gt;&lt;/code&gt; parameter to notify the reviewing admin that the page was tagged by an automated process.&lt;br&gt;<br /> &lt;tt&gt;&lt;nowiki&gt;{{&lt;/nowiki&gt;db-u1&lt;nowiki&gt;|&lt;/nowiki&gt;diff=''Diff#''&lt;nowiki&gt;}}&lt;/nowiki&gt;&lt;/tt&gt;<br /> <br /> :Where ''Diff#'' is a [[Help:Diff|diff]] showing where the user requested deletion. This is obviously not required if the user places the template, or if the deletion request is on the listed page.<br /> <br /> ==See also==<br /> *{{tl|db-author}} - G7. Author requests deletion.<br /> *[[Wikipedia:Criteria for speedy deletion]]<br /> *[[Wikipedia:Deletion policy]]<br /> *[[Wikipedia:Deletion process]]<br /> *[[Wikipedia:Deletion review]]<br /> *[[Wikipedia:Template messages/User talk namespace]]<br /> &lt;includeonly&gt;<br /> <br /> &lt;!-- CATEGORIES AND INTERWIKIS HERE, THANKS --&gt;<br /> [[Category:Speedy deletion templates|U1]]<br /> <br /> <br /> &lt;/includeonly&gt;</div> Code-structure https://en.wikipedia.org/w/index.php?title=User:Code-structure/sandbox/conflicts_resolution&diff=517846452 User:Code-structure/sandbox/conflicts resolution 2012-10-15T02:09:31Z <p>Code-structure: ←Created page with &#039;Context free grammars may have 2 types of conflicts: *Shift-Reduce *Reduce-Reduce&#039;</p> <hr /> <div>Context free grammars may have 2 types of conflicts:<br /> *Shift-Reduce<br /> *Reduce-Reduce</div> Code-structure https://en.wikipedia.org/w/index.php?title=User:Code-structure/sandbox&diff=517846300 User:Code-structure/sandbox 2012-10-15T02:08:23Z <p>Code-structure: </p> <hr /> <div>&lt;!-- EDIT BELOW THIS LINE --&gt;<br /> Grammar of the '''C++''' language is available as part of the standard.<br /> <br /> [[File:Ddf|thumbnail]]<br /> <br /> [[User:Code-structure/sandbox/conflicts resolution]]<br /> <br /> '''Fragment''' **Frag**<br /> <br /> ''gggg'' //Frag//<br /> <br /> |=|=table|=header|<br /> |a|123|qqq|</div> Code-structure https://en.wikipedia.org/w/index.php?title=Wikipedia:Content_forks&diff=517845295 Wikipedia:Content forks 2012-10-15T02:01:02Z <p>Code-structure: Typo, my bad.</p> <hr /> <div>{{subcat guideline|content guideline|Forking|WP:CFORK|WP:CONTENTFORK|WP:CONTENTFORKING}}<br /> {{Guideline in a nutshell|Articles should not be split into multiple articles just so each can advocate a different stance on the subject.}}<br /> <br /> A '''content fork''' is the creation of multiple separate articles all treating the same subject. Content forks that are created unintentionally result in redundant or conflicting articles and are to be avoided. On the other hand, as an article grows, editors often create [[WP:Summary style|Summary style]] spin-offs or new, linked article for related material. This is acceptable, and often encouraged, as a way of making articles clearer and easier to manage.<br /> <br /> A '''point of view (POV) fork''' is a content fork deliberately created to avoid [[WP:NPOV|neutral point of view]] guidelines, often to avoid or highlight negative or positive viewpoints or facts. All POV forks are undesirable on Wikipedia, as they avoid consensus building and therefore violate one of our most important policies.<br /> <br /> ==Unacceptable types of forking==<br /> <br /> ====Redundant content forks====<br /> {{shortcut|WP:REDUNDANTFORK}}<br /> Content forking can be unintentional or intentional. While Wikipedia contributors are reminded to check to make sure there is not an existing article on the subject before they start a new article, there is always the chance they will forget, or that they will search in good faith but fail to find an existing article, or simply flesh out a derivative article rather than the main article on a topic. Wikipedia's principle of [[Wikipedia:assume good faith|assume good faith]] should be kept in mind here. If you suspect a content fork, give the creator of a duplicate article the benefit of the doubt. Check with people who watch the respective articles and participate in talk page discussions to see if the fork was deliberate. If the content fork was unjustified, the more recent article should be [[WP:MERGE|merge]]d back into the main article.<br /> <br /> ====Point of view (POV) forks====<br /> {{shortcut|WP:POVFORK|WP:POVSPLIT}}<br /> In contrast, POV forks generally arise when contributors disagree about the content of an article or other page. Instead of resolving that disagreement by consensus, another version of the article (or another article on the same subject) is created to be developed according to a particular [[WP:POV|point of view]]. This second article is known as a &quot;POV fork&quot; of the first, and is inconsistent with Wikipedia policies. The generally accepted policy is that all facts and major points of view on a certain subject should be treated in one article. As Wikipedia does ''not'' view article forking as an acceptable solution to disagreements between contributors, such forks may be [[Help:Merging and moving pages|merged]], or nominated for [[Wikipedia:Articles for deletion|deletion]].<br /> <br /> Since what qualifies as a &quot;POV fork&quot; is itself based on a POV judgement, do not refer to forks as &quot;POV&quot; except in extreme cases of persistent disruptive editing. Instead, apply Wikipedia's policy that requires a [[WP:NPOV|neutral point of view]]: regardless of the reasons for making the fork, it still must be titled and written in a neutral point of view. It could be that the fork was a good idea, but was approached without balance, or that its creators mistakenly claimed [[WP:OWN|ownership]] over it.<br /> <br /> The most blatant POV forks are those which insert consensus-dodging content under a title that should clearly be made a redirect to an existing article; in some cases, editors have even converted existing redirects into content forks. However, a new article can be a POV fork even if its title is not a synonym of an existing article's title. If one has tried to include one's personal theory that [[heavier-than-air flight]] is impossible in an existing article about [[aviation]], but the consensus of editors has rejected it as [[WP:patent nonsense|patent nonsense]], that does not justify creating an article named &quot;Unanswered questions about heavier-than-air flight&quot; to expound the rejected personal theory.<br /> <br /> The creator of the new article may be sincerely convinced that there is so much information about a certain aspect of a subject that it justifies a separate article. Any daughter article that deals with opinions about the subject of parent article '''must''' include suitably-[[WP:WEIGHT|weight]]ed positive and negative opinions, and/or rebuttals, if available, and the original article should contain a neutral summary of the split article. There is currently no consensus whether a &quot;Criticism of...&quot; article is always a POV fork, but many criticism articles nevertheless suffer from POV problems. If possible, refrain from using &quot;criticism&quot; and instead use neutral terms such as &quot;perception&quot; or &quot;reception&quot;; if the word &quot;criticism&quot; must be used, make sure that such criticism considers both the merits '''and''' faults, and is not entirely negative (consider what would happen if a &quot;Praise of...&quot; article was created instead).<br /> <br /> ==Acceptable types of forking==<br /> <br /> There are things that occur from time to time that may be mistaken for content forking.<br /> <br /> Note that meeting one of the descriptions listed here does not mean that something is '''not''' a content fork&amp;nbsp;– only that it is not ''necessarily'' a content fork.<br /> <br /> ===Project-level forking===<br /> {{main|Wikipedia:Mirrors and forks}}<br /> <br /> There is a difference between article forking within Wikipedia and the legitimate practice of project-level forking. The latter occurs when someone wishes to create their own wiki, according to their own standards and practices, but they want to use Wikipedia's content as a starting place. As long as the new project adheres to their legal obligations under the [[CC-BY-SA]] or [[GFDL]] in exchange for use of this content, as set out at [[WP:C|Wikipedia's copyright policy]], this is perfectly acceptable. Project-level forks are not bound in any way by Wikipedia's community policies or customs, like the [[WP:5P|five pillars]]. Project-level forking is discussed in more detail at [[Wikipedia:Forking FAQ]].<br /> <br /> ===Article spinouts: &quot;Summary style&quot; articles===<br /> {{details|Wikipedia:Summary style}}<br /> {{shortcut|WP:SPINOFF}}<br /> Sometimes, when an article gets long (see [[Wikipedia:Article size]]), a section of the article is made into its own article, and the handling of the subject in the main article is condensed to a brief summary. This is completely normal Wikipedia procedure. The new article is sometimes called a &quot;spinout&quot; or &quot;spinoff&quot; of the main article; [[Wikipedia:Summary style]] explains the technique.<br /> <br /> Even if the subject of the new article is controversial, this does '''not''' automatically make the new article a POV fork. However, the moved material ''must be'' replaced with an NPOV summary of that material. If it is not, then the &quot;spinning out&quot; is really a clear act of POV forking: a new article has been created so that the main article can favor some viewpoints over others.<br /> <br /> Summary style articles, with sub-articles giving greater detail, are not POV forking, provided that all the sub-articles, and the summary, conform to [[WP:NPOV|Neutral Point of View]]. Essentially, it is generally acceptable to have different levels of detail of a subject on different pages, provided that each provides a balanced view of the subject matter. This can happen when a particular controversial incident gets a lot of attention from editors representing different points of view, expanding until every item of evidence is included and referenced. This kind of detailed examination of a single incident in a general article will usually be considered to give Undue Weight to the incident so it is more appropriate to break that section out as a separate section and just have a summary in the main article.<br /> <br /> However, it is possible for article spinouts to become POV forks. If a statement is inadmissible for content policy reasons at an article &lt;nowiki&gt;[[XYZ]]&lt;/nowiki&gt;, then it is also inadmissible at a spinout &lt;nowiki&gt;[[Criticism of XYZ]]&lt;/nowiki&gt;. Spinouts are intended to improve readability and navigation, not to evade Wikipedia's content policies.<br /> <br /> ===Articles whose subject is a POV===<br /> {{Shortcut|WP:SUBPOV}}<br /> Different articles can be legitimately created on subjects which themselves represent points of view, as long as the title clearly indicates what its subject is, the point-of-view subject is presented [[WP:NPOV|neutrally]], and each article cross-references articles on other appropriate points of view. Thus [[Evolution]] and [[Creationism]], [[Capitalism]] and [[Communism]], [[Biblical literalism]] and [[Biblical criticism]], etc., all represent legitimate article subjects. As noted above, &quot;Criticism of&quot; type articles should generally start as sections of the main article and be spun off by agreement among the editors.<br /> <br /> ===Related articles===<br /> {{shortcut|WP:RELART}}<br /> Articles on distinct but related topics may well contain a significant amount of information in common with one another. This does not make either of the two articles a content fork. As an example, clearly [[Joséphine de Beauharnais]] will contain a significant amount of information also in [[Napoleon I of France]]; this does not make it a fork. Another example is where two articles cover the same topic, but are clearly ''directed at different audiences''. In such cases, one of the articles will be prefixed by the text [[Wikipedia:Make technical articles understandable#&quot;Introduction to...&quot; articles|&quot;Introduction to ...&quot;]], for example [[General relativity]] and [[Introduction to general relativity]].<br /> <br /> Further, in encyclopedias it is perfectly proper to have separate articles for each '''different''' definition of a ''term''; unlike dictionaries, a single [[encyclopedia article]] covers a ''topic'', not a ''term''.<br /> <br /> ===Temporary subpages===<br /> {{main|Wikipedia:Subpages}}<br /> <br /> One technique sometimes used to reach consensus on difficult articles is to create a temporary copy which people can then edit to show others proposed rephrasing or other changes. This can be helpful for controversial subjects or controversial changes; editors can show others exactly what their vision for a proposed change is&amp;nbsp;– without the controversy of having that new proposed version automatically replace the existing version.<br /> <br /> However, just as &quot;spinout&quot; articles have sometimes been mistaken for POV forks, temporary subpages have been mistaken for POV forks. Care should be taken on both sides to minimize such mistakes. New drafts should be written in the &quot;user:&quot; or &quot;talk:&quot; [[wikipedia:namespace|namespace]] and '''not in the [[main namespace]]'''; however, accidents happen and those who think they have found a POV fork, in turn, should check to see whether the article title indicates a temporary subpage and whether the talk page of the main article indicates that this is a place to work on consensus rather than to dodge it.<br /> <br /> ==See also==<br /> * [[Wikipedia:Be neutral in form]]<br /> * [[Wikipedia:Criticism]] (essay on the way criticism can be included in Wikipedia articles)<br /> * [[Wikipedia:Splitting]]<br /> * [[Wikipedia:Tendentious editing]]<br /> * [[Wikipedia:Forking isn't as harmful as we think]]<br /> <br /> <br /> <br /> [[Category:Wikipedia neutral point of view]]<br /> <br /> [[af:Wikipedia:Duplikate]]<br /> [[ar:ويكيبيديا:تشعب وجهات النظر]]<br /> [[fa:ویکی‌پدیا:انشعاب محتوا]]<br /> [[kk:Уикипедия:Мақаланы жеке мақалаларға бөлу]]<br /> [[no:Wikipedia:Artikkelforgrening]]<br /> [[ru:Википедия:Ответвление мнений]]<br /> [[zh:Wikipedia:內容分歧]]</div> Code-structure https://en.wikipedia.org/w/index.php?title=Wikipedia:Content_forks&diff=517845239 Wikipedia:Content forks 2012-10-15T02:00:38Z <p>Code-structure: Duplicate the unabbreviation because when somebody comes to this section by direct link the explanation above is scrolled out.</p> <hr /> <div>{{subcat guideline|content guideline|Forking|WP:CFORK|WP:CONTENTFORK|WP:CONTENTFORKING}}<br /> {{Guideline in a nutshell|Articles should not be split into multiple articles just so each can advocate a different stance on the subject.}}<br /> <br /> A '''content fork''' is the creation of multiple separate articles all treating the same subject. Content forks that are created unintentionally result in redundant or conflicting articles and are to be avoided. On the other hand, as an article grows, editors often create [[WP:Summary style|Summary style]] spin-offs or new, linked article for related material. This is acceptable, and often encouraged, as a way of making articles clearer and easier to manage.<br /> <br /> A '''point of view (POV) fork''' is a content fork deliberately created to avoid [[WP:NPOV|neutral point of view]] guidelines, often to avoid or highlight negative or positive viewpoints or facts. All POV forks are undesirable on Wikipedia, as they avoid consensus building and therefore violate one of our most important policies.<br /> <br /> ==Unacceptable types of forking==<br /> <br /> ====Redundant content forks====<br /> {{shortcut|WP:REDUNDANTFORK}}<br /> Content forking can be unintentional or intentional. While Wikipedia contributors are reminded to check to make sure there is not an existing article on the subject before they start a new article, there is always the chance they will forget, or that they will search in good faith but fail to find an existing article, or simply flesh out a derivative article rather than the main article on a topic. Wikipedia's principle of [[Wikipedia:assume good faith|assume good faith]] should be kept in mind here. If you suspect a content fork, give the creator of a duplicate article the benefit of the doubt. Check with people who watch the respective articles and participate in talk page discussions to see if the fork was deliberate. If the content fork was unjustified, the more recent article should be [[WP:MERGE|merge]]d back into the main article.<br /> <br /> ====Point of view (POOV) forks====<br /> {{shortcut|WP:POVFORK|WP:POVSPLIT}}<br /> In contrast, POV forks generally arise when contributors disagree about the content of an article or other page. Instead of resolving that disagreement by consensus, another version of the article (or another article on the same subject) is created to be developed according to a particular [[WP:POV|point of view]]. This second article is known as a &quot;POV fork&quot; of the first, and is inconsistent with Wikipedia policies. The generally accepted policy is that all facts and major points of view on a certain subject should be treated in one article. As Wikipedia does ''not'' view article forking as an acceptable solution to disagreements between contributors, such forks may be [[Help:Merging and moving pages|merged]], or nominated for [[Wikipedia:Articles for deletion|deletion]].<br /> <br /> Since what qualifies as a &quot;POV fork&quot; is itself based on a POV judgement, do not refer to forks as &quot;POV&quot; except in extreme cases of persistent disruptive editing. Instead, apply Wikipedia's policy that requires a [[WP:NPOV|neutral point of view]]: regardless of the reasons for making the fork, it still must be titled and written in a neutral point of view. It could be that the fork was a good idea, but was approached without balance, or that its creators mistakenly claimed [[WP:OWN|ownership]] over it.<br /> <br /> The most blatant POV forks are those which insert consensus-dodging content under a title that should clearly be made a redirect to an existing article; in some cases, editors have even converted existing redirects into content forks. However, a new article can be a POV fork even if its title is not a synonym of an existing article's title. If one has tried to include one's personal theory that [[heavier-than-air flight]] is impossible in an existing article about [[aviation]], but the consensus of editors has rejected it as [[WP:patent nonsense|patent nonsense]], that does not justify creating an article named &quot;Unanswered questions about heavier-than-air flight&quot; to expound the rejected personal theory.<br /> <br /> The creator of the new article may be sincerely convinced that there is so much information about a certain aspect of a subject that it justifies a separate article. Any daughter article that deals with opinions about the subject of parent article '''must''' include suitably-[[WP:WEIGHT|weight]]ed positive and negative opinions, and/or rebuttals, if available, and the original article should contain a neutral summary of the split article. There is currently no consensus whether a &quot;Criticism of...&quot; article is always a POV fork, but many criticism articles nevertheless suffer from POV problems. If possible, refrain from using &quot;criticism&quot; and instead use neutral terms such as &quot;perception&quot; or &quot;reception&quot;; if the word &quot;criticism&quot; must be used, make sure that such criticism considers both the merits '''and''' faults, and is not entirely negative (consider what would happen if a &quot;Praise of...&quot; article was created instead).<br /> <br /> ==Acceptable types of forking==<br /> <br /> There are things that occur from time to time that may be mistaken for content forking.<br /> <br /> Note that meeting one of the descriptions listed here does not mean that something is '''not''' a content fork&amp;nbsp;– only that it is not ''necessarily'' a content fork.<br /> <br /> ===Project-level forking===<br /> {{main|Wikipedia:Mirrors and forks}}<br /> <br /> There is a difference between article forking within Wikipedia and the legitimate practice of project-level forking. The latter occurs when someone wishes to create their own wiki, according to their own standards and practices, but they want to use Wikipedia's content as a starting place. As long as the new project adheres to their legal obligations under the [[CC-BY-SA]] or [[GFDL]] in exchange for use of this content, as set out at [[WP:C|Wikipedia's copyright policy]], this is perfectly acceptable. Project-level forks are not bound in any way by Wikipedia's community policies or customs, like the [[WP:5P|five pillars]]. Project-level forking is discussed in more detail at [[Wikipedia:Forking FAQ]].<br /> <br /> ===Article spinouts: &quot;Summary style&quot; articles===<br /> {{details|Wikipedia:Summary style}}<br /> {{shortcut|WP:SPINOFF}}<br /> Sometimes, when an article gets long (see [[Wikipedia:Article size]]), a section of the article is made into its own article, and the handling of the subject in the main article is condensed to a brief summary. This is completely normal Wikipedia procedure. The new article is sometimes called a &quot;spinout&quot; or &quot;spinoff&quot; of the main article; [[Wikipedia:Summary style]] explains the technique.<br /> <br /> Even if the subject of the new article is controversial, this does '''not''' automatically make the new article a POV fork. However, the moved material ''must be'' replaced with an NPOV summary of that material. If it is not, then the &quot;spinning out&quot; is really a clear act of POV forking: a new article has been created so that the main article can favor some viewpoints over others.<br /> <br /> Summary style articles, with sub-articles giving greater detail, are not POV forking, provided that all the sub-articles, and the summary, conform to [[WP:NPOV|Neutral Point of View]]. Essentially, it is generally acceptable to have different levels of detail of a subject on different pages, provided that each provides a balanced view of the subject matter. This can happen when a particular controversial incident gets a lot of attention from editors representing different points of view, expanding until every item of evidence is included and referenced. This kind of detailed examination of a single incident in a general article will usually be considered to give Undue Weight to the incident so it is more appropriate to break that section out as a separate section and just have a summary in the main article.<br /> <br /> However, it is possible for article spinouts to become POV forks. If a statement is inadmissible for content policy reasons at an article &lt;nowiki&gt;[[XYZ]]&lt;/nowiki&gt;, then it is also inadmissible at a spinout &lt;nowiki&gt;[[Criticism of XYZ]]&lt;/nowiki&gt;. Spinouts are intended to improve readability and navigation, not to evade Wikipedia's content policies.<br /> <br /> ===Articles whose subject is a POV===<br /> {{Shortcut|WP:SUBPOV}}<br /> Different articles can be legitimately created on subjects which themselves represent points of view, as long as the title clearly indicates what its subject is, the point-of-view subject is presented [[WP:NPOV|neutrally]], and each article cross-references articles on other appropriate points of view. Thus [[Evolution]] and [[Creationism]], [[Capitalism]] and [[Communism]], [[Biblical literalism]] and [[Biblical criticism]], etc., all represent legitimate article subjects. As noted above, &quot;Criticism of&quot; type articles should generally start as sections of the main article and be spun off by agreement among the editors.<br /> <br /> ===Related articles===<br /> {{shortcut|WP:RELART}}<br /> Articles on distinct but related topics may well contain a significant amount of information in common with one another. This does not make either of the two articles a content fork. As an example, clearly [[Joséphine de Beauharnais]] will contain a significant amount of information also in [[Napoleon I of France]]; this does not make it a fork. Another example is where two articles cover the same topic, but are clearly ''directed at different audiences''. In such cases, one of the articles will be prefixed by the text [[Wikipedia:Make technical articles understandable#&quot;Introduction to...&quot; articles|&quot;Introduction to ...&quot;]], for example [[General relativity]] and [[Introduction to general relativity]].<br /> <br /> Further, in encyclopedias it is perfectly proper to have separate articles for each '''different''' definition of a ''term''; unlike dictionaries, a single [[encyclopedia article]] covers a ''topic'', not a ''term''.<br /> <br /> ===Temporary subpages===<br /> {{main|Wikipedia:Subpages}}<br /> <br /> One technique sometimes used to reach consensus on difficult articles is to create a temporary copy which people can then edit to show others proposed rephrasing or other changes. This can be helpful for controversial subjects or controversial changes; editors can show others exactly what their vision for a proposed change is&amp;nbsp;– without the controversy of having that new proposed version automatically replace the existing version.<br /> <br /> However, just as &quot;spinout&quot; articles have sometimes been mistaken for POV forks, temporary subpages have been mistaken for POV forks. Care should be taken on both sides to minimize such mistakes. New drafts should be written in the &quot;user:&quot; or &quot;talk:&quot; [[wikipedia:namespace|namespace]] and '''not in the [[main namespace]]'''; however, accidents happen and those who think they have found a POV fork, in turn, should check to see whether the article title indicates a temporary subpage and whether the talk page of the main article indicates that this is a place to work on consensus rather than to dodge it.<br /> <br /> ==See also==<br /> * [[Wikipedia:Be neutral in form]]<br /> * [[Wikipedia:Criticism]] (essay on the way criticism can be included in Wikipedia articles)<br /> * [[Wikipedia:Splitting]]<br /> * [[Wikipedia:Tendentious editing]]<br /> * [[Wikipedia:Forking isn't as harmful as we think]]<br /> <br /> <br /> <br /> [[Category:Wikipedia neutral point of view]]<br /> <br /> [[af:Wikipedia:Duplikate]]<br /> [[ar:ويكيبيديا:تشعب وجهات النظر]]<br /> [[fa:ویکی‌پدیا:انشعاب محتوا]]<br /> [[kk:Уикипедия:Мақаланы жеке мақалаларға бөлу]]<br /> [[no:Wikipedia:Artikkelforgrening]]<br /> [[ru:Википедия:Ответвление мнений]]<br /> [[zh:Wikipedia:內容分歧]]</div> Code-structure https://en.wikipedia.org/w/index.php?title=User:Code-structure/sandbox&diff=517828620 User:Code-structure/sandbox 2012-10-15T00:04:09Z <p>Code-structure: </p> <hr /> <div>&lt;!-- EDIT BELOW THIS LINE --&gt;<br /> Grammar of the '''C++''' language is available as part of the standard.<br /> <br /> [[File:Ddf|thumbnail]]<br /> <br /> '''Fragment''' **Frag**<br /> <br /> ''gggg'' //Frag//<br /> <br /> |=|=table|=header|<br /> |a|123|qqq|<br /> <br /> --[[User:Code-structure|Code-Structure]] ([[User talk:Code-structure|talk]]) 00:04, 15 October 2012 (UTC)</div> Code-structure https://en.wikipedia.org/w/index.php?title=User:Code-structure/sandbox&diff=517828304 User:Code-structure/sandbox 2012-10-15T00:01:54Z <p>Code-structure: </p> <hr /> <div>&lt;!-- EDIT BELOW THIS LINE --&gt;<br /> Grammar of the '''C++''' language is available as part of the standard.<br /> <br /> |=|=table|=header|<br /> |a|123|qqq|</div> Code-structure https://en.wikipedia.org/w/index.php?title=User:Code-structure/sandbox&diff=517828190 User:Code-structure/sandbox 2012-10-15T00:01:12Z <p>Code-structure: </p> <hr /> <div>&lt;!-- EDIT BELOW THIS LINE --&gt;<br /> Grammar of the '''C++''' language is available as part of the standard.<br /> <br /> |=|=table|<br /> |a|123|</div> Code-structure https://en.wikipedia.org/w/index.php?title=Wikipedia:Redirect&diff=517827768 Wikipedia:Redirect 2012-10-14T23:58:17Z <p>Code-structure: The work &quot;make&quot; has more meaning of &quot;create&quot; rather than &quot;transform&quot;.</p> <hr /> <div>{{Redirect|WP:RDR|centralized dispute resolution requests|Wikipedia:Requesting dispute resolution}}<br /> {{Redirect|WP:R|reliable sources|WP:RELY|relevance|WP:REL}}<br /> {{pp-protected|expiry=2012-09-14T03:10:38Z|small=yes}}{{pp-move-indef|small=yes}}<br /> &lt;noinclude&gt;{{Wikipedia subcat guideline|editing guideline|Redirect|WP:R|WP:RDR|WP:REDIR|WP:REDIRECT}}&lt;/noinclude&gt;<br /> <br /> {{nutshell|Redirects aid navigation and searching by allowing a page to be reached under alternative titles.}}<br /> <br /> A '''redirect''' is a page which has no content itself, but sends the reader to another article, section of an article, or page, usually from an alternative title. For example, if you type &quot;UK&quot; in the search box, or follow the wikilink [[UK]], you will be taken to the article [[United Kingdom]], with a note at the top of the page: &quot;&lt;span style=font-size:85% &quot;&gt;(&lt;font color=grey&gt;Redirected from&lt;/font&gt; &lt;font color=#002BB8&gt;UK&lt;/font&gt;)&lt;/span&gt;&quot;. This is because the page [[UK]] contains the wikitext &lt;tt&gt;#REDIRECT&amp;nbsp;&lt;nowiki&gt;[[United Kingdom]]&lt;/nowiki&gt;&lt;/tt&gt;, which defines it as a redirect page and indicates the target article. It is also possible to redirect to a specific [[Help:Section|section]] of the target page, using the &lt;tt&gt;#REDIRECT&amp;nbsp;&lt;nowiki&gt;[[Page name#Section title]]&lt;/nowiki&gt;&lt;/tt&gt; syntax.<br /> <br /> This page contains guidance on the proper use of redirects on Wikipedia. For technical help relating to how redirects work, see '''[[Help:Redirect]]'''. Other relevant pages are [[Wikipedia:Double redirects]], [[Wikipedia:Hatnote#Redirect]] and [[Wikipedia:WikiProject Redirect|WikiProject Redirect]].<br /> <br /> [[File:EnWiki redirect - Pichilemo.png|thumb|right|419px|A screenshot of Wikipedia showing a redirect from [[Pichilemo]] to [[Pichilemu]].]]<br /> <br /> ==Purposes of redirects {{Anchor|reasons|What do we use redirects for?}}==<br /> Reasons for creating and maintaining redirects include:<br /> *Alternative names (for example, [[Edison Arantes do Nascimento]] redirects to [[Pelé]]), a redirect to the [[Wikipedia:Article titles|most appropriate article title]].<br /> *Plurals (for example, [[Greenhouse gases]] redirects to [[Greenhouse gas]]).<br /> *Closely related words (for example, [[Symbiont]] redirects to [[Symbiosis]]).<br /> *Adjectives/Adverbs point to noun forms (e.g. [[Treasonous]] redirects to [[Treason]])<br /> *Less specific forms of names, for which the article subject is still the [[WP:PRIMARYTOPIC|primary topic]]. For example, [[Hitler]] redirects to [[Adolf Hitler]], whereas [[Johnson]] is a disambiguation page rather than a redirect, since no Johnson is regarded as the primary topic for that name.<br /> *More specific forms of names (for example, [[Articles of Confederation and Perpetual Union]] redirects to [[Articles of Confederation]]).<br /> *Abbreviations and initialisms (for example, [[DSM-IV]] redirects to [[Diagnostic and Statistical Manual of Mental Disorders]]). But often an abbreviation will have multiple meanings, none of which is a [[WP:PRIMARYTOPIC|primary topic]]—in that case a [[WP:Disambiguation|disambiguation]] page should be created rather than a redirect.<br /> *Alternative spellings or punctuation. For example, [[Colour]] redirects to [[Color]], and [[Al-Jazeera]] redirects to [[Al Jazeera]].<br /> *Punctuation issues—titles containing [[en dash|dash]]es should have redirects using [[hyphen-minus|hyphens]].<br /> *Representations using ASCII characters, that is, common transliterations (for example, [[Pele]] also redirects to [[Pelé]] while [[Kurt Goedel]] and [[Kurt Godel]] redirect to [[Kurt Gödel]]).<br /> *Likely misspellings (for example, [[Condoleeza Rice]] redirects to [[Condoleezza Rice]]).<br /> *Likely alternative capitalizations (for example, [[Natural Selection]] redirects to [[Natural selection]]). This is not necessary for user searching, but may aid linking from other articles and external sites.<br /> *To comply with the maintenance of nontrivial edit history, pursuant to [[WP:MERGETEXT]] for copyright licensing requirements.<br /> *Sub-topics or other topics which are described or listed within a wider article. (Such redirects are often targeted to a particular section of the article.)<br /> *Redirects to disambiguation pages which do not contain &quot;(disambiguation)&quot; in the title (for example, [[America (disambiguation)]] redirects to [[America]]). These help maintenance by allowing deliberate links to disambiguation pages to be distinguished from links which need to be disambiguated.<br /> *[[WP:Shortcut|Shortcut]]s (for example, [[WP:V]] redirects to [[Wikipedia:Verifiability]]). This is commonly done in [[WP:Project namespace|project space]], but not in article space.<br /> *Old-style [[WP:CamelCase|CamelCase]] links (if already in existence) ([[AnnaKournikova]] redirects to [[Anna Kournikova]]).<br /> *Links auto-generated from Exif information ([[Adobe Photoshop CS Windows]] redirects to [[Adobe Photoshop]]).<br /> <br /> There are [[Wikipedia:Template_messages/Redirect_pages|redirect templates]] to explain the [[WP:R#PLA|reason]] for a redirect.<br /> <br /> Note that redirects to other Wikimedia projects, other websites, or [[Special:SpecialPages|special pages]] do not work. These should be avoided or replaced with a {{tl|soft redirect}} template. Soft redirects are also used in [[Help:Category|category space]] (using the {{tl|category redirect}} template).<br /> <br /> ==How to make a redirect==<br /> <br /> To create a basic redirect, set &lt;tt&gt;#REDIRECT &lt;nowiki&gt;[[target page name here]]&lt;/nowiki&gt;&lt;/tt&gt; as the only body text of the page. For instance, if you were redirecting from &quot;{{noredirect|UK}}&quot; to &quot;[[United Kingdom]]&quot;, this would be the entire body of {{noredirect|UK|the &quot;UK&quot; page}}:<br /> <br /> &lt;code&gt;<br /> &lt;nowiki&gt;<br /> #REDIRECT [[United Kingdom]]<br /> &lt;/nowiki&gt;<br /> &lt;/code&gt;<br /> <br /> ==How to edit a redirect or convert it into an article==<br /> Sometimes an existing redirect should really be handled by a full article, per [[:Category:Redirects with possibilities]]. For example, the name of a notable musician (who does not yet have an article) may instead be a redirect to an existing article about a band of which the musician is a member. In this case you may edit the redirect to make it into an article. Also, if an existing redirect points to the wrong page, you may edit the redirect to point to a different page.<br /> <br /> If you want to edit a redirect page you must use a special technique in order to get to the redirect page itself. This is because when you try to go straight to the redirect page and edit it, the redirect page will automatically redirect you to its target page (because this is what a redirect page is meant to do). Below is an example of why you might need to go to a redirect page itself (to do a small edit) and how to actually get there. <br /> <br /> For example, say [[Trygve Halvdan Lie]] did not have his own article, and so this link was a redirect to the page [[Secretary-General of the United Nations]]. If, later on, the page [[Trygve Lie]] was created as a biography, the page [[Trygve Halvdan Lie]] should be changed to redirect to [[Trygve Lie]] per [[WP:COMMONNAME]]. To do this, go to the redirect page by clicking the redirect note on the target page, which in this case would read &quot;(Redirected from [[Trygve Halvdan Lie]])&quot;. Once there, you may click the &quot;Edit&quot; tab, and change the page from &lt;tt&gt;#REDIRECT&amp;nbsp;&lt;nowiki&gt;[[Secretary-General of the United Nations]]&lt;/nowiki&gt;&lt;/tt&gt; to &lt;tt&gt;#REDIRECT&amp;nbsp;&lt;nowiki&gt;[[Trygve Lie]]&lt;/nowiki&gt;&lt;/tt&gt;.<br /> <br /> ==Targeted and untargeted redirects==<br /> {{shortcut|WP:TARGET|WP:RSECT}}<br /> Most redirects are ''untargeted'', i.e. they lead simply to a page, not to any specific section of the page. This is usually done when there is more than one possible name under which an article might be sought (for example, [[Cellphone]] redirects to the article [[Mobile phone]]). For deciding which should be the actual title of the article, see [[WP:Article titles|Article titles]].<br /> <br /> It is also possible to create a ''targeted redirect'', i.e. a redirect to a particular point on the target page—either a [[Help:Section|section header]] or an [[Help:Anchor|anchor]]. For example, [[Malia Obama]] redirects to [[Family of Barack Obama#Malia and Sasha Obama]]. Therefore, entering &quot;''Malia Obama''&quot; will bring the searcher straight to that section of the article [[Family of Barack Obama]] which deals with &quot;Malia and Sasha Obama&quot;.<br /> <br /> Consider that when the target page is displayed, it is likely that the top of the page will not be shown, so the user may not see the helpful &quot;(redirected from... )&quot; text unless they know to scroll back to the top. This is less likely to cause confusion if the redirect is to a heading with the same name as the redirect.<br /> <br /> The text given in the link on a targeted redirect page must exactly match the target section heading or anchor text, including capitalization. (In the absence of a match, the reader will simply be taken to the top of the target page.) It is often helpful to leave a [[WP:HIDDEN|hidden comment]] in the target text, to inform other editors that a section title is linked, so that if the title is altered, the redirect can be changed. For example:<br /> <br /> &lt;pre&gt;&lt;nowiki&gt;<br /> ==Vaccine overload==<br /> &lt;!-- linked from redirect [[Vaccine overload]] --&gt;<br /> &lt;/nowiki&gt;&lt;/pre&gt;<br /> <br /> To ensure that a redirect will not break if a section title gets altered, or to create a redirect to a point on the page other than a section heading, create an explicit target anchor in the page, e.g. by using the {{tl|anchor}} template. The anchor text will not be visible (unless the {{tl|visible anchor}} template is used), but it will serve as a permanent marker of that place on the page. Editors should generally not remove or alter such anchors without checking all incoming links and redirects.<br /> <br /> For example, in the [[Google search]] article, the text &lt;tt&gt;&lt;nowiki&gt;{{anchor|calculator}}&lt;/nowiki&gt;&lt;/tt&gt; is placed at the point where ''Google Calculator'' is described. The title [[Google Calculator]] can then be redirected to [[Google search#calculator]].<br /> <br /> ===Warning===<br /> #Don't give an anchor the same name as a section heading&amp;nbsp;– this creates invalid code, as [http://www.w3.org/TR/xhtml1/#C_8 anchor names must be unique].<br /> #Be careful with anchor capitalization&amp;nbsp;– [http://www.w3.org/TR/html4/struct/links.html#h-12.2.1 section redirects are case-sensitive in standards-compliant browsers].&lt;!--(XHTML standard is the same)--&gt;<br /> <br /> ==Double redirects==<br /> {{main|Wikipedia:Double redirects}}<br /> The software will not follow chains of more than one redirect - this is called a double redirect. A redirect should not be left pointing to another redirect page.<br /> <br /> Double redirects often arise after a page is [[WP:MOVE|moved]] (renamed)—after moving a page, check whether there are any redirects to the old title (using the link on the move result page, or using [[WP:WHATLINKSHERE|&quot;What links here&quot;]]), and change them to redirect straight to the new title. (Double redirects are usually fixed by a [[Wikipedia:Bots/Status|bot]] after some time.)<br /> <br /> ==Linking to a redirect==<br /> {{Main|Wikipedia:Manual of Style (linking)#Redirects|l1=MoS linking redirects}}<br /> <br /> A redirect may be linked to from a source page the same way an article is [[Help:Link|linked]]—by placing the redirect page name within a set of double brackets, such as: &lt;div style=&quot;margin-left: 2em&quot;&gt;&lt;code&gt;&lt;nowiki&gt;[[&lt;/nowiki&gt;&lt;var&gt;Some name&lt;/var&gt;&lt;nowiki&gt;]]&lt;/nowiki&gt;&lt;/code&gt;&lt;/div&gt; replacing &lt;var&gt;Some name&lt;/var&gt; with the name of the redirect page to link.<br /> <br /> To link to a redirect page without following the underlying redirect, use: &lt;div style=&quot;margin-left: 2em&quot;&gt;&lt;code&gt;&lt;nowiki&gt;{{&lt;/nowiki&gt;noredirect|&lt;var&gt;Some name&lt;/var&gt;&lt;nowiki&gt;}}&lt;/nowiki&gt;&lt;/code&gt;&lt;/div&gt; replacing &lt;var&gt;Some name&lt;/var&gt; with the name of the redirect page to link. Clicking on a noredirect link will send the reader to the redirect page rather than the final redirect destination.<br /> <br /> ==Categorizing redirect pages==<br /> {{main|Wikipedia:Categorizing redirects}}<br /> Most redirect pages are not placed in any [[WP:Categorization|categories]]. However there are three types of exception to this:<br /> *Certain categories have been created for particular types of redirects, such as [[:Category:Redirects from abbreviations]], in which a redirect page may be placed using the {{tl|R from abbreviation}} template. See [[Wikipedia:Template messages/Redirect pages]] for a full list of these templates.<br /> *Sometimes a redirect is placed in an article category because the form of the redirected title is more appropriate to the context of that category. (Redirects appear in italics in category listings.)<br /> *Discussion pages. If a discussion/talk page exists for an article, please change the article's class to &quot;class=Redirect&quot; for all projects.<br /> <br /> ==&lt;span id=&quot;CRD&quot;&gt;When should we delete a redirect?&lt;/span&gt;&lt;span id=&quot;crd&quot;/&gt;==<br /> &lt;!-- Link directly to this section with: [[Wikipedia:Redirect#CRD]]<br /> Where CRD represents Criteria for Redirect Deletion --&gt;<br /> {{shortcut|WP:R#CRD|WP:RDR#CRD|WP:REDIR#CRD|WP:REDIRECT#CRD}}<br /> To delete a redirect '''without replacing it with a new article''', list it on [[Wikipedia:Redirects for discussion|redirects for discussion]]. See [[Wikipedia:Deletion policy|deletion policy]] for details on how to nominate pages for deletion.<br /> <br /> Listing is not necessary if you just want to replace a redirect with an article, or change where it points: see [[meta:Help:Redirect#Changing a redirect|these instructions]] for help doing this. If you want to ''swap'' a redirect and an article, but are not able to move the article to the location of the redirect please use [[Wikipedia:Requested moves]] to request help from an [[Wikipedia:Administrators|admin]] in doing that.<br /> <br /> &lt;!-- If you modify this list, do the same to the copy at [[WP:RfD]]. --&gt;<br /> &lt;!-- Apparently this is too complex for some people to follow. Let's try it this way, then. --&gt;<br /> {{Wikipedia:Redirect/DeletionReasons}}<br /> <br /> ==&lt;span id=&quot;PLA&quot;&gt;What needs to be done on pages that are targets of redirects?&lt;/span&gt;&lt;span id=&quot;pla&quot;/&gt;==<br /> &lt;!-- Link directly to this section with: [[Wikipedia:Redirect#PLA]]<br /> Where PLA represents Principle of Least Astonishment --&gt;<br /> {{shortcut|WP:R#PLA|WP:RDR#PLA|WP:REDIR#PLA|WP:REDIRECT#PLA}}<br /> We follow the &quot;[[Wikipedia:Guide to writing better articles#Principle of least astonishment|principle of least astonishment]]&quot;—after following a redirect, the reader's first question is likely to be: &quot;hang on ... I wanted to read about ''this''. Why has the link taken me to ''that''?&quot;. Make it clear to the reader that they ''have'' arrived in the right place.<br /> <br /> Normally, we try to make sure that all &quot;inbound redirects&quot; other than misspellings or other obvious close variants of the article title are mentioned in the first couple of paragraphs of the article or section to which the redirect goes. It will often be appropriate to '''bold''' the redirected term. For example:<br /> * '''James Tiptree, Jr.''' (August 24, 1915&amp;nbsp;– May 19, 1987) was the pen name of American science fiction author '''Alice Bradley Sheldon''' ...<br /> ** [[James Tiptree, Jr.]], redirect from [[Alice Sheldon]]<br /> * '''Water''' (H2O, HOH) is the most abundant molecule ...<br /> ** [[Properties of water]], redirect from [[H2O]], NB not bolded<br /> <br /> If the redirected term could have other meanings, a [[WP:Hatnote|hatnote]] ([[Wikipedia:HATTEST#Redirect|examples]]) should be placed at the top of the target article directing readers to the other meanings or to a relevant [[WP:DAB|disambiguation]] page. This is usually done using one of the [[:Template:Redirect#&quot;… redirects here. For other uses, see …&quot;|redirect disambiguation templates]] ([[Wikipedia:HATTEST#Redirect|examples]]).<br /> <br /> It may also helpful to [[Help:Searching|search]] the [[Help:Category#Listing_all_categories|List of Categories]] for [[Wikipedia:FAQ/Categories#Can_I_specify_categories_when_searching.3F|related terms]]; adding a [[WP:HATNOTE|hatnote]] and a [[Help:Category|category link]] to the old term will make related pages easier to locate.<br /> <br /> ==&lt;span id=&quot;NOTBROKEN&quot;&gt;Do not &quot;fix&quot; links to redirects that are not broken&lt;/span&gt;&lt;span id=&quot;notbroken&quot;/&gt;==<br /> {{shortcut|WP:NOTBROKEN|WP:R#NOTBROKEN|WP:RDR#NOTBROKEN|WP:REDIR#NOTBROKEN|WP:REDIRECT#NOTBROKEN}}<br /> There is nothing inherently wrong with linking to redirects. Some editors are tempted, upon finding a link to a redirect page, to bypass the redirect and point the link directly at the target page. While there are a limited number of cases where this is beneficial, it is generally an unhelpful exercise, and it can actually be detrimental.<br /> <br /> With a few limited exceptions, there are no good reasons to pipe links solely to avoid redirects. It is almost never helpful to replace &lt;nowiki&gt;[[redirect]] with [[target|redirect]]&lt;/nowiki&gt;.<br /> <br /> It is likewise unhelpful to edit visible links for no reason other than to avoid redirects. That is, editors should not change, for instance, &lt;nowiki&gt;[[Franklin Roosevelt]] to [[Franklin D. Roosevelt]]&lt;/nowiki&gt; just to &quot;fix a redirect&quot;. This rule does not apply to cases where there are other reasons to make the change, such as linking to an [[:Category:Unprintworthy redirects|unprintworthy redirect]].<br /> <br /> Reasons not to change (bypass) redirects include:<br /> * Redirects can indicate [[:Category:Redirects with possibilities|possible future articles]].<br /> * Introducing unnecessary invisible text makes the article more difficult to read in page source form.<br /> * Non-piped links make better use of the &quot;what links here&quot; tool, making it easier to track how articles are linked and helping with large-scale changes to links.<br /> * Shortcuts or redirects to subsections of articles or [[Wikipedia:Policies and guidelines|Wikipedia's advice pages]] should never be bypassed, as the section headings on the page may change over time. Updating one redirect is far more efficient than updating dozens of piped links.<br /> *If editors persistently use a redirect instead of an article title, it may be that the article needs to be moved rather than the redirect changed. As such the systematic &quot;fixing of redirects&quot; may eradicate useful information which can be used to help decide on the &quot;best&quot; article title.<br /> <br /> Exceptions:{{shortcut|WP:BRINT}}<br /> * {{Anchor|Bypass redirects in navigational templates}}&lt;span id=&quot;template link fix&quot;/&gt;&lt;span id=&quot;template linkfix&quot;/&gt;&lt;span id=&quot;templatelinkfix&quot;/&gt;&lt;span id=&quot;TLF&quot;/&gt;In many cases it is preferable to change redirected links in navigational templates, such as those found at the bottom of many articles (e.g. {{tl|US Presidents}} at the end of [[George Washington]]). In this case, when the template is placed on an article, and contains a direct link to the same article (rather than a redirect), the direct link will display in '''bold''' (and not as a link), making it easier to navigate through a series of articles using the template. There are exceptions to this exception: where a redirect represents a distinct sub-topic within a larger article and is not merely a variant name, it is preferable to leave the redirect in the template.<br /> * It may be appropriate to make this kind of change if the hint that appears when a user hovers over the link is misleading.<br /> * &lt;nowiki&gt;[[redirect|target]] may be replaced with [[target]] if [[redirect]] is not a&lt;/nowiki&gt; {{tl|Redirect with possibilities}}.<br /> * The [[WP:NS|virtual namespace]] ''Media:'' does not work on redirects, that is, if ''File:Barbaz.jpg'' is a redirect to ''File:Foobar.jpg'', then &lt;nowiki&gt;[[Media:Barbaz.jpg]]&lt;/nowiki&gt; will not work and must be replaced by &lt;nowiki&gt;[[Media:Foobar.jpg]]&lt;/nowiki&gt;.<br /> <br /> ===Self-redirects===<br /> Avoid linking to titles which redirect straight back to the page on which the link is found. This situation may arise if a redirect is created from a red link on the page, or if the title was once a separate page but was merged. However, it is acceptable to link to a title which redirects to a section within the article, especially in a long article that cannot be viewed all at once on an average-sized computer screen.<br /> <br /> ==Template redirects== &lt;!--Wikipedia:AutoWikiBrowser/General fixes links here --&gt;<br /> A template can be redirected to another template in the same way, e.g. by entering the following markup at the top of a template T2:<br /> &lt;nowiki&gt;#REDIRECT [[Template:T1]]&lt;/nowiki&gt;<br /> <br /> This allows the template name T2 to be used instead of the actual template name T1. All the parameters of T1 will be respected by T2.<br /> <br /> A categorisation template such as {{tl|R from move}} may be added to T2 (below the &lt;nowiki&gt;#REDIRECT&lt;/nowiki&gt; line) as follows:<br /> <br /> &lt;nowiki&gt;{{R from move|T1}}&lt;/nowiki&gt;<br /> <br /> Redirects for templates can cause confusion and make updating template calls more complicated. For example, if calls to T1 are to be changed to some new template TN1, articles must be searched for &lt;nowiki&gt;{{T1}}&lt;/nowiki&gt; and a separate search must be made for each of its aliases (including T2 in this example). Moreover changes to syntax, corrections, scans and other processes (for example tag dating) must take into account ''all'' redirects.<br /> <br /> ==&lt;span id=&quot;CATEGORY&quot;&gt;Category redirects&lt;/span&gt;&lt;span id=&quot;category&quot;/&gt;==<br /> {{shortcut|WP:R#CATEGORY|WP:RDR#CATEGORY|WP:REDIR#CATEGORY|WP:REDIRECT#CATEGORY}}<br /> Although it is possible to attempt to redirect [[WP:CAT|categories]] by adding a line such as &lt;tt&gt;&lt;nowiki&gt;#REDIRECT [[:Category:Automotive technologies]]&lt;/nowiki&gt;&lt;/tt&gt; to a category, it is not generally recommended because of limitations in the MediaWiki software. Categories &quot;redirected&quot; in this way do not prevent the addition of articles to the redirected category. Articles added to the &quot;redirected&quot; category do not show up as in the target category.<br /> Until these issues are addressed (in future versions of the software), '''#REDIRECT''' should not be added to category pages.<br /> <br /> &quot;Soft&quot; redirects for categories can be created using {{[[Template:Category redirect|Category redirect]]}}. A [[Wikipedia:Bot policy|bot]] traverses categories redirected in this manner moving articles out of the redirected category into the target category, see [[Template talk:Category redirect]].<br /> <br /> == {{anchor|SUPPRESS}}Suppressing redirects ==<br /> {{shortcut|WP:R#SUPPRESS|WP:RDR#SUPPRESS|WP:REDIR#SUPPRESS|WP:REDIRECT#SUPPRESS}}<br /> When a page is moved, a redirect is automatically left behind. Some groups of users (those who possess a &lt;code&gt;suppressredirect&lt;/code&gt; [[Special:ListGroupRights|right]]) have the ability to prevent the redirect being created, by unchecking the box labelled &quot;Leave a redirect behind.&quot; Currently these groups are administrators, bots and [[meta:Global rollback|global rollbackers]]. In some circumstances, a page should be moved, but a redirect from its current name is inappropriate, such as reverting page-move vandalism. Suppressing the redirect can avoid an extra action (page removal) and save time in these cases.<br /> <br /> However in general, the redirect will be a useful entry in the history, and it is best to leave it behind, unless there is a good reason to suppress the redirect, such as vandalism, [[WP:Userfication|userfying]] ''recently created'' malplaced items or freeing a title to be occupied immediately by another page (e.g. moving &lt;u&gt;term&lt;/u&gt; to &lt;u&gt;accurate term&lt;/u&gt; and &lt;u&gt;term (disambiguation)&lt;/u&gt; to &lt;u&gt;term&lt;/u&gt;). Redirects leave a trail to help readers find the old article, in case a new article is created at its previous location, and to prevent [[Wikipedia:Linkrot|linkrot]]. Therefore, we usually neither suppress nor [[#When should we delete a redirect?|delete]] redirects. As Brion Vibber [[bugzilla:15842#c20|said]], &quot;Not breaking links helps everyone, ''especially us first and foremost''&quot;. He also [[bugzilla:15842#c15|said]] that the removal of (file) redirects is &quot;extremely user-hostile and makes the project less useful&quot;.<br /> <br /> ==See also==<br /> {{Wikipedia glossary}}<br /> *[[:Category:Redirect templates]]<br /> *[[:Category:Wikipedia redirects]]<br /> *[[Help:Moving a page]]<br /> *[[Help:Redirect]]<br /> *[[Special:BrokenRedirects]]<br /> *[[Special:DoubleRedirects]]<br /> *[[Template:Redirect]]<br /> *[[Wikipedia:Disambiguation]]<br /> *[[Wikipedia:Double redirects]]<br /> *[[Wikipedia:Hatnote]] (see [[Wikipedia:Redirect#What_needs_to_be_done_on_pages_that_are_targets_of_redirects.3F|above]])<br /> *[[Wikipedia:Redirects for discussion]]<br /> *[[Wikipedia:Redirects to be made]]<br /> *[[Wikipedia:Soft redirect]]<br /> *[[Wikipedia:WikiProject Redirect]]<br /> **[[Wikipedia:WikiProject Redirect/Style guide]]<br /> *[[Wikipedia:Database reports/Page count by namespace]] and by non-redirects/redirects<br /> <br /> == External links ==<br /> {{Commonscat|MediaWiki redirects}}<br /> <br /> [[Category:Wikipedia editing guidelines]]<br /> [[Category:Wikipedia redirects| ]]<br /> [[Category:Article Feedback 5 Additional Articles]]<br /> <br /> [[af:Wikipedia:Aanstuur]]<br /> [[ar:ويكيبيديا:تحويل]]<br /> [[bn:উইকিপিডিয়া:পুনর্নির্দেশনা]]<br /> [[zh-min-nan:Wikipedia:Choán-ia̍h]]<br /> [[be-x-old:Вікіпэдыя:Перанакіраваньне]]<br /> [[ca:Viquipèdia:Redirecció]]<br /> [[cs:Wikipedie:Přesměrování]]<br /> [[et:Vikipeedia:Ümbersuunamine]]<br /> [[el:Βικιπαίδεια:Ανακατεύθυνση]]<br /> [[fa:ویکی‌پدیا:تغییرمسیر]]<br /> [[fy:Wikipedy:Synonym]]<br /> [[gl:Wikipedia:Como redireccionar unha páxina]]<br /> [[ko:위키백과:넘겨주기 문서]]<br /> [[hi:विकिपीडिया:पुनर्निर्देशन]]<br /> [[hr:Wikipedija:Preusmjeravanje]]<br /> [[id:Wikipedia:Pengalihan]]<br /> [[it:Wikipedia:Redirect]]<br /> [[he:ויקיפדיה:דף הפניה]]<br /> [[jv:Wikipedia:Pangalihan]]<br /> [[kk:Уикипедия:Айдатқыштар]]<br /> [[la:Vicipaedia:Redirectio]]<br /> [[lt:Vikipedija:Nukreipiamieji straipsniai]]<br /> [[ms:Wikipedia:Lencongan]]<br /> [[nl:Wikipedia:Redirect]]<br /> [[ja:Wikipedia:リダイレクト]]<br /> [[ro:Wikipedia:Redirecționare]]<br /> [[ru:Википедия:Перенаправления]]<br /> [[sk:Wikipédia:Presmerovanie]]<br /> [[sl:Wikipedija:Preusmeritev]]<br /> [[sr:Википедија:Преусмерење]]<br /> [[sh:Wikipedia:Redirect]]<br /> [[fi:Wikipedia:Ohjaus]]<br /> [[sv:Wikipedia:Omdirigeringar]]<br /> [[ta:விக்கிப்பீடியா:வழிமாற்று]]<br /> [[te:వికీపీడియా:దారిమార్పు]]<br /> [[vi:Wikipedia:Trang đổi hướng]]<br /> [[yi:װיקיפּעדיע:ווייטערפירונג]]<br /> [[zh-yue:Wikipedia:跳轉]]<br /> [[zh:Wikipedia:重定向]]</div> Code-structure https://en.wikipedia.org/w/index.php?title=Wikipedia:Redirect&diff=517826164 Wikipedia:Redirect 2012-10-14T23:46:53Z <p>Code-structure: The verb &quot;add&quot; does not imply removing the previous content if any.</p> <hr /> <div>{{Redirect|WP:RDR|centralized dispute resolution requests|Wikipedia:Requesting dispute resolution}}<br /> {{Redirect|WP:R|reliable sources|WP:RELY|relevance|WP:REL}}<br /> {{pp-protected|expiry=2012-09-14T03:10:38Z|small=yes}}{{pp-move-indef|small=yes}}<br /> &lt;noinclude&gt;{{Wikipedia subcat guideline|editing guideline|Redirect|WP:R|WP:RDR|WP:REDIR|WP:REDIRECT}}&lt;/noinclude&gt;<br /> <br /> {{nutshell|Redirects aid navigation and searching by allowing a page to be reached under alternative titles.}}<br /> <br /> A '''redirect''' is a page which has no content itself, but sends the reader to another article, section of an article, or page, usually from an alternative title. For example, if you type &quot;UK&quot; in the search box, or follow the wikilink [[UK]], you will be taken to the article [[United Kingdom]], with a note at the top of the page: &quot;&lt;span style=font-size:85% &quot;&gt;(&lt;font color=grey&gt;Redirected from&lt;/font&gt; &lt;font color=#002BB8&gt;UK&lt;/font&gt;)&lt;/span&gt;&quot;. This is because the page [[UK]] contains the wikitext &lt;tt&gt;#REDIRECT&amp;nbsp;&lt;nowiki&gt;[[United Kingdom]]&lt;/nowiki&gt;&lt;/tt&gt;, which defines it as a redirect page and indicates the target article. It is also possible to redirect to a specific [[Help:Section|section]] of the target page, using the &lt;tt&gt;#REDIRECT&amp;nbsp;&lt;nowiki&gt;[[Page name#Section title]]&lt;/nowiki&gt;&lt;/tt&gt; syntax.<br /> <br /> This page contains guidance on the proper use of redirects on Wikipedia. For technical help relating to how redirects work, see '''[[Help:Redirect]]'''. Other relevant pages are [[Wikipedia:Double redirects]], [[Wikipedia:Hatnote#Redirect]] and [[Wikipedia:WikiProject Redirect|WikiProject Redirect]].<br /> <br /> [[File:EnWiki redirect - Pichilemo.png|thumb|right|419px|A screenshot of Wikipedia showing a redirect from [[Pichilemo]] to [[Pichilemu]].]]<br /> <br /> ==Purposes of redirects {{Anchor|reasons|What do we use redirects for?}}==<br /> Reasons for creating and maintaining redirects include:<br /> *Alternative names (for example, [[Edison Arantes do Nascimento]] redirects to [[Pelé]]), a redirect to the [[Wikipedia:Article titles|most appropriate article title]].<br /> *Plurals (for example, [[Greenhouse gases]] redirects to [[Greenhouse gas]]).<br /> *Closely related words (for example, [[Symbiont]] redirects to [[Symbiosis]]).<br /> *Adjectives/Adverbs point to noun forms (e.g. [[Treasonous]] redirects to [[Treason]])<br /> *Less specific forms of names, for which the article subject is still the [[WP:PRIMARYTOPIC|primary topic]]. For example, [[Hitler]] redirects to [[Adolf Hitler]], whereas [[Johnson]] is a disambiguation page rather than a redirect, since no Johnson is regarded as the primary topic for that name.<br /> *More specific forms of names (for example, [[Articles of Confederation and Perpetual Union]] redirects to [[Articles of Confederation]]).<br /> *Abbreviations and initialisms (for example, [[DSM-IV]] redirects to [[Diagnostic and Statistical Manual of Mental Disorders]]). But often an abbreviation will have multiple meanings, none of which is a [[WP:PRIMARYTOPIC|primary topic]]—in that case a [[WP:Disambiguation|disambiguation]] page should be created rather than a redirect.<br /> *Alternative spellings or punctuation. For example, [[Colour]] redirects to [[Color]], and [[Al-Jazeera]] redirects to [[Al Jazeera]].<br /> *Punctuation issues—titles containing [[en dash|dash]]es should have redirects using [[hyphen-minus|hyphens]].<br /> *Representations using ASCII characters, that is, common transliterations (for example, [[Pele]] also redirects to [[Pelé]] while [[Kurt Goedel]] and [[Kurt Godel]] redirect to [[Kurt Gödel]]).<br /> *Likely misspellings (for example, [[Condoleeza Rice]] redirects to [[Condoleezza Rice]]).<br /> *Likely alternative capitalizations (for example, [[Natural Selection]] redirects to [[Natural selection]]). This is not necessary for user searching, but may aid linking from other articles and external sites.<br /> *To comply with the maintenance of nontrivial edit history, pursuant to [[WP:MERGETEXT]] for copyright licensing requirements.<br /> *Sub-topics or other topics which are described or listed within a wider article. (Such redirects are often targeted to a particular section of the article.)<br /> *Redirects to disambiguation pages which do not contain &quot;(disambiguation)&quot; in the title (for example, [[America (disambiguation)]] redirects to [[America]]). These help maintenance by allowing deliberate links to disambiguation pages to be distinguished from links which need to be disambiguated.<br /> *[[WP:Shortcut|Shortcut]]s (for example, [[WP:V]] redirects to [[Wikipedia:Verifiability]]). This is commonly done in [[WP:Project namespace|project space]], but not in article space.<br /> *Old-style [[WP:CamelCase|CamelCase]] links (if already in existence) ([[AnnaKournikova]] redirects to [[Anna Kournikova]]).<br /> *Links auto-generated from Exif information ([[Adobe Photoshop CS Windows]] redirects to [[Adobe Photoshop]]).<br /> <br /> There are [[Wikipedia:Template_messages/Redirect_pages|redirect templates]] to explain the [[WP:R#PLA|reason]] for a redirect.<br /> <br /> Note that redirects to other Wikimedia projects, other websites, or [[Special:SpecialPages|special pages]] do not work. These should be avoided or replaced with a {{tl|soft redirect}} template. Soft redirects are also used in [[Help:Category|category space]] (using the {{tl|category redirect}} template).<br /> <br /> ==How to make a redirect==<br /> <br /> To create a basic redirect, set &lt;tt&gt;#REDIRECT &lt;nowiki&gt;[[target page name here]]&lt;/nowiki&gt;&lt;/tt&gt; as the only body text of the page. For instance, if you were redirecting from &quot;{{noredirect|UK}}&quot; to &quot;[[United Kingdom]]&quot;, this would be the entire body of {{noredirect|UK|the &quot;UK&quot; page}}:<br /> <br /> &lt;code&gt;<br /> &lt;nowiki&gt;<br /> #REDIRECT [[United Kingdom]]<br /> &lt;/nowiki&gt;<br /> &lt;/code&gt;<br /> <br /> ==How to edit a redirect or make it into an article==<br /> Sometimes an existing redirect should really be handled by a full article, per [[:Category:Redirects with possibilities]]. For example, the name of a notable musician (who does not yet have an article) may instead be a redirect to an existing article about a band of which the musician is a member. In this case you may edit the redirect to make it into an article. Also, if an existing redirect points to the wrong page, you may edit the redirect to point to a different page.<br /> <br /> If you want to edit a redirect page you must use a special technique in order to get to the redirect page itself. This is because when you try to go straight to the redirect page and edit it, the redirect page will automatically redirect you to its target page (because this is what a redirect page is meant to do). Below is an example of why you might need to go to a redirect page itself (to do a small edit) and how to actually get there. <br /> <br /> For example, say [[Trygve Halvdan Lie]] did not have his own article, and so this link was a redirect to the page [[Secretary-General of the United Nations]]. If, later on, the page [[Trygve Lie]] was created as a biography, the page [[Trygve Halvdan Lie]] should be changed to redirect to [[Trygve Lie]] per [[WP:COMMONNAME]]. To do this, go to the redirect page by clicking the redirect note on the target page, which in this case would read &quot;(Redirected from [[Trygve Halvdan Lie]])&quot;. Once there, you may click the &quot;Edit&quot; tab, and change the page from &lt;tt&gt;#REDIRECT&amp;nbsp;&lt;nowiki&gt;[[Secretary-General of the United Nations]]&lt;/nowiki&gt;&lt;/tt&gt; to &lt;tt&gt;#REDIRECT&amp;nbsp;&lt;nowiki&gt;[[Trygve Lie]]&lt;/nowiki&gt;&lt;/tt&gt;.<br /> <br /> ==Targeted and untargeted redirects==<br /> {{shortcut|WP:TARGET|WP:RSECT}}<br /> Most redirects are ''untargeted'', i.e. they lead simply to a page, not to any specific section of the page. This is usually done when there is more than one possible name under which an article might be sought (for example, [[Cellphone]] redirects to the article [[Mobile phone]]). For deciding which should be the actual title of the article, see [[WP:Article titles|Article titles]].<br /> <br /> It is also possible to create a ''targeted redirect'', i.e. a redirect to a particular point on the target page—either a [[Help:Section|section header]] or an [[Help:Anchor|anchor]]. For example, [[Malia Obama]] redirects to [[Family of Barack Obama#Malia and Sasha Obama]]. Therefore, entering &quot;''Malia Obama''&quot; will bring the searcher straight to that section of the article [[Family of Barack Obama]] which deals with &quot;Malia and Sasha Obama&quot;.<br /> <br /> Consider that when the target page is displayed, it is likely that the top of the page will not be shown, so the user may not see the helpful &quot;(redirected from... )&quot; text unless they know to scroll back to the top. This is less likely to cause confusion if the redirect is to a heading with the same name as the redirect.<br /> <br /> The text given in the link on a targeted redirect page must exactly match the target section heading or anchor text, including capitalization. (In the absence of a match, the reader will simply be taken to the top of the target page.) It is often helpful to leave a [[WP:HIDDEN|hidden comment]] in the target text, to inform other editors that a section title is linked, so that if the title is altered, the redirect can be changed. For example:<br /> <br /> &lt;pre&gt;&lt;nowiki&gt;<br /> ==Vaccine overload==<br /> &lt;!-- linked from redirect [[Vaccine overload]] --&gt;<br /> &lt;/nowiki&gt;&lt;/pre&gt;<br /> <br /> To ensure that a redirect will not break if a section title gets altered, or to create a redirect to a point on the page other than a section heading, create an explicit target anchor in the page, e.g. by using the {{tl|anchor}} template. The anchor text will not be visible (unless the {{tl|visible anchor}} template is used), but it will serve as a permanent marker of that place on the page. Editors should generally not remove or alter such anchors without checking all incoming links and redirects.<br /> <br /> For example, in the [[Google search]] article, the text &lt;tt&gt;&lt;nowiki&gt;{{anchor|calculator}}&lt;/nowiki&gt;&lt;/tt&gt; is placed at the point where ''Google Calculator'' is described. The title [[Google Calculator]] can then be redirected to [[Google search#calculator]].<br /> <br /> ===Warning===<br /> #Don't give an anchor the same name as a section heading&amp;nbsp;– this creates invalid code, as [http://www.w3.org/TR/xhtml1/#C_8 anchor names must be unique].<br /> #Be careful with anchor capitalization&amp;nbsp;– [http://www.w3.org/TR/html4/struct/links.html#h-12.2.1 section redirects are case-sensitive in standards-compliant browsers].&lt;!--(XHTML standard is the same)--&gt;<br /> <br /> ==Double redirects==<br /> {{main|Wikipedia:Double redirects}}<br /> The software will not follow chains of more than one redirect - this is called a double redirect. A redirect should not be left pointing to another redirect page.<br /> <br /> Double redirects often arise after a page is [[WP:MOVE|moved]] (renamed)—after moving a page, check whether there are any redirects to the old title (using the link on the move result page, or using [[WP:WHATLINKSHERE|&quot;What links here&quot;]]), and change them to redirect straight to the new title. (Double redirects are usually fixed by a [[Wikipedia:Bots/Status|bot]] after some time.)<br /> <br /> ==Linking to a redirect==<br /> {{Main|Wikipedia:Manual of Style (linking)#Redirects|l1=MoS linking redirects}}<br /> <br /> A redirect may be linked to from a source page the same way an article is [[Help:Link|linked]]—by placing the redirect page name within a set of double brackets, such as: &lt;div style=&quot;margin-left: 2em&quot;&gt;&lt;code&gt;&lt;nowiki&gt;[[&lt;/nowiki&gt;&lt;var&gt;Some name&lt;/var&gt;&lt;nowiki&gt;]]&lt;/nowiki&gt;&lt;/code&gt;&lt;/div&gt; replacing &lt;var&gt;Some name&lt;/var&gt; with the name of the redirect page to link.<br /> <br /> To link to a redirect page without following the underlying redirect, use: &lt;div style=&quot;margin-left: 2em&quot;&gt;&lt;code&gt;&lt;nowiki&gt;{{&lt;/nowiki&gt;noredirect|&lt;var&gt;Some name&lt;/var&gt;&lt;nowiki&gt;}}&lt;/nowiki&gt;&lt;/code&gt;&lt;/div&gt; replacing &lt;var&gt;Some name&lt;/var&gt; with the name of the redirect page to link. Clicking on a noredirect link will send the reader to the redirect page rather than the final redirect destination.<br /> <br /> ==Categorizing redirect pages==<br /> {{main|Wikipedia:Categorizing redirects}}<br /> Most redirect pages are not placed in any [[WP:Categorization|categories]]. However there are three types of exception to this:<br /> *Certain categories have been created for particular types of redirects, such as [[:Category:Redirects from abbreviations]], in which a redirect page may be placed using the {{tl|R from abbreviation}} template. See [[Wikipedia:Template messages/Redirect pages]] for a full list of these templates.<br /> *Sometimes a redirect is placed in an article category because the form of the redirected title is more appropriate to the context of that category. (Redirects appear in italics in category listings.)<br /> *Discussion pages. If a discussion/talk page exists for an article, please change the article's class to &quot;class=Redirect&quot; for all projects.<br /> <br /> ==&lt;span id=&quot;CRD&quot;&gt;When should we delete a redirect?&lt;/span&gt;&lt;span id=&quot;crd&quot;/&gt;==<br /> &lt;!-- Link directly to this section with: [[Wikipedia:Redirect#CRD]]<br /> Where CRD represents Criteria for Redirect Deletion --&gt;<br /> {{shortcut|WP:R#CRD|WP:RDR#CRD|WP:REDIR#CRD|WP:REDIRECT#CRD}}<br /> To delete a redirect '''without replacing it with a new article''', list it on [[Wikipedia:Redirects for discussion|redirects for discussion]]. See [[Wikipedia:Deletion policy|deletion policy]] for details on how to nominate pages for deletion.<br /> <br /> Listing is not necessary if you just want to replace a redirect with an article, or change where it points: see [[meta:Help:Redirect#Changing a redirect|these instructions]] for help doing this. If you want to ''swap'' a redirect and an article, but are not able to move the article to the location of the redirect please use [[Wikipedia:Requested moves]] to request help from an [[Wikipedia:Administrators|admin]] in doing that.<br /> <br /> &lt;!-- If you modify this list, do the same to the copy at [[WP:RfD]]. --&gt;<br /> &lt;!-- Apparently this is too complex for some people to follow. Let's try it this way, then. --&gt;<br /> {{Wikipedia:Redirect/DeletionReasons}}<br /> <br /> ==&lt;span id=&quot;PLA&quot;&gt;What needs to be done on pages that are targets of redirects?&lt;/span&gt;&lt;span id=&quot;pla&quot;/&gt;==<br /> &lt;!-- Link directly to this section with: [[Wikipedia:Redirect#PLA]]<br /> Where PLA represents Principle of Least Astonishment --&gt;<br /> {{shortcut|WP:R#PLA|WP:RDR#PLA|WP:REDIR#PLA|WP:REDIRECT#PLA}}<br /> We follow the &quot;[[Wikipedia:Guide to writing better articles#Principle of least astonishment|principle of least astonishment]]&quot;—after following a redirect, the reader's first question is likely to be: &quot;hang on ... I wanted to read about ''this''. Why has the link taken me to ''that''?&quot;. Make it clear to the reader that they ''have'' arrived in the right place.<br /> <br /> Normally, we try to make sure that all &quot;inbound redirects&quot; other than misspellings or other obvious close variants of the article title are mentioned in the first couple of paragraphs of the article or section to which the redirect goes. It will often be appropriate to '''bold''' the redirected term. For example:<br /> * '''James Tiptree, Jr.''' (August 24, 1915&amp;nbsp;– May 19, 1987) was the pen name of American science fiction author '''Alice Bradley Sheldon''' ...<br /> ** [[James Tiptree, Jr.]], redirect from [[Alice Sheldon]]<br /> * '''Water''' (H2O, HOH) is the most abundant molecule ...<br /> ** [[Properties of water]], redirect from [[H2O]], NB not bolded<br /> <br /> If the redirected term could have other meanings, a [[WP:Hatnote|hatnote]] ([[Wikipedia:HATTEST#Redirect|examples]]) should be placed at the top of the target article directing readers to the other meanings or to a relevant [[WP:DAB|disambiguation]] page. This is usually done using one of the [[:Template:Redirect#&quot;… redirects here. For other uses, see …&quot;|redirect disambiguation templates]] ([[Wikipedia:HATTEST#Redirect|examples]]).<br /> <br /> It may also helpful to [[Help:Searching|search]] the [[Help:Category#Listing_all_categories|List of Categories]] for [[Wikipedia:FAQ/Categories#Can_I_specify_categories_when_searching.3F|related terms]]; adding a [[WP:HATNOTE|hatnote]] and a [[Help:Category|category link]] to the old term will make related pages easier to locate.<br /> <br /> ==&lt;span id=&quot;NOTBROKEN&quot;&gt;Do not &quot;fix&quot; links to redirects that are not broken&lt;/span&gt;&lt;span id=&quot;notbroken&quot;/&gt;==<br /> {{shortcut|WP:NOTBROKEN|WP:R#NOTBROKEN|WP:RDR#NOTBROKEN|WP:REDIR#NOTBROKEN|WP:REDIRECT#NOTBROKEN}}<br /> There is nothing inherently wrong with linking to redirects. Some editors are tempted, upon finding a link to a redirect page, to bypass the redirect and point the link directly at the target page. While there are a limited number of cases where this is beneficial, it is generally an unhelpful exercise, and it can actually be detrimental.<br /> <br /> With a few limited exceptions, there are no good reasons to pipe links solely to avoid redirects. It is almost never helpful to replace &lt;nowiki&gt;[[redirect]] with [[target|redirect]]&lt;/nowiki&gt;.<br /> <br /> It is likewise unhelpful to edit visible links for no reason other than to avoid redirects. That is, editors should not change, for instance, &lt;nowiki&gt;[[Franklin Roosevelt]] to [[Franklin D. Roosevelt]]&lt;/nowiki&gt; just to &quot;fix a redirect&quot;. This rule does not apply to cases where there are other reasons to make the change, such as linking to an [[:Category:Unprintworthy redirects|unprintworthy redirect]].<br /> <br /> Reasons not to change (bypass) redirects include:<br /> * Redirects can indicate [[:Category:Redirects with possibilities|possible future articles]].<br /> * Introducing unnecessary invisible text makes the article more difficult to read in page source form.<br /> * Non-piped links make better use of the &quot;what links here&quot; tool, making it easier to track how articles are linked and helping with large-scale changes to links.<br /> * Shortcuts or redirects to subsections of articles or [[Wikipedia:Policies and guidelines|Wikipedia's advice pages]] should never be bypassed, as the section headings on the page may change over time. Updating one redirect is far more efficient than updating dozens of piped links.<br /> *If editors persistently use a redirect instead of an article title, it may be that the article needs to be moved rather than the redirect changed. As such the systematic &quot;fixing of redirects&quot; may eradicate useful information which can be used to help decide on the &quot;best&quot; article title.<br /> <br /> Exceptions:{{shortcut|WP:BRINT}}<br /> * {{Anchor|Bypass redirects in navigational templates}}&lt;span id=&quot;template link fix&quot;/&gt;&lt;span id=&quot;template linkfix&quot;/&gt;&lt;span id=&quot;templatelinkfix&quot;/&gt;&lt;span id=&quot;TLF&quot;/&gt;In many cases it is preferable to change redirected links in navigational templates, such as those found at the bottom of many articles (e.g. {{tl|US Presidents}} at the end of [[George Washington]]). In this case, when the template is placed on an article, and contains a direct link to the same article (rather than a redirect), the direct link will display in '''bold''' (and not as a link), making it easier to navigate through a series of articles using the template. There are exceptions to this exception: where a redirect represents a distinct sub-topic within a larger article and is not merely a variant name, it is preferable to leave the redirect in the template.<br /> * It may be appropriate to make this kind of change if the hint that appears when a user hovers over the link is misleading.<br /> * &lt;nowiki&gt;[[redirect|target]] may be replaced with [[target]] if [[redirect]] is not a&lt;/nowiki&gt; {{tl|Redirect with possibilities}}.<br /> * The [[WP:NS|virtual namespace]] ''Media:'' does not work on redirects, that is, if ''File:Barbaz.jpg'' is a redirect to ''File:Foobar.jpg'', then &lt;nowiki&gt;[[Media:Barbaz.jpg]]&lt;/nowiki&gt; will not work and must be replaced by &lt;nowiki&gt;[[Media:Foobar.jpg]]&lt;/nowiki&gt;.<br /> <br /> ===Self-redirects===<br /> Avoid linking to titles which redirect straight back to the page on which the link is found. This situation may arise if a redirect is created from a red link on the page, or if the title was once a separate page but was merged. However, it is acceptable to link to a title which redirects to a section within the article, especially in a long article that cannot be viewed all at once on an average-sized computer screen.<br /> <br /> ==Template redirects== &lt;!--Wikipedia:AutoWikiBrowser/General fixes links here --&gt;<br /> A template can be redirected to another template in the same way, e.g. by entering the following markup at the top of a template T2:<br /> &lt;nowiki&gt;#REDIRECT [[Template:T1]]&lt;/nowiki&gt;<br /> <br /> This allows the template name T2 to be used instead of the actual template name T1. All the parameters of T1 will be respected by T2.<br /> <br /> A categorisation template such as {{tl|R from move}} may be added to T2 (below the &lt;nowiki&gt;#REDIRECT&lt;/nowiki&gt; line) as follows:<br /> <br /> &lt;nowiki&gt;{{R from move|T1}}&lt;/nowiki&gt;<br /> <br /> Redirects for templates can cause confusion and make updating template calls more complicated. For example, if calls to T1 are to be changed to some new template TN1, articles must be searched for &lt;nowiki&gt;{{T1}}&lt;/nowiki&gt; and a separate search must be made for each of its aliases (including T2 in this example). Moreover changes to syntax, corrections, scans and other processes (for example tag dating) must take into account ''all'' redirects.<br /> <br /> ==&lt;span id=&quot;CATEGORY&quot;&gt;Category redirects&lt;/span&gt;&lt;span id=&quot;category&quot;/&gt;==<br /> {{shortcut|WP:R#CATEGORY|WP:RDR#CATEGORY|WP:REDIR#CATEGORY|WP:REDIRECT#CATEGORY}}<br /> Although it is possible to attempt to redirect [[WP:CAT|categories]] by adding a line such as &lt;tt&gt;&lt;nowiki&gt;#REDIRECT [[:Category:Automotive technologies]]&lt;/nowiki&gt;&lt;/tt&gt; to a category, it is not generally recommended because of limitations in the MediaWiki software. Categories &quot;redirected&quot; in this way do not prevent the addition of articles to the redirected category. Articles added to the &quot;redirected&quot; category do not show up as in the target category.<br /> Until these issues are addressed (in future versions of the software), '''#REDIRECT''' should not be added to category pages.<br /> <br /> &quot;Soft&quot; redirects for categories can be created using {{[[Template:Category redirect|Category redirect]]}}. A [[Wikipedia:Bot policy|bot]] traverses categories redirected in this manner moving articles out of the redirected category into the target category, see [[Template talk:Category redirect]].<br /> <br /> == {{anchor|SUPPRESS}}Suppressing redirects ==<br /> {{shortcut|WP:R#SUPPRESS|WP:RDR#SUPPRESS|WP:REDIR#SUPPRESS|WP:REDIRECT#SUPPRESS}}<br /> When a page is moved, a redirect is automatically left behind. Some groups of users (those who possess a &lt;code&gt;suppressredirect&lt;/code&gt; [[Special:ListGroupRights|right]]) have the ability to prevent the redirect being created, by unchecking the box labelled &quot;Leave a redirect behind.&quot; Currently these groups are administrators, bots and [[meta:Global rollback|global rollbackers]]. In some circumstances, a page should be moved, but a redirect from its current name is inappropriate, such as reverting page-move vandalism. Suppressing the redirect can avoid an extra action (page removal) and save time in these cases.<br /> <br /> However in general, the redirect will be a useful entry in the history, and it is best to leave it behind, unless there is a good reason to suppress the redirect, such as vandalism, [[WP:Userfication|userfying]] ''recently created'' malplaced items or freeing a title to be occupied immediately by another page (e.g. moving &lt;u&gt;term&lt;/u&gt; to &lt;u&gt;accurate term&lt;/u&gt; and &lt;u&gt;term (disambiguation)&lt;/u&gt; to &lt;u&gt;term&lt;/u&gt;). Redirects leave a trail to help readers find the old article, in case a new article is created at its previous location, and to prevent [[Wikipedia:Linkrot|linkrot]]. Therefore, we usually neither suppress nor [[#When should we delete a redirect?|delete]] redirects. As Brion Vibber [[bugzilla:15842#c20|said]], &quot;Not breaking links helps everyone, ''especially us first and foremost''&quot;. He also [[bugzilla:15842#c15|said]] that the removal of (file) redirects is &quot;extremely user-hostile and makes the project less useful&quot;.<br /> <br /> ==See also==<br /> {{Wikipedia glossary}}<br /> *[[:Category:Redirect templates]]<br /> *[[:Category:Wikipedia redirects]]<br /> *[[Help:Moving a page]]<br /> *[[Help:Redirect]]<br /> *[[Special:BrokenRedirects]]<br /> *[[Special:DoubleRedirects]]<br /> *[[Template:Redirect]]<br /> *[[Wikipedia:Disambiguation]]<br /> *[[Wikipedia:Double redirects]]<br /> *[[Wikipedia:Hatnote]] (see [[Wikipedia:Redirect#What_needs_to_be_done_on_pages_that_are_targets_of_redirects.3F|above]])<br /> *[[Wikipedia:Redirects for discussion]]<br /> *[[Wikipedia:Redirects to be made]]<br /> *[[Wikipedia:Soft redirect]]<br /> *[[Wikipedia:WikiProject Redirect]]<br /> **[[Wikipedia:WikiProject Redirect/Style guide]]<br /> *[[Wikipedia:Database reports/Page count by namespace]] and by non-redirects/redirects<br /> <br /> == External links ==<br /> {{Commonscat|MediaWiki redirects}}<br /> <br /> [[Category:Wikipedia editing guidelines]]<br /> [[Category:Wikipedia redirects| ]]<br /> [[Category:Article Feedback 5 Additional Articles]]<br /> <br /> [[af:Wikipedia:Aanstuur]]<br /> [[ar:ويكيبيديا:تحويل]]<br /> [[bn:উইকিপিডিয়া:পুনর্নির্দেশনা]]<br /> [[zh-min-nan:Wikipedia:Choán-ia̍h]]<br /> [[be-x-old:Вікіпэдыя:Перанакіраваньне]]<br /> [[ca:Viquipèdia:Redirecció]]<br /> [[cs:Wikipedie:Přesměrování]]<br /> [[et:Vikipeedia:Ümbersuunamine]]<br /> [[el:Βικιπαίδεια:Ανακατεύθυνση]]<br /> [[fa:ویکی‌پدیا:تغییرمسیر]]<br /> [[fy:Wikipedy:Synonym]]<br /> [[gl:Wikipedia:Como redireccionar unha páxina]]<br /> [[ko:위키백과:넘겨주기 문서]]<br /> [[hi:विकिपीडिया:पुनर्निर्देशन]]<br /> [[hr:Wikipedija:Preusmjeravanje]]<br /> [[id:Wikipedia:Pengalihan]]<br /> [[it:Wikipedia:Redirect]]<br /> [[he:ויקיפדיה:דף הפניה]]<br /> [[jv:Wikipedia:Pangalihan]]<br /> [[kk:Уикипедия:Айдатқыштар]]<br /> [[la:Vicipaedia:Redirectio]]<br /> [[lt:Vikipedija:Nukreipiamieji straipsniai]]<br /> [[ms:Wikipedia:Lencongan]]<br /> [[nl:Wikipedia:Redirect]]<br /> [[ja:Wikipedia:リダイレクト]]<br /> [[ro:Wikipedia:Redirecționare]]<br /> [[ru:Википедия:Перенаправления]]<br /> [[sk:Wikipédia:Presmerovanie]]<br /> [[sl:Wikipedija:Preusmeritev]]<br /> [[sr:Википедија:Преусмерење]]<br /> [[sh:Wikipedia:Redirect]]<br /> [[fi:Wikipedia:Ohjaus]]<br /> [[sv:Wikipedia:Omdirigeringar]]<br /> [[ta:விக்கிப்பீடியா:வழிமாற்று]]<br /> [[te:వికీపీడియా:దారిమార్పు]]<br /> [[vi:Wikipedia:Trang đổi hướng]]<br /> [[yi:װיקיפּעדיע:ווייטערפירונג]]<br /> [[zh-yue:Wikipedia:跳轉]]<br /> [[zh:Wikipedia:重定向]]</div> Code-structure https://en.wikipedia.org/w/index.php?title=User:Code-structure/sandbox&diff=517816699 User:Code-structure/sandbox 2012-10-14T22:36:01Z <p>Code-structure: </p> <hr /> <div>&lt;!-- EDIT BELOW THIS LINE --&gt;<br /> Grammar of the '''C++''' language is available as part of the standard.</div> Code-structure https://en.wikipedia.org/w/index.php?title=User:Code-structure/sandbox&diff=517816395 User:Code-structure/sandbox 2012-10-14T22:33:50Z <p>Code-structure: ←Created page with &#039;{{User sandbox}} &lt;!-- EDIT BELOW THIS LINE --&gt; Grammar of the &#039;&#039;&#039;C++&#039;&#039;&#039; language is available as part of the standard.&#039;</p> <hr /> <div>{{User sandbox}}<br /> &lt;!-- EDIT BELOW THIS LINE --&gt;<br /> Grammar of the '''C++''' language is available as part of the standard.</div> Code-structure https://en.wikipedia.org/w/index.php?title=C%2B%2B11&diff=517816059 C++11 2012-10-14T22:31:29Z <p>Code-structure: Better language.</p> <hr /> <div>{{ multiple issues<br /> | refimprove = July 2012<br /> | lead too short = July 2012<br /> }}<br /> {{manual|date=July 2012}}<br /> <br /> '''C++11''' (formerly known as '''C++0x'''&lt;ref&gt;http://video.google.com/videoplay?docid=5262479012306588324#&lt;/ref&gt;) is the most recent version of the standard of the [[C++ programming language]]. It was approved by [[International Organization for Standardization|ISO]] on 12 August 2011, replacing [[C++03]].&lt;ref&gt;{{cite web|title=We have an international standard: C++0x is unanimously approved|url=http://herbsutter.com/2011/08/12/we-have-an-international-standard-c0x-is-unanimously-approved/| accessdate=12 August 2011}}&lt;/ref&gt; The name is derived from the tradition of naming language versions by the year of the specification's publication.<br /> <br /> C++11 includes several additions to the [[core language]] and extends the [[C++ standard library]], incorporating most of the [[C++ Technical Report 1]] (TR1) [[Library (computer science)|libraries]] — with the exception of the library of mathematical special functions.&lt;ref&gt;{{cite web|title=Bjarne Stroustrup: A C++0x overview|url=http://www.research.ibm.com/arl/seminar/media/stroustrup.pdf| accessdate=30 June 2011}}&lt;/ref&gt; C++11 was published as ''ISO/IEC 14882:2011''&lt;ref&gt;{{ cite web | authorlink = ISO | title = ISO/IEC 14882:2011 | publisher = ISO | date = 2 September 2011 | url = http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=50372 | accessdate =3 September 2011 }}&lt;/ref&gt; in September 2011 and is available for a fee. The working draft most similar to the published C++11 standard is N3337, dated 12 January 2012;&lt;ref&gt;[http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf]&lt;/ref&gt; it has only editorial corrections from the C++11 standard.&lt;ref&gt;http://stackoverflow.com/a/4653479/734069&lt;/ref&gt;<br /> <br /> ==Changes from the previous version of the standard==<br /> The modifications for C++ involve both the core language and the standard library.<br /> <br /> In the development of every utility of the 2011 standard, the committee has applied some directives:<br /> * Maintain stability and compatibility with [[ISO/IEC 14882|C++98]] and possibly with [[C (programming language)|C]];<br /> * Prefer introduction of new features through the standard library, rather than extending the core language;<br /> * Prefer changes that can evolve programming technique;<br /> * Improve C++ to facilitate systems and library design, rather than to introduce new features useful only to specific applications;<br /> * Increase type safety by providing safer alternatives to earlier unsafe techniques;<br /> * Increase performance and the ability to work directly with hardware;<br /> * Provide proper solutions for real-world problems;<br /> * Implement “zero-overhead” principle (additional support required by some utilities must be used only if the utility is used);<br /> * Make C++ easy to teach and to learn without removing any utility needed by expert programmers.<br /> <br /> Attention to beginners is considered important, because they will always compose the majority of computer programmers, and because many beginners would not intend to extend their knowledge of {{nowrap|C++}}, limiting themselves to operate in the aspects of the language in which they are specialized.{{Ref|web-strou-brief}}<br /> <br /> ==Extensions to the C++ core language==<br /> One function of the C++ committee is the development of the language core. Areas of the core language that were significantly improved include [[Thread (computer science)|multithreading]] support, [[generic programming]] support, uniform initialization, and performance enhancements.<br /> <br /> For the purposes of this article, core language features and changes are grouped into four general sections: run-time performance enhancements, build-time performance enhancements, usability enhancements, and new functionality. Some features could fall into multiple groups, but they are mentioned only in the group that primarily represents that feature.<br /> <br /> ==Core language runtime performance enhancements==<br /> These language features primarily exist to provide some kind of performance benefit, either of memory or of computational speed.<br /> <br /> ===Rvalue references and move constructors===<br /> In C++03 (and before), temporaries (termed &quot;[[value (computer science)|rvalue]]s&quot;, as they often lie on the right side of an assignment) were intended to never be modifiable — just as in C — and were considered to be indistinguishable from &lt;code&gt;const T&amp;amp;&lt;/code&gt; types; nevertheless, in some cases, temporaries could have been modified, a behavior that was even considered to be a useful loophole (for the former, see &lt;ref name=&quot;Sutter_Alexandrescu&quot;&gt;Sutter, Alexandrescu &quot;C++ coding standards&quot; #15&lt;/ref&gt;). C++11 adds a new non-const reference type called an {{visible anchor|rvalue reference}}, identified by &lt;code&gt;T&amp;amp;&amp;amp;&lt;/code&gt;. This refers to temporaries that are permitted to be modified after they are initialized, for the purpose of allowing &quot;move semantics&quot;.<br /> <br /> A chronic performance problem with C++03 is the costly and unnecessary deep copies that can happen implicitly when objects are passed by value. To illustrate the issue, consider that a &lt;code&gt;std::vector&amp;lt;T&amp;gt;&lt;/code&gt; is, internally, a wrapper around a C-style array with a size. If a &lt;code&gt;std::vector&amp;lt;T&amp;gt;&lt;/code&gt; temporary is created or returned from a function, it can be stored only by creating a new &lt;code&gt;std::vector&amp;lt;T&amp;gt;&lt;/code&gt; and copying all of the rvalue's data into it. Then the temporary and all its memory is destroyed. (For simplicity, this discussion neglects the [[return value optimization]]).<br /> <br /> In C++11, a [[b:More C++ Idioms/Move Constructor|{{visible anchor|move constructor}}]] of &lt;code&gt;std::vector&amp;lt;T&amp;gt;&lt;/code&gt; that takes an rvalue reference to a &lt;code&gt;std::vector&amp;lt;T&amp;gt;&lt;/code&gt; can copy the pointer to the internal C-style array out of the rvalue into the new &lt;code&gt;std::vector&amp;lt;T&amp;gt;&lt;/code&gt;, then set the pointer inside the rvalue to null. Since the temporary will never again be used, no code will try to access the null pointer, and because the pointer is null, its memory is not deleted when it goes out of scope. Hence, the operation not only forgoes the expense of a deep copy, but is safe and invisible.<br /> <br /> Rvalue references can provide performance benefits to existing code without needing to make any changes outside the standard library. The type of the returned value of a function returning a &lt;code&gt;std::vector&amp;lt;T&amp;gt;&lt;/code&gt; temporary does not need to be changed explicitly to &lt;code&gt;std::vector&amp;lt;T&amp;gt; &amp;amp;&amp;amp;&lt;/code&gt; to invoke the move constructor, as temporaries are considered rvalues automatically. (However, if &lt;code&gt;std::vector&amp;lt;T&amp;gt;&lt;/code&gt; is a C++03 version without a move constructor, then the copy constructor will be invoked with a &lt;code&gt;const std::vector&amp;lt;T&amp;gt;&amp;amp;&lt;/code&gt;, incurring a significant memory allocation.)<br /> <br /> For safety reasons, some restrictions are imposed. A named variable will never be considered to be an rvalue even if it is declared as such; in order to get an rvalue, the function template &lt;code&gt;std::move&amp;lt;T&amp;gt;()&lt;/code&gt; should be used. Rvalue references can also be modified only under certain circumstances, being intended to be used primarily with move constructors.<br /> <br /> Due to the nature of the wording of rvalue references, and to some modification to the wording for lvalue references (regular references), rvalue references allow developers to provide perfect function forwarding. When combined with [[#Variadic_templates|variadic templates]], this ability allows for function templates that can perfectly forward arguments to another function that takes those particular arguments. This is most useful for forwarding constructor parameters, to create factory functions that will automatically call the correct constructor for those particular arguments. This is seen in the [http://en.cppreference.com/w/cpp/container/vector/emplace_back emplace_back] set of the C++ standard library methods.<br /> <br /> ===constexpr - Generalized constant expressions===<br /> C++ has always had the concept of constant expressions. These are expressions such as &lt;code&gt;3+4&lt;/code&gt; that will always yield the same results, at compile time and at run time. Constant expressions are optimization opportunities for compilers, and compilers frequently execute them at compile time and hardcode the results in the program. Also, there are a number of places where the C++ specification requires the use of constant expressions. Defining an array requires a constant expression, and enumerator values must be constant expressions.<br /> <br /> However, a constant expression has never been allowed to contain a function call or object constructor. So a piece of code as simple as this is illegal:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> int get_five() {return 5;}<br /> <br /> int some_value[get_five() + 7]; // Create an array of 12 integers. Ill-formed C++<br /> &lt;/source&gt;<br /> <br /> This was not legal in C++03, because &lt;code&gt;get_five() + 7&lt;/code&gt; is not a constant expression. A C++03 compiler has no way of knowing if &lt;code&gt;get_five()&lt;/code&gt; actually is constant at runtime. In theory, this function could affect a global variable, call other non-runtime constant functions, etc.<br /> <br /> C++11 introduced the keyword &lt;code&gt;constexpr&lt;/code&gt;, which allows the user to guarantee that a function or object constructor is a compile-time constant.&lt;ref&gt;{{cite web|url=http://www.stroustrup.com/sac10-constexpr.pdf|title=General Constant Expressions for System Programming Languages, Proceedings SAC ’10 | author=Gabriel Dos Reis and Bjarne Stroustrup |date=22 March 2010}}&lt;/ref&gt; The above example can be rewritten as follows:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> constexpr int get_five() {return 5;}<br /> <br /> int some_value[get_five() + 7]; // Create an array of 12 integers. Legal C++11<br /> &lt;/source&gt;<br /> <br /> This allows the compiler to understand, and verify, that &lt;code&gt;get_five&lt;/code&gt; is a compile-time constant.<br /> <br /> The use of &lt;code&gt;constexpr&lt;/code&gt; on a function imposes some limitations on what that function can do. First, the function must have a non-void return type. Second, the function body cannot declare variables or define new types. Third, the body may contain only declarations, null statements and a single return statement. There must exist argument values such that, after argument substitution, the expression in the return statement produces a constant expression.<br /> <br /> Prior to C++11, the values of variables could be used in constant expressions only if the variables are declared const, have an initializer which is a constant expression, and are of integral or enumeration type. C++11 removes the restriction that the variables must be of integral or enumeration type if they are defined with the &lt;code&gt;constexpr&lt;/code&gt; keyword:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> constexpr double earth_gravitational_acceleration = 9.8;<br /> constexpr double moon_gravitational_acceleration = earth_gravitational_acceleration / 6.0;<br /> &lt;/source&gt;<br /> <br /> Such data variables are implicitly const, and must have an initializer which must be a constant expression.<br /> <br /> In order to construct constant expression data values from user-defined types, constructors can also be declared with &lt;code&gt;constexpr&lt;/code&gt;. A &lt;code&gt;constexpr&lt;/code&gt; constructor's function body can contain only declarations and null statements, and cannot declare variables or define types, as with a &lt;code&gt;constexpr&lt;/code&gt; function. There must exist argument values such that, after argument substitution, it initializes the class's members with constant expressions. The destructors for such types must be trivial.<br /> <br /> The copy constructor for a type with any &lt;code&gt;constexpr&lt;/code&gt; constructors should usually also be defined as a &lt;code&gt;constexpr&lt;/code&gt; constructor, in order to allow objects of the type to be returned by value from a constexpr function. Any member function of a class, such as copy constructors, operator overloads, etc., can be declared as &lt;code&gt;constexpr&lt;/code&gt;, so long as they meet the requirements for constexpr functions. This allows the compiler to copy classes at compile time, perform operations on them, etc.<br /> <br /> If a constexpr function or constructor is called with arguments which aren't constant expressions, the call behaves as if the function were not constexpr, and the resulting value is not a constant expression. Likewise, if the expression in the return statement of a constexpr function does not evaluate to a constant expression for a particular invocation, the result is not a constant expression.<br /> <br /> ===Modification to the definition of plain old data===<br /> In C++03, a class or struct must follow a number of rules in order for it to be considered a [[Plain Old Data Structures|plain old data]] (POD) type. Types that fit this definition produce object layouts that are compatible with C, and they could also be initialized statically. However, the definition in C++03 is unnecessarily strict{{citation needed|date=April 2012}} and there are good reasons{{clarify|date=April 2012}} for allowing more types to fit the POD definition{{citation needed|date=April 2012}}.<br /> <br /> C++11 relaxed several of the POD rules, by dividing the POD concept into two separate concepts: ''trivial'' and ''standard-layout''.<br /> <br /> A type that is ''trivial'' can be statically initialized. It also means that it is legal to copy data around via &lt;code&gt;memcpy&lt;/code&gt;, rather than having to use a copy constructor. The lifetime of a ''trivial'' type begins when its storage is defined, not when a constructor completes.<br /> <br /> A trivial class or struct is defined as one that:<br /> <br /> # Has a trivial default constructor. This may use the [[#Explicitly defaulted and deleted special member functions|default constructor syntax]] (&lt;code&gt;SomeConstructor() = default;&lt;/code&gt;).<br /> # Has trivial copy and move constructors, which may use the default syntax.<br /> # Has trivial copy and move assignment operators, which may use the default syntax.<br /> # Has a trivial destructor, which must not be virtual.<br /> <br /> Constructors are trivial only if there are no virtual member functions of the class and no virtual base classes. Copy/move operations also require that all of the non-static data members be trivial.<br /> <br /> A type that is ''standard-layout'' means that it orders and packs its members in a way that is compatible with C. A class or struct is standard-layout, by definition, provided:<br /> <br /> # It has no virtual functions<br /> # It has no virtual base classes<br /> # All its non-static data members have the same access control (public, private, protected)<br /> # All its non-static data members, including any in its base classes, are in the same one class in the hierarchy<br /> # The above rules also apply to all the base classes and to all non-static data members in the class hierarchy<br /> # It has no base classes of the same type as the first defined non-static data member<br /> <br /> A class/struct/union is considered POD if it is trivial, standard-layout, and all of its non-static data members and base classes are PODs.<br /> <br /> By separating these concepts, it becomes possible to give up one without losing the other. A class with complex move and copy constructors may not be trivial, but it could be standard-layout and thus interop with C. Similarly, a class with public and private non-static data members would not be standard-layout, but it would be trivial and thus &lt;code&gt;memcpy&lt;/code&gt;-able.<br /> <br /> ==Core language build time performance enhancements==<br /> <br /> ===Extern template===<br /> In C++03, the compiler must instantiate a template whenever a fully specified template is encountered in a translation unit. If the template is instantiated with the same types in many translation units, this can dramatically increase compile times. There is no way to prevent this in C++03, so C++11 introduced extern template declarations, analogous to extern data declarations.<br /> <br /> C++03 has this syntax to oblige the compiler to instantiate a template:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template class std::vector&lt;MyClass&gt;;<br /> &lt;/source&gt;<br /> <br /> C++11 now provides this syntax:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> extern template class std::vector&lt;MyClass&gt;;<br /> &lt;/source&gt;<br /> <br /> which tells the compiler ''not'' to instantiate the template in this translation unit.<br /> <br /> ==Core language usability enhancements==<br /> These features exist for the primary purpose of making the language easier to use. These can improve type safety, minimize code repetition, make erroneous code less likely, etc.<br /> <br /> ===Initializer lists===<br /> C++03 inherited the initializer-list feature from C. A struct or array is given a list of arguments in curly brackets, in the order of the members' definitions in the struct. These initializer-lists are recursive, so an array of structs or struct containing other structs can use them.<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct Object<br /> {<br /> float first;<br /> int second;<br /> };<br /> <br /> Object scalar = {0.43f, 10}; //One Object, with first=0.43f and second=10<br /> Object anArray[] = {{13.4f, 3}, {43.28f, 29}, {5.934f, 17}}; //An array of three Objects<br /> &lt;/source&gt;<br /> <br /> This is very useful for static lists or just for initializing a struct to a particular value. C++ also provides constructors to initialize an object, but they are often not as convenient as the initializer list. However C++03 allows initializer-lists only on structs and classes that conform to the Plain Old Data (POD) definition; C++11 extends initializer-lists, so they can be used for all classes including standard containers like &lt;code&gt;std::vector&lt;/code&gt;.<br /> <br /> C++11 binds the concept to a template, called &lt;code&gt;std::initializer_list&lt;/code&gt;. This allows constructors and other functions to take initializer-lists as parameters. For example:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> class SequenceClass {<br /> public:<br /> SequenceClass(std::initializer_list&lt;int&gt; list);<br /> };<br /> &lt;/source&gt;<br /> <br /> This allows &lt;code&gt;SequenceClass&lt;/code&gt; to be constructed from a sequence of integers, as such:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> SequenceClass some_var = {1, 4, 5, 6};<br /> &lt;/source&gt;<br /> <br /> This constructor is a special kind of constructor, called an initializer-list-constructor. Classes with such a constructor are treated specially during uniform initialization (see [[#Uniform_initialization|below]])<br /> <br /> The class &lt;code&gt;std::initializer_list&amp;lt;&amp;gt;&lt;/code&gt; is a first-class C++11 standard library type. However, they can be initially constructed statically by the C++11 compiler only through the use of the {} syntax. The list can be copied once constructed, though this is only a copy-by-reference. An initializer list is constant; its members cannot be changed once the initializer list is created, nor can the data in those members be changed.<br /> <br /> Because initializer_list is a real type, it can be used in other places besides class constructors. Regular functions can take typed initializer lists as arguments. For example:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> void function_name(std::initializer_list&lt;float&gt; list);<br /> <br /> function_name({1.0f, -3.45f, -0.4f});<br /> &lt;/source&gt;<br /> <br /> Standard containers can also be initialized in the following ways:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> std::vector&lt;std::string&gt; v = { &quot;xyzzy&quot;, &quot;plugh&quot;, &quot;abracadabra&quot; };<br /> std::vector&lt;std::string&gt; v({ &quot;xyzzy&quot;, &quot;plugh&quot;, &quot;abracadabra&quot; });<br /> std::vector&lt;std::string&gt; v{ &quot;xyzzy&quot;, &quot;plugh&quot;, &quot;abracadabra&quot; }; // see &quot;Uniform initialization&quot; below<br /> &lt;/source&gt;<br /> <br /> ===Uniform initialization===<br /> C++03 has a number of problems with initializing types. There are several ways to initialize types, and they do not all produce the same results when interchanged. The traditional constructor syntax, for example, can look like a function declaration, and steps must be taken to ensure that the compiler's [[most vexing parse]] rule will not mistake it for such. Only aggregates and POD types can be initialized with aggregate initializers (using &lt;code&gt;SomeType var = {/*stuff*/};&lt;/code&gt;).<br /> <br /> C++11 provides a syntax that allows for fully uniform type initialization that works on any object. It expands on the initializer list syntax:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct BasicStruct {<br /> int x;<br /> double y;<br /> };<br /> <br /> struct AltStruct {<br /> AltStruct(int x, double y) : x_{x}, y_{y} {}<br /> <br /> private:<br /> int x_;<br /> double y_;<br /> };<br /> <br /> BasicStruct var1{5, 3.2};<br /> AltStruct var2{2, 4.3};<br /> &lt;/source&gt;<br /> <br /> The initialization of &lt;code&gt;var1&lt;/code&gt; behaves exactly as though it were aggregate-initialization. That is, each data member of an object, in turn, will be copy-initialized with the corresponding value from the initializer-list. Implicit type conversion will be used where necessary. If no conversion exists, or only a narrowing conversion exists, the program is ill-formed. The initialization of &lt;code&gt;var2&lt;/code&gt; invokes the constructor.<br /> <br /> One is also able to do the following:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> <br /> struct IdString {<br /> std::string name;<br /> int identifier;<br /> };<br /> <br /> IdString get_string()<br /> {<br /> return {&quot;foo&quot;, 42}; //Note the lack of explicit type.<br /> }<br /> &lt;/source&gt;<br /> <br /> Uniform initialization does not replace constructor syntax. There are still times when constructor syntax is required. If a class has an initializer list constructor (&lt;code&gt;TypeName(initializer_list&lt;SomeType&gt;);&lt;/code&gt;), then it takes priority over other forms of construction, provided that the initializer list conforms to the sequence constructor's type. The C++11 version of &lt;code&gt;std::vector&lt;/code&gt; has an initializer list constructor for its template type. This means that the following code:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> std::vector&lt;int&gt; the_vec{4};<br /> &lt;/source&gt;<br /> <br /> will call the initializer list constructor, not the constructor of &lt;code&gt;std::vector&lt;/code&gt; that takes a single size parameter and creates the vector with that size. To access the latter constructor, the user will need to use the standard constructor syntax directly.<br /> <br /> ===Type inference===<br /> In C++03 (and C), the type of a variable must be explicitly specified in order to use it. However, with the advent of template types and template metaprogramming techniques, the type of something, particularly the well-defined return value of a function, may not be easily expressed. Therefore, storing intermediates in variables is difficult, possibly requiring knowledge of the internals of a particular metaprogramming library.<br /> <br /> C++11 allows this to be mitigated in two ways. First, the definition of a variable with an explicit initialization can use the &lt;code&gt;auto&lt;/code&gt; keyword. This creates a variable of the specific type of the initializer:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> auto some_strange_callable_type = boost::bind(&amp;some_function, _2, _1, some_object);<br /> auto other_variable = 5;<br /> &lt;/source&gt;<br /> <br /> The type of &lt;code&gt;some_strange_callable_type&lt;/code&gt; is simply whatever the particular template function override of &lt;code&gt;boost::bind&lt;/code&gt; returns for those particular arguments. This type is easily determined procedurally by the compiler as part of its semantic analysis duties, but is not easy for the user to determine upon inspection.<br /> <br /> The type of &lt;code&gt;other_variable&lt;/code&gt; is also well-defined, but it is easier for the user to determine. It is an &lt;code&gt;int&lt;/code&gt;, which is the same type as the integer literal.<br /> <br /> Additionally, the keyword &lt;code&gt;[[decltype]]&lt;/code&gt; can be used to determine the type of an expression at compile-time. For example:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> int some_int;<br /> decltype(some_int) other_integer_variable = 5;<br /> &lt;/source&gt;<br /> <br /> This is more useful in conjunction with &lt;code&gt;auto&lt;/code&gt;, since the type of an auto variable is known only to the compiler. However, &lt;code&gt;decltype&lt;/code&gt; can also be very useful for expressions in code that makes heavy use of operator overloading and specialized types.<br /> <br /> &lt;code&gt;auto&lt;/code&gt; is also useful for reducing the verbosity of the code. For instance, instead of writing<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> for (std::vector&lt;int&gt;::const_iterator itr = myvec.cbegin(); itr != myvec.cend(); ++itr)<br /> &lt;/source&gt;<br /> the programmer can use the shorter<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> for (auto itr = myvec.cbegin(); itr != myvec.cend(); ++itr)<br /> &lt;/source&gt;<br /> <br /> This difference grows as the programmer begins to nest containers, though in such cases &lt;code&gt;typedef&lt;/code&gt;s are a good way to decrease the amount of code.<br /> <br /> The type denoted by &lt;code&gt;decltype&lt;/code&gt; can be different from the type deduced by &lt;code&gt;auto&lt;/code&gt;.<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> #include &lt;vector&gt;<br /> int main()<br /> {<br /> const std::vector&lt;int&gt; v(1);<br /> auto a = v[0]; // a has type int<br /> decltype(v[0]) b = 1; // b has type const int&amp;, the return type of<br /> // std::vector&lt;int&gt;::operator[](size_type) const<br /> auto c = 0; // c has type int<br /> auto d = c; // d has type int<br /> decltype(c) e; // e has type int, the type of the entity named by c<br /> decltype((c)) f = c; // f has type int&amp;, because (c) is an lvalue<br /> decltype(0) g; // g has type int, because 0 is an rvalue<br /> }<br /> &lt;/source&gt;<br /> <br /> ===Range-based for-loop===<br /> In C++03, iterating over the elements of a list requires a lot of code. Other languages have implemented support for [[syntactic sugar]] that allow the programmer to write a simple “foreach” statement that automatically traverses items in a list.<br /> One of those languages is the [[Java (programming language)|Java]] programming language, which received support for what has been defined as enhanced for loops in [[Java version history#J2SE 5.0 .28September_30.2C_2004.29|Java 5.0]].&lt;ref&gt;{{cite web|url=http://docs.oracle.com/javase/1.5.0/docs/guide/language/index.html |title=Java Programming Language: Enhancements in JDK 5 |publisher=Oracle.com}}&lt;/ref&gt;<br /> <br /> C++11 added a similar feature. The statement &lt;code&gt;for&lt;/code&gt; allows for easy iteration over a list of elements:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> int my_array[5] = {1, 2, 3, 4, 5};<br /> for (int &amp;x : my_array) {<br /> x *= 2;<br /> }<br /> &lt;/source&gt;<br /> <br /> This form of &lt;code&gt;for&lt;/code&gt;, called the “range-based for”, will iterate over each element in the list. It will work for C-style arrays, initializer lists, and any type that has &lt;code&gt;begin()&lt;/code&gt; and &lt;code&gt;end()&lt;/code&gt; functions defined for it that return iterators. All of the standard library containers that have begin/end pairs will work with the range-based for statement.<br /> <br /> ===Lambda functions and expressions===<br /> {{main|Anonymous function#C++}}<br /> <br /> C++11 provides the ability to create [[anonymous function]]s, called lambda functions.&lt;ref&gt;<br /> {{cite web<br /> |url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1968.pdf<br /> |title=Document no: N1968=06-0038- Lambda expressions and closures for C++<br /> |publisher=Open Standards<br /> }}&lt;/ref&gt;<br /> These are defined as follows:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> [](int x, int y) { return x + y; }<br /> &lt;/source&gt;<br /> <br /> The return type is implicit; it returns the type of the return expression (&lt;code&gt;decltype(x+y)&lt;/code&gt;). The return type of a lambda can be omitted as long as all &lt;code&gt;return&lt;/code&gt; expressions return the same type.<br /> A lambda can optionally be a [[Closure (computer science)|closure]].<br /> <br /> ===Alternative function syntax===<br /> [[C (programming language)|Standard C]] function declaration syntax was perfectly adequate for the feature set of the C language. As C++ evolved from C, it kept the basic syntax and extended it where necessary. However, as C++ became more complicated, it exposed a number of limitations, particularly with regard to template function declarations. The following, for example, is not allowed in C++03:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template&lt;class Lhs, class Rhs&gt;<br /> Ret adding_func(const Lhs &amp;lhs, const Rhs &amp;rhs) {return lhs + rhs;} //Ret must be the type of lhs+rhs<br /> &lt;/source&gt;<br /> <br /> The type &lt;code&gt;Ret&lt;/code&gt; is whatever the addition of types &lt;code&gt;Lhs&lt;/code&gt; and &lt;code&gt;Rhs&lt;/code&gt; will produce. Even with the aforementioned C++11 functionality of &lt;code&gt;decltype&lt;/code&gt;, this is not possible:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template&lt;class Lhs, class Rhs&gt;<br /> decltype(lhs+rhs) adding_func(const Lhs &amp;lhs, const Rhs &amp;rhs) {return lhs + rhs;} //Not legal C++11<br /> &lt;/source&gt;<br /> <br /> This is not legal C++ because &lt;code&gt;lhs&lt;/code&gt; and &lt;code&gt;rhs&lt;/code&gt; have not yet been defined; they will not be valid identifiers until after the parser has parsed the rest of the function prototype.<br /> <br /> To work around this, C++11 introduced a new function declaration syntax, with a ''trailing-return-type'':<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template&lt;class Lhs, class Rhs&gt;<br /> auto adding_func(const Lhs &amp;lhs, const Rhs &amp;rhs) -&gt; decltype(lhs+rhs) {return lhs + rhs;}<br /> &lt;/source&gt;<br /> <br /> This syntax can be used for more mundane function declarations and definitions:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct SomeStruct {<br /> auto func_name(int x, int y) -&gt; int;<br /> };<br /> <br /> auto SomeStruct::func_name(int x, int y) -&gt; int {<br /> return x + y;<br /> }<br /> &lt;/source&gt;<br /> <br /> The use of the keyword “auto” in this case means something different from its use in automatic type deduction.<br /> <br /> ===Object construction improvement===<br /> In C++03, constructors of a class are not allowed to call other constructors of that class; each constructor must construct all of its class members itself or call a common member function, like these,<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> class SomeType {<br /> int number;<br /> <br /> public:<br /> SomeType(int new_number) : number(new_number) {}<br /> SomeType() : number(42) {}<br /> };<br /> &lt;/source&gt;<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> class SomeType {<br /> int number;<br /> <br /> private:<br /> void Construct(int new_number) { number = new_number; }<br /> public:<br /> SomeType(int new_number) { Construct(new_number); }<br /> SomeType() { Construct(42); }<br /> };<br /> &lt;/source&gt;<br /> <br /> Constructors for base classes cannot be directly exposed to derived classes; each derived class must implement constructors even if a base class constructor would be appropriate. Non-constant data members of classes cannot be initialized at the site of the declaration of those members. They can be initialized only in a constructor.<br /> <br /> C++11 provides solutions to all of these problems.<br /> <br /> C++11 allows constructors to call other peer constructors (known as [[Delegation (programming)|delegation]]). This allows constructors to utilize another constructor's behavior with a minimum of added code. Examples of other languages similar to C++ that provide delegation are [[Java (programming language)|Java]], [[C Sharp (programming language)|C#]], and [[D (programming language)|D]].<br /> <br /> This syntax is as follows:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> class SomeType {<br /> int number;<br /> <br /> public:<br /> SomeType(int new_number) : number(new_number) {}<br /> SomeType() : SomeType(42) {}<br /> };<br /> &lt;/source&gt;<br /> <br /> Notice that, in this case, the same effect could have been achieved by making new_number a defaulting parameter. The new syntax, however, allows the default value (42) to be expressed in the implementation rather than the interface &amp;mdash; a benefit to maintainers of library code since default values for function parameters are “baked in” to call sites, whereas constructor delegation allows the value to be changed without recompilation of the code using the library.<br /> <br /> This comes with a caveat: C++03 considers an object to be constructed when its constructor finishes executing, but C++11 considers an object constructed once ''any'' constructor finishes execution. Since multiple constructors will be allowed to execute, this will mean that each delegate constructor will be executing on a fully constructed object of its own type. Derived class constructors will execute after all delegation in their base classes is complete.<br /> <br /> For base-class constructors, C++11 allows a class to specify that base class constructors will be inherited. This means that the C++11 compiler will generate code to perform the inheritance, the forwarding of the derived class to the base class. Note that this is an all-or-nothing feature; either all of that base class's constructors are forwarded or none of them are. Also, note that there are restrictions for multiple inheritance, such that class constructors cannot be inherited from two classes that use constructors with the same signature. Nor can a constructor in the derived class exist that matches a signature in the inherited base class.<br /> <br /> The syntax is as follows:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> class BaseClass {<br /> public:<br /> BaseClass(int value);<br /> };<br /> <br /> class DerivedClass : public BaseClass {<br /> public:<br /> using BaseClass::BaseClass;<br /> };<br /> &lt;/source&gt;<br /> <br /> For member initialization, C++11 allows the following syntax:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> class SomeClass {<br /> public:<br /> SomeClass() {}<br /> explicit SomeClass(int new_value) : value(new_value) {}<br /> <br /> private:<br /> int value = 5;<br /> };<br /> &lt;/source&gt;<br /> <br /> Any constructor of the class will initialize &lt;code&gt;value&lt;/code&gt; with 5, if the constructor does not override the initialization with its own. So the above empty constructor will initialize &lt;code&gt;value&lt;/code&gt; as the class definition states, but the constructor that takes an int will initialize it to the given parameter.<br /> <br /> It can also use constructor or uniform initialization, instead of the equality initialization shown above.<br /> <br /> ===Explicit overrides and final===<br /> In C++03, it is possible to accidentally create a new virtual function, when one intended to override a base class function. For example:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct Base {<br /> virtual void some_func(float);<br /> };<br /> <br /> struct Derived : Base {<br /> virtual void some_func(int);<br /> };<br /> &lt;/source&gt;<br /> <br /> The &lt;code&gt;Derived::some_func&lt;/code&gt; is intended to replace the base class version. But because it has a different interface, it creates a second virtual function. This is a common problem, particularly when a user goes to modify the base class.<br /> <br /> C++11 provides syntax to solve this problem.<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct Base {<br /> virtual void some_func(float);<br /> };<br /> <br /> struct Derived : Base {<br /> virtual void some_func(int) override; // ill-formed because it doesn't override a base class method<br /> };<br /> &lt;/source&gt;<br /> <br /> The &lt;code&gt;override&lt;/code&gt; special identifier means that the compiler will check the base class(es) to see if there is a virtual function with this exact signature. And if there is not, the compiler will error out.<br /> <br /> C++11 also adds the ability to prevent inheriting from classes or simply preventing overriding methods in derived classes. This is done with the special identifier &lt;code&gt;final&lt;/code&gt;. For example:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct Base1 final { };<br /> <br /> struct Derived1 : Base1 { }; // ill-formed because the class Base1 has been marked final<br /> <br /> struct Base2 {<br /> virtual void f() final;<br /> };<br /> <br /> struct Derived2 : Base2 {<br /> void f(); // ill-formed because the virtual function Base2::f has been marked final<br /> };<br /> &lt;/source&gt;<br /> <br /> In this example, the &lt;code&gt;virtual void f() final;&lt;/code&gt; statement declares a new virtual function, but it also prevents derived classes from overriding it. It also has the effect of preventing derived classes from using that particular function name and parameter combination.<br /> <br /> Note that neither &lt;code&gt;override&lt;/code&gt; nor &lt;code&gt;final&lt;/code&gt; are language keywords. They are technically identifiers; they gain special meaning only when used in those specific contexts. In any other location, they can be valid identifiers.<br /> <br /> ===Null pointer constant===<br /> For the purposes of this section and this section alone, every occurrence of “&lt;code&gt;0&lt;/code&gt;” is meant as “a constant expression which evaluates to &lt;code&gt;0&lt;/code&gt;, which is of type int”. In reality, the constant expression can be of any integral type.<br /> <br /> Since the dawn of C in 1972, the constant &lt;code&gt;[[0 (number)|0]]&lt;/code&gt; has had the double role of constant integer and null pointer constant. The ambiguity inherent in the double meaning of &lt;code&gt;0&lt;/code&gt; was dealt with in C by the use of the preprocessor macro &lt;code&gt;NULL&lt;/code&gt;, which commonly expands to either &lt;code&gt;((void*)0)&lt;/code&gt; or &lt;code&gt;0&lt;/code&gt;. C++ didn't adopt the same behavior, allowing only &lt;code&gt;0&lt;/code&gt; as a null pointer constant. This interacts poorly with function overloading:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> void foo(char *);<br /> void foo(int);<br /> &lt;/source&gt;<br /> <br /> If &lt;code&gt;NULL&lt;/code&gt; is defined as &lt;code&gt;0&lt;/code&gt; (which is usually the case in C++), the statement &lt;code&gt;foo(NULL);&lt;/code&gt; will call &lt;code&gt;foo(int)&lt;/code&gt;, which is almost certainly not what the programmer intended, and not what a superficial reading of the code suggests.<br /> <br /> C++11 corrects this by introducing a new keyword to serve as a distinguished null pointer constant: &lt;code&gt;nullptr&lt;/code&gt;. It is of type &lt;code&gt;nullptr_t&lt;/code&gt;, which is implicitly convertible and comparable to any pointer type or pointer-to-member type. It is not implicitly convertible or comparable to integral types, except for &lt;code&gt;bool&lt;/code&gt;. While the original proposal specified that an rvalue of type &lt;code&gt;nullptr&lt;/code&gt; should not be convertible to &lt;code&gt;bool&lt;/code&gt;, the core language working group decided that such a conversion would be desirable, for consistency with regular pointer types. The proposed wording changes were unanimously voted into the Working Paper in June 2008.{{Ref|n2697}}<br /> <br /> For backwards compatibility reasons, &lt;code&gt;0&lt;/code&gt; remains a valid null pointer constant.<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> char *pc = nullptr; // OK<br /> int *pi = nullptr; // OK<br /> bool b = nullptr; // OK. b is false.<br /> int i = nullptr; // error<br /> <br /> foo(nullptr); // calls foo(char *), not foo(int);<br /> &lt;/source&gt;<br /> <br /> ===Strongly typed enumerations===<br /> In C++03, enumerations are not type-safe. They are effectively integers, even when the enumeration types are distinct. This allows the comparison between two enum values of different enumeration types. The only safety that C++03 provides is that an integer or a value of one enum type does not convert implicitly to another enum type. Additionally, the underlying integral type is implementation-defined; code that depends on the size of the enumeration is therefore non-portable. Lastly, enumeration values are scoped to the enclosing scope. Thus, it is not possible for two separate enumerations to have matching member names.<br /> <br /> C++11 allows a special classification of enumeration that has none of these issues. This is expressed using the &lt;code&gt;enum class&lt;/code&gt; (&lt;code&gt;enum struct&lt;/code&gt; is also accepted as a synonym) declaration:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> enum class Enumeration {<br /> Val1,<br /> Val2,<br /> Val3 = 100,<br /> Val4 // = 101<br /> };<br /> &lt;/source&gt;<br /> <br /> This enumeration is type-safe. Enum class values are not implicitly converted to integers; therefore, they cannot be compared to integers either (the expression &lt;code&gt;Enumeration::Val4 == 101&lt;/code&gt; gives a compiler error).<br /> <br /> The underlying type of enum classes is always known. The default type is &lt;code&gt;int&lt;/code&gt;; this can be overridden to a different integral type as can be seen in the following example:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> enum class Enum2 : unsigned int {Val1, Val2};<br /> &lt;/source&gt;<br /> <br /> With old-style enumerations the values are placed in the outer scope. With new-style enumerations they are placed within the scope of the enum class name. So in the above example, &lt;code&gt;Val1&lt;/code&gt; is undefined, but &lt;code&gt;Enum2::Val1&lt;/code&gt; is defined.<br /> <br /> There is also a transitional syntax to allow old-style enumerations to provide explicit scoping as well as the definition of the underlying type:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> enum Enum3 : unsigned long {Val1 = 1, Val2};<br /> &lt;/source&gt;<br /> <br /> In this case the enumerator names are defined in the enumeration's scope (&lt;code&gt;Enum3::Val1&lt;/code&gt;), but for backwards compatibility they are also placed in the enclosing scope.<br /> <br /> Forward-declaring enums is also possible in C++11. Previously, enum types could not be forward-declared because the size of the enumeration depends on the definition of its members. As long as the size of the enumeration is specified either implicitly or explicitly, it can be forward-declared:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> enum Enum1; // Illegal in C++03 and C++11; the underlying type cannot be determined.<br /> enum Enum2 : unsigned int; // Legal in C++11, the underlying type is explicitly specified.<br /> enum class Enum3; // Legal in C++11, the underlying type is int.<br /> enum class Enum4 : unsigned int; // Legal in C++11.<br /> enum Enum2 : unsigned short; // Illegal in C++11, because Enum2 was previously declared with a different underlying type.<br /> &lt;/source&gt;<br /> <br /> ===Right angle bracket===<br /> C++03's parser defines “&lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt;” as the right shift operator in all cases. However, with nested template declarations, there is a tendency for the programmer to neglect to place a space between the two right angle brackets, thus causing a compiler syntax error.<br /> <br /> C++11 improves the specification of the parser so that multiple right angle brackets will be interpreted as closing the template argument list where it is reasonable. This can be overridden by using parentheses:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template&lt;bool Test&gt; class SomeType;<br /> std::vector&lt;SomeType&lt;1&gt;2&gt;&gt; x1; // Interpreted as a std::vector of SomeType&lt;true&gt; 2&gt;,<br /> // which is not legal syntax. 1 is true.<br /> std::vector&lt;SomeType&lt;(1&gt;2)&gt;&gt; x1; // Interpreted as std::vector of SomeType&lt;false&gt;,<br /> // which is legal C++11 syntax. (1&gt;2) is false.<br /> &lt;/source&gt;<br /> <br /> ===Explicit conversion operators===<br /> C++98 added the &lt;code&gt;explicit&lt;/code&gt; keyword as a modifier on constructors to prevent single-argument constructors from being used as implicit type conversion operators. However, this does nothing for actual conversion operators. For example, a smart pointer class may have an &lt;code&gt;operator bool()&lt;/code&gt; to allow it to act more like a primitive pointer: if it includes this conversion, it can be tested with &lt;code&gt;if (smart_ptr_variable)&lt;/code&gt; (which would be true if the pointer was non-null and false otherwise). However, this allows other, unintended conversions as well. Because C++ &lt;code&gt;bool&lt;/code&gt; is defined as an arithmetic type, it can be implicitly converted to integral or even floating-point types, which allows for mathematical operations that are not intended by the user.<br /> <br /> In C++11, the &lt;code&gt;explicit&lt;/code&gt; keyword can now be applied to conversion operators. As with constructors, it prevents the use of those conversion functions in implicit conversions. However, language contexts that specifically require a boolean value (the conditions of if-statements and loops, as well as operands to the logical operators) count as explicit conversions and can thus use a bool conversion operator.<br /> <br /> ===Alias templates===<br /> <br /> In C++03, it is possible to define a typedef only as a synonym for another type, including a synonym for a template specialization with all actual template arguments specified. It is not possible to create a typedef template. For example:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template &lt;typename First, typename Second, int Third&gt;<br /> class SomeType;<br /> <br /> template &lt;typename Second&gt;<br /> typedef SomeType&lt;OtherType, Second, 5&gt; TypedefName; //Illegal in C++03<br /> &lt;/source&gt;<br /> <br /> This will not compile.<br /> <br /> C++11 adds this ability with the following syntax:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template &lt;typename First, typename Second, int Third&gt;<br /> class SomeType;<br /> <br /> template &lt;typename Second&gt;<br /> using TypedefName = SomeType&lt;OtherType, Second, 5&gt;;<br /> &lt;/source&gt;<br /> <br /> The &lt;code&gt;using&lt;/code&gt; syntax can be also used as type aliasing in C++11:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> typedef void (*Type)(double); // Old style<br /> using OtherType = void (*)(double); // New introduced syntax<br /> &lt;/source&gt;<br /> <br /> ===Unrestricted unions===<br /> In C++03, there are restrictions on what types of objects can be members of a &lt;code&gt;union&lt;/code&gt;. For example, unions cannot contain any objects that define a non-trivial constructor. C++11 lifts some of these restrictions.{{Ref|n2544}}<br /> <br /> * Unions can now contain objects that have a non-trivial constructor.<br /> * If so, the implicit default constructor of the union is deleted, forcing a manual definition.<br /> <br /> This is a simple example of a union permitted in C++11:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> #include &lt;new&gt; // Required for placement 'new'.<br /> //<br /> struct Point {<br /> Point() {}<br /> Point(int x, int y): x_(x), y_(y) {}<br /> int x_, y_;<br /> };<br /> //<br /> union U {<br /> int z;<br /> double w;<br /> Point p; // Illegal in C++03; legal in C++11.<br /> //<br /> // Due to the Point member, a constructor definition is now required.<br /> //<br /> U() {new(&amp;p) Point();} <br /> };<br /> &lt;/source&gt;<br /> <br /> The changes will not break any existing code since they only relax current rules.<br /> <br /> ==Core language functionality improvements==<br /> These features allow the language to do things that were previously impossible, exceedingly verbose, or required non-portable libraries.<br /> <br /> ===Variadic templates===<br /> {{main|variadic templates}}<br /> <br /> In C++11, templates can take variable numbers of template parameters. This also allows the definition of type-safe [[variadic function]]s.<br /> <br /> ===New string literals===<br /> C++03 offers two kinds of string literals. The first kind, contained within double quotes, produces a null-terminated array of type &lt;code&gt;const char&lt;/code&gt;. The second kind, defined as &lt;code&gt;L&quot;&quot;&lt;/code&gt;, produces a null-terminated array of type &lt;code&gt;const wchar_t&lt;/code&gt;, where &lt;code&gt;wchar_t&lt;/code&gt; is a wide-character of undefined size and semantics. Neither literal type offers support for string literals with [[UTF-8]], [[UTF-16]], or any other kind of [[Unicode]] [[Comparison of Unicode encodings|encodings]].<br /> <br /> For the purpose of enhancing support for Unicode in C++ compilers, the definition of the type &lt;code&gt;char&lt;/code&gt; has been modified to be both at least the size necessary to store an eight-bit coding of [[UTF-8]] and large enough to contain any member of the compiler's basic execution character set. It was previously defined as only the latter.<br /> <br /> There are three Unicode encodings that C++11 will support: [[UTF-8]], [[UTF-16]], and [[UTF-32]]. In addition to the previously noted changes to the definition of &lt;code&gt;char&lt;/code&gt;, C++11 adds two new character types: &lt;code&gt;char16_t&lt;/code&gt; and &lt;code&gt;char32_t&lt;/code&gt;. These are designed to store UTF-16 and UTF-32 respectively.<br /> <br /> The following shows how to create string literals for each of these encodings:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> u8&quot;I'm a UTF-8 string.&quot;<br /> u&quot;This is a UTF-16 string.&quot;<br /> U&quot;This is a UTF-32 string.&quot;<br /> &lt;/source&gt;<br /> <br /> The type of the first string is the usual &lt;code&gt;const char[]&lt;/code&gt;. The type of the second string is &lt;code&gt;const char16_t[]&lt;/code&gt;. The type of the third string is &lt;code&gt;const char32_t[]&lt;/code&gt;.<br /> <br /> When building Unicode string literals, it is often useful to insert Unicode codepoints directly into the string. To do this, C++11 allows the following syntax:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> u8&quot;This is a Unicode Character: \u2018.&quot;<br /> u&quot;This is a bigger Unicode Character: \u2018.&quot;<br /> U&quot;This is a Unicode Character: \u2018.&quot;<br /> &lt;/source&gt;<br /> <br /> The number after the &lt;code&gt;\u&lt;/code&gt; is a hexadecimal number; it does not need the usual &lt;code&gt;0x&lt;/code&gt; prefix. The identifier &lt;code&gt;\u&lt;/code&gt; represents a 16-bit Unicode codepoint; to enter a 32-bit codepoint, use &lt;code&gt;\U&lt;/code&gt; and a 32-bit hexadecimal number. Only valid Unicode codepoints can be entered. For example, codepoints on the range U+D800–U+DFFF are forbidden, as they are reserved for surrogate pairs in UTF-16 encodings.<br /> <br /> It is also sometimes useful to avoid escaping strings manually, particularly for using literals of [[XML]] files, scripting languages, or regular expressions. C++11 provides a raw string literal:<br /> <br /> &lt;pre&gt;<br /> R&quot;(The String Data \ Stuff &quot; )&quot;<br /> R&quot;delimiter(The String Data \ Stuff &quot; )delimiter&quot;<br /> &lt;/pre&gt;<br /> <br /> In the first case, everything between the &lt;code&gt;&quot;(&lt;/code&gt; and the &lt;code&gt;)&quot;&lt;/code&gt; is part of the string. The &lt;code&gt;&quot;&lt;/code&gt; and &lt;code&gt;\&lt;/code&gt; characters do not need to be escaped. In the second case, the &lt;code&gt;&quot;delimiter(&lt;/code&gt; starts the string, and it ends only when &lt;code&gt;)delimiter&quot;&lt;/code&gt; is reached. The string &lt;code&gt;delimiter&lt;/code&gt; can be any string up to 16 characters in length, including the empty string. This string cannot contain spaces, control characters, '&lt;code&gt;(&lt;/code&gt;', '&lt;code&gt;)&lt;/code&gt;', or the '&lt;code&gt;\&lt;/code&gt;' character. The use of this delimiter string allows the user to have &quot;&lt;code&gt;)&lt;/code&gt;&quot; characters within raw string literals. For example, &lt;code&gt;R&quot;delimiter((a-z))delimiter&quot;&lt;/code&gt; is equivalent to &lt;code&gt;&quot;(a-z)&quot;&lt;/code&gt;.{{Ref|n3000}}<br /> <br /> Raw string literals can be combined with the wide literal or any of the Unicode literal prefixes:<br /> <br /> &lt;pre&gt;<br /> u8R&quot;XXX(I'm a &quot;raw UTF-8&quot; string.)XXX&quot;<br /> uR&quot;*(This is a &quot;raw UTF-16&quot; string.)*&quot;<br /> UR&quot;(This is a &quot;raw UTF-32&quot; string.)&quot;<br /> &lt;/pre&gt;<br /> <br /> ===User-defined literals===<br /> C++03 provides a number of literals. The characters “&lt;code&gt;12.5&lt;/code&gt;” are a literal that is resolved by the compiler as a type &lt;code&gt;double&lt;/code&gt; with the value of 12.5. However, the addition of the suffix “&lt;code&gt;f&lt;/code&gt;”, as in “&lt;code&gt;12.5f&lt;/code&gt;”, creates a value of type &lt;code&gt;float&lt;/code&gt; that contains the value 12.5. The suffix modifiers for literals are fixed by the C++ specification, and C++ code cannot create new literal modifiers.<br /> <br /> C++11 also includes the ability for the user to define new kinds of literal modifiers that will construct objects based on the string of characters that the literal modifies.<br /> <br /> Literals transformation is redefined into two distinct phases: raw and cooked. A raw literal is a sequence of characters of some specific type, while the cooked literal is of a separate type. The C++ literal &lt;code&gt;1234&lt;/code&gt;, as a raw literal, is this sequence of characters &lt;code&gt;'1'&lt;/code&gt;, &lt;code&gt;'2'&lt;/code&gt;, &lt;code&gt;'3'&lt;/code&gt;, &lt;code&gt;'4'&lt;/code&gt;. As a cooked literal, it is the integer 1234. The C++ literal &lt;code&gt;0xA&lt;/code&gt; in raw form is &lt;code&gt;'0'&lt;/code&gt;, &lt;code&gt;'x'&lt;/code&gt;, &lt;code&gt;'A'&lt;/code&gt;, while in cooked form it is the integer 10.<br /> <br /> Literals can be extended in both raw and cooked forms, with the exception of string literals, which can be processed only in cooked form. This exception is due to the fact that strings have prefixes that affect the specific meaning and type of the characters in question.<br /> <br /> All user-defined literals are suffixes; defining prefix literals is not possible.<br /> <br /> User-defined literals processing the raw form of the literal are defined as follows:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> OutputType operator &quot;&quot; _suffix(const char * literal_string);<br /> <br /> OutputType some_variable = 1234_suffix;<br /> &lt;/source&gt;<br /> <br /> The second statement executes the code defined by the user-defined literal function. This function is passed &lt;code&gt;&quot;1234&quot;&lt;/code&gt; as a C-style string, so it has a null terminator.<br /> <br /> An alternative mechanism for processing integer and floating point raw literals is through a [[variadic template]]:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template&lt;char...&gt; OutputType operator &quot;&quot; _suffix();<br /> <br /> OutputType some_variable = 1234_suffix;<br /> OutputType another_variable = 2.17_suffix;<br /> &lt;/source&gt;<br /> <br /> This instantiates the literal processing function as &lt;code&gt;operator &quot;&quot; _suffix&lt;'1', '2', '3', '4'&gt;()&lt;/code&gt;. In this form, there is no terminating null character to the string. The main purpose to doing this is to use C++11's &lt;code&gt;constexpr&lt;/code&gt; keyword and the compiler to allow the literal to be transformed entirely at compile time, assuming &lt;code&gt;OutputType&lt;/code&gt; is a constexpr-constructable and copyable type, and the literal processing function is a &lt;code&gt;constexpr&lt;/code&gt; function.<br /> <br /> For numeric literals, the type of the cooked literal is either &lt;code&gt;unsigned long long&lt;/code&gt; for integral literals or &lt;code&gt;long double&lt;/code&gt; for floating point literals. (Note: There is no need for signed integral types because a sign-prefixed literal is parsed as expression containing the sign as unary prefix operator and the unsigned number.) There is no alternative template form:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> OutputType operator &quot;&quot; _suffix(unsigned long long);<br /> OutputType operator &quot;&quot; _suffix(long double);<br /> <br /> OutputType some_variable = 1234_suffix; // Uses the 'unsigned long long' overload.<br /> OutputType another_variable = 3.1416_suffix; // Uses the 'long double' overload.<br /> &lt;/source&gt;<br /> <br /> For string literals, the following are used, in accordance with the previously mentioned new string prefixes:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> OutputType operator &quot;&quot; _suffix(const char * string_values, size_t num_chars);<br /> OutputType operator &quot;&quot; _suffix(const wchar_t * string_values, size_t num_chars);<br /> OutputType operator &quot;&quot; _suffix(const char16_t * string_values, size_t num_chars);<br /> OutputType operator &quot;&quot; _suffix(const char32_t * string_values, size_t num_chars);<br /> <br /> OutputType some_variable = &quot;1234&quot;_suffix; // Uses the 'const char *' overload.<br /> OutputType some_variable = u8&quot;1234&quot;_suffix; // Uses the 'const char *' overload.<br /> OutputType some_variable = L&quot;1234&quot;_suffix; // Uses the 'const wchar_t *' overload.<br /> OutputType some_variable = u&quot;1234&quot;_suffix; // Uses the 'const char16_t *' overload.<br /> OutputType some_variable = U&quot;1234&quot;_suffix; // Uses the 'const char32_t *' overload.<br /> &lt;/source&gt;<br /> <br /> There is no alternative template form. Character literals are defined similarly.<br /> <br /> ===Multithreading memory model===<br /> {{See also|Memory model (computing)}}<br /> The C++11 standardizes support for [[Thread (computer science)|multithreaded programming]].<br /> <br /> There are two parts involved: a memory model which allows multiple threads to co-exist in a program and library support for interaction between threads. (See this article's section on [[#Threading facilities|threading facilities]].)<br /> <br /> The memory model defines when multiple threads may access the same memory location, and specifies when updates by one thread become visible to other threads.<br /> <br /> ===Thread-local storage===<br /> In a multi-threaded environment, it is common for every thread to have some unique [[Variable (programming)|variables]]. This already happens for the local variables of a function, but it does not happen for global and static variables.<br /> <br /> A new [[Thread-Local Storage|''thread-local'']] storage duration (in addition to the existing ''static'', ''dynamic'' and ''automatic'') is indicated by the storage specifier &lt;code&gt;thread_local&lt;/code&gt;.<br /> <br /> Any object which could have static storage duration (i.e., lifetime spanning the entire execution of the program) may be given thread-local duration instead. The intent is that like any other static-duration variable, a thread-local object can be initialized using a constructor and destroyed using a destructor.<br /> <br /> ===Explicitly defaulted and deleted special member functions===<br /> In C++03, the compiler provides, for classes that do not provide them for themselves, a default constructor, a copy constructor, a copy assignment operator (&lt;code&gt;operator=&lt;/code&gt;), and a destructor. The programmer can override these defaults by defining custom versions. C++ also defines several global operators (such as &lt;code&gt;operator=&lt;/code&gt; and &lt;code&gt;operator new&lt;/code&gt;) that work on all classes, which the programmer can override.<br /> <br /> However, there is very little control over the creation of these defaults. Making a class inherently non-copyable, for example, requires declaring a private copy constructor and copy assignment operator and not defining them. Attempting to use these functions is a violation of the [[One Definition Rule]] (ODR). While a diagnostic message is not required,&lt;ref name=&quot;C++03 3.2/3&quot;&gt;[[ISO]]/[[International Electrotechnical Commission|IEC]] (2003). ''[[ISO/IEC 14882|ISO/IEC 14882:2003(E): Programming Languages - C++]] §3.2 One definition rule [basic.def.odr]'' para. 3&lt;/ref&gt; this typically results in a linker error.{{Citation needed|date=June 2009}}<br /> <br /> In the case of the default constructor, the compiler will not generate a default constructor if a class is defined with ''any'' constructors. This is useful in many cases, but it is also useful to be able to have both specialized constructors and the compiler-generated default.<br /> <br /> C++11 allows the explicit defaulting and deleting of these special member functions. For example, the following type explicitly declares that it is using the default constructor:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct SomeType {<br /> SomeType() = default; //The default constructor is explicitly stated.<br /> SomeType(OtherType value);<br /> };<br /> &lt;/source&gt;<br /> <br /> Alternatively, certain features can be explicitly disabled. For example, the following type is non-copyable:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct NonCopyable {<br /> NonCopyable &amp; operator=(const NonCopyable&amp;) = delete;<br /> NonCopyable(const NonCopyable&amp;) = delete;<br /> NonCopyable() = default;<br /> };<br /> &lt;/source&gt;<br /> <br /> The &lt;code&gt;= delete&lt;/code&gt; specifier can be used to prohibit calling any function, which can be used to disallow calling a member function with particular parameters. For example:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct NoInt {<br /> void f(double i);<br /> void f(int) = delete;<br /> };<br /> &lt;/source&gt;<br /> <br /> An attempt to call &lt;code&gt;f()&lt;/code&gt; with an &lt;code&gt;int&lt;/code&gt; will be rejected by the compiler, instead of performing a silent conversion to &lt;code&gt;double&lt;/code&gt;. This can be generalized to disallow calling the function with any type other than &lt;code&gt;double&lt;/code&gt; as follows:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct OnlyDouble {<br /> void f(double d);<br /> template&lt;class T&gt; void f(T) = delete;<br /> };<br /> &lt;/source&gt;<br /> <br /> ===Type &lt;code&gt;long long int&lt;/code&gt;===<br /> In C++03, the largest integer type is &lt;code&gt;long int&lt;/code&gt;. It is guaranteed to have at least as many usable bits as &lt;code&gt;int&lt;/code&gt;. This resulted in &lt;code&gt;long int&lt;/code&gt; having size of 64 bits on some popular implementations and 32 bits on others. C++11 adds a new integer type &lt;code&gt;long long int&lt;/code&gt; to address this issue. It is guaranteed to be at least as large as a &lt;code&gt;long int&lt;/code&gt;, and have no fewer than 64 bits. The type was originally introduced by [[C99]] to the standard C, and most C++ compilers support it as an extension already.&lt;ref&gt;http://gcc.gnu.org/onlinedocs/gcc/Long-Long.html&lt;/ref&gt;&lt;ref&gt;http://msdn.microsoft.com/en-us/library/s3f49ktz(VS.80).aspx&lt;/ref&gt;<br /> <br /> ===Static assertions===<br /> C++03 provides two methods to test [[Assertion (computing)|assertions]]: the macro &lt;code&gt;assert&lt;/code&gt; and the preprocessor directive &lt;code&gt;#error&lt;/code&gt;. However, neither is appropriate for use in templates: the macro tests the assertion at execution-time, while the preprocessor directive tests the assertion during preprocessing, which happens before instantiation of templates. Neither is appropriate for testing properties that are dependent on template parameters.<br /> <br /> The new utility introduces a new way to test assertions at compile-time, using the new keyword &lt;code&gt;static_assert&lt;/code&gt;.<br /> The declaration assumes the following form:<br /> static_assert (''constant-expression'', ''error-message'');<br /> <br /> Here are some examples of how &lt;code&gt;static_assert&lt;/code&gt; can be used:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> static_assert((GREEKPI &gt; 3.14) &amp;&amp; (GREEKPI &lt; 3.15), &quot;GREEKPI is inaccurate!&quot;);<br /> &lt;/source&gt;<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template&lt;class T&gt;<br /> struct Check {<br /> static_assert(sizeof(int) &lt;= sizeof(T), &quot;T is not big enough!&quot;);<br /> };<br /> &lt;/source&gt;<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template&lt;class Integral&gt;<br /> Integral foo(Integral x, Integral y) {<br /> static_assert(std::is_integral&lt;Integral&gt;::value, &quot;foo() parameter must be an integral type.&quot;);<br /> }<br /> &lt;/source&gt;<br /> <br /> When the constant expression is &lt;code&gt;false&lt;/code&gt; the compiler produces an error message. The first example represents an alternative to the preprocessor directive &lt;code&gt;#error&lt;/code&gt;, in contrast in the second example the assertion is checked at every instantiation of the template class &lt;code&gt;Check&lt;/code&gt;.<br /> <br /> Static assertions are useful outside of templates as well. For instance, a particular implementation of an algorithm might depend on the size of a &lt;code&gt;long long&lt;/code&gt; being larger than an &lt;code&gt;int&lt;/code&gt;, something the standard does not guarantee. Such an assumption is valid on most systems and compilers, but not all.<br /> <br /> ===Allow &lt;code&gt;sizeof&lt;/code&gt; to work on members of classes without an explicit object===<br /> In C++03, the &lt;code&gt;sizeof&lt;/code&gt; operator can be used on types and objects. But it cannot be used to do the following:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct SomeType { OtherType member; };<br /> <br /> sizeof(SomeType::member); //Does not work with C++03. Okay with C++11<br /> &lt;/source&gt;<br /> <br /> This should return the size of &lt;code&gt;OtherType&lt;/code&gt;. C++03 does not allow this, so it is a compile error. C++11 does allow it.<br /> <br /> ===Control and query object alignment===<br /> C++11 allows variable alignment to be queried and controlled with &lt;code&gt;alignof&lt;/code&gt; and &lt;code&gt;alignas&lt;/code&gt;.<br /> <br /> The &lt;code&gt;alignof&lt;/code&gt; operator takes a type and returns the power of 2 byte boundary on which the type instances must be allocated (as a &lt;code&gt;std::size_t&lt;/code&gt;). When given a reference type &lt;code&gt;alignof&lt;/code&gt; returns the referenced type's alignment; for arrays it returns the element type's alignment.<br /> <br /> The &lt;code&gt;alignas&lt;/code&gt; specifier controls the memory alignment for a variable. The specifier takes a constant or a type; when supplied a type &lt;code&gt;alignas(T)&lt;/code&gt; is short hand for &lt;code&gt;alignas(alignof(T))&lt;/code&gt;. For example, to specify that a char array should be properly aligned to hold a float:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> alignas(float) unsigned char c[sizeof(float)]<br /> &lt;/source&gt;<br /> <br /> ===Allow garbage collected implementations===<br /> In previous C++ standards, a conforming implementation could not collect objects even if no pointer to the object remained because pointers might still exist in some encoded form (e.g., as strings). C++11 changes language semantics to make garbage collection possible. {{citation needed|date=August 2012}} It is still implementation-defined whether unreachable dynamically allocated objects actually are automatically reclaimed.<br /> <br /> ==C++ standard library changes==<br /> A number of new features were introduced in the C++11 standard library. Many of these could have been implemented under the old standard, but some rely (to a greater or lesser extent) on new C++11 core features.<br /> <br /> A large part of the new [[Library (computer science)|libraries]] was defined in the document ''[[Technical Report 1|C++ Standards Committee's Library Technical Report]]'' (called TR1), which was published in 2005. Various full and partial implementations of TR1 are currently available using the namespace &lt;code&gt;std::tr1&lt;/code&gt;. For C++11 they were moved to namespace &lt;code&gt;std&lt;/code&gt;. However, as TR1 features were brought into the C++11 standard library, they were upgraded where appropriate with C++11 language features that were not available in the initial TR1 version. Also, they may have been enhanced with features that were possible under C++03, but were not part of the original TR1 specification.<br /> <br /> The committee intends to create a second technical report (called TR2) now that standardization of C++11 is complete. Library proposals which were not ready in time for C++11 will be put into TR2 or further technical reports.<br /> <br /> ===Upgrades to standard library components===<br /> C++11 offers a number of new language features that the currently existing standard library components can benefit from. For example, most standard library containers can benefit from Rvalue reference based move constructor support, both for quickly moving heavy containers around and for moving the contents of those containers to new memory locations. The standard library components were upgraded with new C++11 language features where appropriate. These include, but are not necessarily limited to:<br /> <br /> * Rvalue references and the associated move support<br /> * Support for the UTF-16 encoding unit, and UTF-32 encoding unit Unicode character types<br /> * [[Variadic templates]] (coupled with Rvalue references to allow for perfect forwarding)<br /> * Compile-time constant expressions<br /> * &lt;code&gt;[[decltype]]&lt;/code&gt;<br /> * &lt;code&gt;explicit&lt;/code&gt; conversion operators<br /> * &lt;code&gt;default&lt;/code&gt;/&lt;code&gt;delete&lt;/code&gt;d functions<br /> <br /> Additionally, much time has passed since the previous C++ standard. A great deal of code using the standard library has been written; this has revealed portions of the standard libraries that could use some improvement. Among the many areas of improvement considered were standard library [[Allocator (C++)|allocator]]s. A new scope-based model of allocators was included in C++11 to supplement the previous model.<br /> <br /> ===Threading facilities===<br /> While the C++11 language provides a memory model that supports threading, the primary support for actually using threading comes with the C++11 standard library.<br /> <br /> A thread class (&lt;code&gt;std::thread&lt;/code&gt;) is provided which takes a [[function object]] — and an optional series of arguments to pass to it — to run in the new thread. It is possible to cause a thread to halt until another executing thread completes, providing thread joining support through the &lt;code&gt;std::thread::join()&lt;/code&gt; member function. Access is provided, where feasible, to the underlying native thread object(s) for [[Platform (computing)|platform]] specific operations by the &lt;code&gt;std::thread::native_handle()&lt;/code&gt; member function.<br /> <br /> For synchronization between threads, appropriate [[Mutual exclusion|mutexes]] (&lt;code&gt;std::mutex&lt;/code&gt;, &lt;code&gt;std::recursive_mutex&lt;/code&gt;, etc.) and [[Monitor (synchronization)|condition variables]] (&lt;code&gt;std::condition_variable&lt;/code&gt; and &lt;code&gt;std::condition_variable_any&lt;/code&gt;) are added to the library. These are accessible through [[Resource Acquisition Is Initialization|RAII]] locks (&lt;code&gt;std::lock_guard&lt;/code&gt; and &lt;code&gt;std::unique_lock&lt;/code&gt;) and locking algorithms for easy use.<br /> <br /> For high-performance, low-level work, it is sometimes necessary to communicate between threads without the overhead of mutexes. This is achieved using [[atomic operation]]s on memory locations. These can optionally specify the minimum memory visibility constraints required for an operation. Explicit [[memory barrier]]s may also be used for this purpose.<br /> <br /> The C++11 thread library also includes [[futures and promises]] for passing asynchronous results between threads, and &lt;code&gt;std::packaged_task&lt;/code&gt; for wrapping up a function call that can generate such an asynchronous result. The futures proposal was criticized because it lacks a way to combine futures and check for the completion of one promise inside a set of promises.&lt;ref&gt;{{Cite web<br /> | last = Milewski<br /> | first = Bartosz<br /> | title = Broken promises–C++0x futures<br /> | date = 3 March 2009<br /> | url = http://bartoszmilewski.wordpress.com/2009/03/03/broken-promises-c0x-futures/<br /> | accessdate =24 January 2010}}&lt;/ref&gt;<br /> <br /> Further high-level threading facilities such as [[thread pool]]s have been remanded to a future C++ [[Technical Report 1|technical report]]. They are not part of C++11, but their eventual implementation is expected to be built entirely on top of the thread library features.<br /> <br /> The new &lt;code&gt;std::async&lt;/code&gt; facility provides a convenient method of running tasks and tying them to a &lt;code&gt;std::future&lt;/code&gt;. The user can choose whether the task is to be run asynchronously on a separate thread or synchronously on a thread that waits for the value. By default, the implementation can choose, which provides an easy way to take advantage of hardware concurrency without oversubscription, and provides some of the advantages of a thread pool for simple usages.<br /> <br /> ===Tuple types===<br /> [[Tuples]] are collections composed of heterogeneous objects of pre-arranged dimensions. A tuple can be considered a generalization of a struct's member variables.<br /> <br /> The C++11 version of the TR1 tuple type benefited from C++11 features like [[#Variadic templates|variadic templates]]. The TR1 version required an implementation-defined maximum number of contained types, and required substantial macro trickery to implement reasonably. By contrast, the implementation of the C++11 version requires no explicit implementation-defined maximum number of types. Though compilers will have an internal maximum recursion depth for template instantiation (which is normal), the C++11 version of tuples will not expose this value to the user.<br /> <br /> Using [[variadic templates]], the declaration of the tuple class looks as follows:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template &lt;class ...Types&gt; class tuple;<br /> &lt;/source&gt;<br /> <br /> An example of definition and use of the tuple type:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> typedef std::tuple &lt;int, double, long &amp;, const char *&gt; test_tuple;<br /> long lengthy = 12;<br /> test_tuple proof (18, 6.5, lengthy, &quot;Ciao!&quot;);<br /> <br /> lengthy = std::get&lt;0&gt;(proof); // Assign to 'lengthy' the value 18.<br /> std::get&lt;3&gt;(proof) = &quot; Beautiful!&quot;; // Modify the tuple’s fourth element.<br /> &lt;/source&gt;<br /> <br /> It’s possible to create the tuple &lt;code&gt;proof&lt;/code&gt; without defining its contents, but only if the tuple elements' types possess default constructors. Moreover, it’s possible to assign a tuple to another tuple: if the two tuples’ types are the same, it is necessary that each element type possesses a copy constructor; otherwise, it is necessary that each element type of the right-side tuple is convertible to that of the corresponding element type of the left-side tuple or that the corresponding element type of the left-side tuple has a suitable constructor.<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> typedef std::tuple &lt;int , double, string &gt; tuple_1 t1;<br /> typedef std::tuple &lt;char, short , const char * &gt; tuple_2 t2 ('X', 2, &quot;Hola!&quot;);<br /> t1 = t2 ; // Ok, first two elements can be converted,<br /> // the third one can be constructed from a 'const char *'.<br /> &lt;/source&gt;<br /> <br /> Relational operators are available (among tuples with the same number of elements), and two expressions are available to check a tuple’s characteristics (only during compilation):<br /> *&lt;code&gt;std::tuple_size&lt;nowiki&gt;&lt;T&gt;&lt;/nowiki&gt;::value&lt;/code&gt; returns the number of elements in the tuple &lt;code&gt;T&lt;/code&gt;,<br /> *&lt;code&gt;std::tuple_element&lt;nowiki&gt;&lt;I, T&gt;&lt;/nowiki&gt;::type&lt;/code&gt; returns the type of the object number &lt;code&gt;I&lt;/code&gt; of the tuple &lt;code&gt;T&lt;/code&gt;.<br /> <br /> ===Hash tables===<br /> Including [[hash tables]] (unordered associative containers) in the C++ standard library is one of the most recurring requests. It was not adopted in C++03 due to time constraints only. Although hash tables are less efficient than a balanced tree in the worst case (in the presence of many collisions), they perform better in many real applications.<br /> <br /> Collisions are managed only through ''[[Hash tables#Separate chaining|linear chaining]]'' because the committee didn't consider opportune to standardize solutions of ''[[open addressing]]'' that introduce quite a lot of intrinsic problems (above all when erasure of elements is admitted). To avoid name clashes with non-standard libraries that developed their own hash table implementations, the prefix “unordered” was used instead of “hash”.<br /> <br /> The new library has four types of hash tables, differentiated by whether or not they accept elements with the same key (unique keys or equivalent keys), and whether they map each key to an associated value. They correspond to the four existing binary-search-tree-based associative containers, with an &lt;tt&gt;unordered_&lt;/tt&gt; prefix.<br /> <br /> {| class=&quot;wikitable&quot; style=&quot;text-align: center&quot;<br /> ! Type of hash table !! Associated values !! Equivalent keys<br /> |-<br /> | style=&quot;text-align: left&quot; | &lt;code&gt;[[Unordered associative containers (C++)|std::unordered_set]]&lt;/code&gt; || {{no}} || {{no}}<br /> |-<br /> | style=&quot;text-align: left&quot; | &lt;code&gt;[[Unordered associative containers (C++)|std::unordered_multiset]]&lt;/code&gt; || {{no}} || {{yes}}<br /> |-<br /> | style=&quot;text-align: left&quot; | &lt;code&gt;[[Unordered associative containers (C++)|std::unordered_map]]&lt;/code&gt; || {{yes}} || {{no}}<br /> |-<br /> | style=&quot;text-align: left&quot; | &lt;code&gt;[[Unordered associative containers (C++)|std::unordered_multimap]]&lt;/code&gt; || {{yes}} || {{yes}}<br /> |}<br /> <br /> New classes fulfill all the requirements of a [[Standard Template Library#Containers|container class]], and have all the methods necessary to access elements: &lt;code&gt;insert&lt;/code&gt;, &lt;code&gt;erase&lt;/code&gt;, &lt;code&gt;begin&lt;/code&gt;, &lt;code&gt;end&lt;/code&gt;.<br /> <br /> This new feature didn't need any C++ language core extensions (though implementations will take advantage of various C++11 language features), only a small extension of the header &lt;code&gt;&lt;nowiki&gt;&lt;functional&gt;&lt;/nowiki&gt;&lt;/code&gt; and the introduction of headers &lt;code&gt;&lt;nowiki&gt;&lt;unordered_set&gt;&lt;/nowiki&gt;&lt;/code&gt; and &lt;code&gt;&lt;nowiki&gt;&lt;unordered_map&gt;&lt;/nowiki&gt;&lt;/code&gt;. No other changes to any existing standard classes were needed, and it doesn’t depend on any other extensions of the standard library.<br /> <br /> ===Regular expressions===<br /> <br /> The new library, defined in the new header &lt;code&gt;&lt;nowiki&gt;&lt;regex&gt;&lt;/nowiki&gt;&lt;/code&gt;, is made of a couple of new classes:<br /> *[[regular expressions]] are represented by instance of the template class &lt;code&gt;std::regex&lt;/code&gt;;<br /> *occurrences are represented by instance of the template class &lt;code&gt;std::match_results&lt;/code&gt;.<br /> The function &lt;code&gt;std::regex_search&lt;/code&gt; is used for searching, while for ‘search and replace’ the function &lt;code&gt;std::regex_replace&lt;/code&gt; is used which returns a new string.<br /> The algorithms &lt;code&gt;std::regex_search&lt;/code&gt; and &lt;code&gt;std::regex_replace&lt;/code&gt; take a regular expression and a string and write the occurrences found in the struct &lt;code&gt;std::match_results&lt;/code&gt;.<br /> <br /> Here is an example of the use of &lt;code&gt;std::match_results&lt;/code&gt;:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> const char *reg_esp = &quot;[ ,.\\t\\n;:]&quot;; // List of separator characters.<br /> <br /> // this can be done using raw string literals:<br /> // const char *reg_esp = R&quot;([ ,.\t\n;:])&quot;;<br /> <br /> std::regex rgx(reg_esp); // 'regex' is an instance of the template class<br /> // 'basic_regex' with argument of type 'char'.<br /> std::cmatch match; // 'cmatch' is an instance of the template class<br /> // 'match_results' with argument of type 'const char *'.<br /> const char *target = &quot;Unseen University - Ankh-Morpork&quot;;<br /> <br /> // Identifies all words of 'target' separated by characters of 'reg_esp'.<br /> if( std::regex_search( target, match, rgx ) ) {<br /> // If words separated by specified characters are present.<br /> <br /> const size_t n = match.size();<br /> for( size_t a = 0; a &lt; n; a++ ) {<br /> std::string str( match[a].first, match[a].second );<br /> std::cout &lt;&lt; str &lt;&lt; &quot;\n&quot;;<br /> }<br /> }<br /> &lt;/source&gt;<br /> <br /> Note the use of double [[backslash]]es, because C++ uses backslash as an escape character. The C++11 [[#New_string_literals|raw string]] feature could be used to avoid the problem.<br /> <br /> The library &lt;code&gt;&lt;nowiki&gt;&lt;regex&gt;&lt;/nowiki&gt;&lt;/code&gt; requires neither alteration of any existing header (though it will use them where appropriate) nor an extension of the core language.<br /> <br /> ===General-purpose smart pointers===<br /> {{main|Smart_pointer|l1=C++ Smart Pointers}}<br /> C++11 provides {{code|std::unique_ptr}}, as well as improvements to {{code|std::shared_ptr}} and {{code|std::weak_ptr}} from TR1. {{code|std::auto_ptr}} is deprecated.<br /> <br /> ===Extensible random number facility===<br /> The C standard library provides the ability to generate [[pseudorandom numbers]] through the function &lt;code&gt;rand&lt;/code&gt;. However, the algorithm is delegated entirely to the library vendor. C++ inherited this functionality with no changes, but C++11 will provide a new method for generating pseudorandom numbers.<br /> <br /> C++11's random number functionality is split into two parts: a generator engine that contains the random number generator's state and produces the pseudorandom numbers; and a distribution, which determines the range and [[Distribution (mathematics)|mathematical distribution]] of the outcome. These two are combined to form a random number generator object.<br /> <br /> Unlike the C standard &lt;code&gt;rand&lt;/code&gt;, the C++11 mechanism will come with three base generator engine algorithms:<br /> * &lt;code&gt;[[Linear congruential generator|linear_congruential_engine]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Subtract with carry|subtract_with_carry_engine]]&lt;/code&gt;, and<br /> * &lt;code&gt;[[Mersenne twister|mersenne_twister_engine]]&lt;/code&gt;.<br /> <br /> C++11 will also provide a number of standard distributions:<br /> * &lt;code&gt;[[Uniform distribution (discrete)|uniform_int_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Uniform distribution (continuous)|uniform_real_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Bernoulli distribution|bernoulli_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Binomial distribution|binomial_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Geometric distribution|geometric_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Negative binomial distribution|negative_binomial_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Poisson distribution|poisson_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Exponential distribution|exponential_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Gamma distribution|gamma_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Weibull distribution|weibull_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Generalized extreme value distribution|extreme_value_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Normal distribution|normal_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Lognormal distribution|lognormal_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Chi squared distribution|chi_squared_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Cauchy distribution|cauchy_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[F-distribution|fisher_f_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Student's t-distribution|student_t_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Discrete_distribution#Discrete_probability_distribution|discrete_distribution]]&lt;/code&gt;,<br /> * &lt;code&gt;[[Step function|piecewise_constant_distribution]]&lt;/code&gt; and<br /> * &lt;code&gt;[[Piecewise linear function|piecewise_linear_distribution]]&lt;/code&gt;.<br /> <br /> The generator and distributions are combined as in the following example:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> #include &lt;random&gt;<br /> #include &lt;functional&gt;<br /> <br /> std::uniform_int_distribution&lt;int&gt; distribution(0, 99);<br /> std::mt19937 engine; // Mersenne twister MT19937<br /> auto generator = std::bind(distribution, engine);<br /> int random = generator(); // Generate a uniform integral variate between 0 and 99.<br /> int random2 = distribution(engine); // Generate another sample directly using the distribution and the engine objects.<br /> &lt;/source&gt;<br /> <br /> ===Wrapper reference===<br /> A [[Adapter pattern|wrapper]] reference is obtained from an instance of the template class &lt;code&gt;reference_wrapper&lt;/code&gt;. Wrapper references are similar to normal references (‘&lt;code&gt;&amp;amp;&lt;/code&gt;’) of the C++ language. To obtain a wrapper reference from any object the function template &lt;code&gt;ref&lt;/code&gt; is used (for a constant reference &lt;code&gt;cref&lt;/code&gt; is used).<br /> <br /> Wrapper references are useful above all for function templates, where references to parameters rather than copies are needed:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> // This function will obtain a reference to the parameter 'r' and increment it.<br /> void func (int &amp;r) { r++; }<br /> <br /> // Template function.<br /> template&lt;class F, class P&gt; void g (F f, P t) { f(t); }<br /> <br /> int main()<br /> {<br /> int i = 0 ;<br /> g (func, i) ; // 'g&lt;void (int &amp;r), int&gt;' is instantiated<br /> // then 'i' will not be modified.<br /> std::cout &lt;&lt; i &lt;&lt; std::endl; // Output -&gt; 0<br /> <br /> g (func, std::ref(i)); // 'g&lt;void(int &amp;r),reference_wrapper&lt;int&gt;&gt;' is instantiated<br /> // then 'i' will be modified.<br /> std::cout &lt;&lt; i &lt;&lt; std::endl; // Output -&gt; 1<br /> }<br /> &lt;/source&gt;<br /> <br /> This new utility was added to the existing &lt;code&gt;&lt;nowiki&gt;&lt;utility&gt;&lt;/nowiki&gt;&lt;/code&gt; header and didn't need further extensions of the C++ language.<br /> <br /> ===Polymorphic wrappers for function objects===<br /> [[Type polymorphism|Polymorphic]] [[Adapter pattern|wrappers]] for [[function objects]] are similar to [[function pointers]] in semantics and syntax, but are less tightly bound and can indiscriminately refer to anything which can be called (function pointers, member function pointers, or functors) whose arguments are compatible with those of the wrapper.<br /> <br /> Through the example it is possible to understand its characteristics:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> std::function&lt;int (int, int)&gt; func; // Wrapper creation using<br /> // template class 'function'.<br /> std::plus&lt;int&gt; add; // 'plus' is declared as 'template&lt;class T&gt; T plus( T, T ) ;'<br /> // then 'add' is type 'int add( int x, int y )'.<br /> func = add; // OK - Parameters and return types are the same.<br /> <br /> int a = func (1, 2); // NOTE: if the wrapper 'func' does not refer to any function,<br /> // the exception 'std::bad_function_call' is thrown.<br /> <br /> std::function&lt;bool (short, short)&gt; func2 ;<br /> if(!func2) { // True because 'func2' has not yet been assigned a function.<br /> <br /> bool adjacent(long x, long y);<br /> func2 = &amp;adjacent ; // OK - Parameters and return types are convertible.<br /> <br /> struct Test {<br /> bool operator()(short x, short y);<br /> };<br /> Test car;<br /> func = std::ref(car); // 'std::ref' is a template function that returns the wrapper<br /> // of member function 'operator()' of struct 'car'.<br /> }<br /> func = func2; // OK - Parameters and return types are convertible.<br /> &lt;/source&gt;<br /> <br /> The template class &lt;code&gt;function&lt;/code&gt; was defined inside the header &lt;code&gt;&lt;nowiki&gt;&lt;functional&gt;&lt;/nowiki&gt;&lt;/code&gt;, and didn't require any changes to the C++ language.<br /> <br /> ===Type traits for metaprogramming===<br /> [[Metaprogramming]] consists of creating a program that creates or modifies another program (or itself). This can happen during compilation or during execution. The [[C++ Standards Committee]] has decided to introduce a library that allows metaprogramming during compilation through templates.<br /> <br /> Here is an example of a meta-program, using the current C++03 standard: a [[recursion]] of template instances for calculating integer exponents:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template&lt;int B, int N&gt;<br /> struct Pow {<br /> // recursive call and recombination.<br /> enum{ value = B*Pow&lt;B, N-1&gt;::value };<br /> };<br /> <br /> template&lt; int B &gt;<br /> struct Pow&lt;B, 0&gt; {<br /> // ''N == 0'' condition of termination.<br /> enum{ value = 1 };<br /> };<br /> int quartic_of_three = Pow&lt;3, 4&gt;::value;<br /> &lt;/source&gt;<br /> <br /> Many algorithms can operate on different types of data; C++'s [[Template (programming)|template]]s support [[generic programming]] and make code more compact and useful. Nevertheless it is common for algorithms to need information on the data types being used. This information can be extracted during instantiation of a template class using '''type traits'''.<br /> <br /> '''Type traits''' can identify the category of an object and all the characteristics of a class (or of a struct). They are defined in the new header &lt;code&gt;&lt;nowiki&gt;&lt;type_traits&gt;&lt;/nowiki&gt;&lt;/code&gt;.<br /> <br /> In the next example there is the template function ‘elaborate’ that, depending on the given data types, will instantiate one of the two proposed algorithms (&lt;code&gt;algorithm.do_it&lt;/code&gt;).<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> // First way of operating.<br /> template&lt; bool B &gt; struct Algorithm {<br /> template&lt;class T1, class T2&gt; static int do_it (T1 &amp;, T2 &amp;) { /*...*/ }<br /> };<br /> <br /> // Second way of operating.<br /> template&lt;&gt; struct Algorithm&lt;true&gt; {<br /> template&lt;class T1, class T2&gt; static int do_it (T1, T2) { /*...*/ }<br /> };<br /> <br /> // Instantiating 'elaborate' will automatically instantiate the correct way to operate.<br /> template&lt;class T1, class T2&gt;<br /> int elaborate (T1 A, T2 B)<br /> {<br /> // Use the second way only if 'T1' is an integer and if 'T2' is<br /> // in floating point, otherwise use the first way.<br /> return Algorithm&lt;std::is_integral&lt;T1&gt;::value &amp;&amp; std::is_floating_point&lt;T2&gt;::value&gt;::do_it( A, B ) ;<br /> }<br /> &lt;/source&gt;<br /> <br /> Through '''type traits''', defined in header &lt;code&gt;&lt;nowiki&gt;&lt;type_transform&gt;&lt;/nowiki&gt;&lt;/code&gt;, it’s also possible to create type transformation operations (&lt;code&gt;static_cast&lt;/code&gt; and &lt;code&gt;const_cast&lt;/code&gt; are insufficient inside a template).<br /> <br /> This type of programming produces elegant and concise code; however the weak point of these techniques is the debugging: uncomfortable during compilation and very difficult during program execution.<br /> <br /> ===Uniform method for computing the return type of function objects===<br /> Determining the return type of a template function object at compile-time is not intuitive, particularly if the return value depends on the parameters of the function. As an example:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct Clear {<br /> int operator()(int) const; // The parameter type is<br /> double operator()(double) const; // equal to the return type.<br /> };<br /> <br /> template &lt;class Obj&gt;<br /> class Calculus {<br /> public:<br /> template&lt;class Arg&gt; Arg operator()(Arg&amp; a) const<br /> {<br /> return member(a);<br /> }<br /> private:<br /> Obj member;<br /> };<br /> &lt;/source&gt;<br /> <br /> Instantiating the class template &lt;code&gt;Calculus&lt;nowiki&gt;&lt;Clear&gt;&lt;/nowiki&gt;&lt;/code&gt;, the function object of &lt;code&gt;calculus&lt;/code&gt; will have always the same return type as the function object of &lt;code&gt;Clear&lt;/code&gt;. However, given class &lt;code&gt;Confused&lt;/code&gt; below:<br /> <br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> struct Confused {<br /> double operator()(int) const; // The parameter type is not<br /> int operator()(double) const; // equal to the return type.<br /> };<br /> &lt;/source&gt;<br /> Attempting to instantiate &lt;code&gt;Calculus&lt;nowiki&gt;&lt;Confused&gt;&lt;/nowiki&gt;&lt;/code&gt; will cause the return type of &lt;code&gt;Calculus&lt;/code&gt; to not be the same as that of class &lt;code&gt;Confused&lt;/code&gt;. The compiler may generate warnings about the conversion from &lt;code&gt;int&lt;/code&gt; to &lt;code&gt;double&lt;/code&gt; and vice-versa.<br /> <br /> TR1 introduces, and C++11 adopts, the template class &lt;code&gt;std::result_of&lt;/code&gt; that allows one to determine and use the return type of a function object for every declaration. The object &lt;code&gt;CalculusVer2&lt;/code&gt; uses the &lt;code&gt;std::result_of&lt;/code&gt; object to derive the return type of the function object:<br /> &lt;source lang=&quot;cpp&quot;&gt;<br /> template&lt; class Obj &gt;<br /> class CalculusVer2 {<br /> public:<br /> template&lt;class Arg&gt;<br /> typename std::result_of&lt;Obj(Arg)&gt;::type operator()(Arg&amp; a) const<br /> {<br /> return member(a);<br /> }<br /> private:<br /> Obj member;<br /> };<br /> &lt;/source&gt;<br /> In this way in instances of function object of &lt;code&gt;CalculusVer2&lt;nowiki&gt;&lt;Confused&gt;&lt;/nowiki&gt;&lt;/code&gt; there are no conversions, warnings, or errors.<br /> <br /> The only change from the TR1 version of &lt;code&gt;std::result_of&lt;/code&gt; is that the TR1 version allowed an implementation to fail to be able to determine the result type of a function call. Due to changes to C++ for supporting &lt;code&gt;[[#Type inference|decltype]]&lt;/code&gt;, the C++11 version of &lt;code&gt;std::result_of&lt;/code&gt; no longer needs these special cases; implementations are required to compute a type in all cases.<br /> <br /> ==Features originally planned but removed or not included==<br /> Heading for a separate TR:<br /> * [http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3347.pdf Modules]<br /> * Decimal Types<br /> * Math Special Functions<br /> Postponed:<br /> * [[Concepts (C++)|Concepts]]<br /> * More complete or required garbage collection support<br /> * Reflection<br /> * Macro Scopes<br /> <br /> ==Features removed or deprecated==<br /> * The term [[sequence point]], which is being replaced by specifying that either one operation is sequenced before another, or that two operations are unsequenced.&lt;ref&gt;{{cite web|url=http://blogs.msdn.com/b/vcblog/archive/2007/06/04/update-on-the-c-0x-language-standard.aspx|title=Update on the C++-0x Language Standard|last=Caves|first=Jonathan|date=4 June 2007|accessdate=25 May 2010}}&lt;/ref&gt;<br /> * &lt;code&gt;[[export (C++)|export]]&lt;/code&gt;&lt;ref name=&quot;sutter0310&quot;&gt;{{cite web|url=http://herbsutter.com/2010/03/13/trip-report-march-2010-iso-c-standards-meeting/|title=Trip Report: March 2010 ISO C++ Standards Meeting|last=Sutter|first=Herb|authorlink=Herb Sutter|date=3 March 2010|accessdate=24 March 2010}}&lt;/ref&gt;: Its current use is ''removed'', but the keyword itself is still reserved, for potential future use.<br /> * dynamic [[exception specification]]s&lt;ref name=&quot;sutter0310&quot;/&gt; are deprecated. Compile time specification of non-exception throwing functions is available with the &lt;code&gt;noexcept&lt;/code&gt; keyword (useful for optimization)<br /> * &lt;code&gt;[[auto ptr|std::auto_ptr]]&lt;/code&gt; is deprecated. Superseded by &lt;code&gt;std::unique_ptr&lt;/code&gt;<br /> * Function object base classes (&lt;code&gt;std::unary_function&lt;/code&gt;, &lt;code&gt;std::binary_function&lt;/code&gt;), adapters to pointers to functions and adapters to pointers to members, binder classes; these are all deprecated.<br /> <br /> ==See also==<br /> <br /> *[[C++ Technical Report 1]]<br /> *[[C99]]<br /> *[[C11_(C_standard_revision)|C11]]<br /> <br /> ==References==<br /> <br /> {{reflist}}<br /> <br /> == External links ==<br /> * [http://www.open-std.org/jtc1/sc22/wg21/ The C++ Standards Committee]<br /> * [http://www.informit.com/guides/content.aspx?g=cplusplus&amp;seqNum=216 C++0X: The New Face of Standard C++]<br /> * [http://herbsutter.wordpress.com/ Herb Sutter's blog coverage of C++11]<br /> * [http://www.justsoftwaresolutions.co.uk/cplusplus/ Anthony Williams' blog coverage of C++11]<br /> * [http://www.csclub.uwaterloo.ca/media/C++0x%20-%20An%20Overview.html A talk on C++0x given by Bjarne Stroustrup at the University of Waterloo]<br /> * [http://www.devx.com/SpecialReports/Article/38813/0/page/1 The State of the Language: An Interview with Bjarne Stroustrup (15 August 2008)]<br /> * [http://wiki.apache.org/stdcxx/C++0xCompilerSupport Wiki page to help keep track of C++ 0x core language features and their availability in compilers]<br /> * [http://en.cppreference.com Online C++11 standard library reference]<br /> <br /> {{CProLang}}<br /> <br /> [[Category:C++]]<br /> [[Category:Computer standards]]<br /> [[Category:Articles with example C++ code]]<br /> <br /> [[es:C++11]]<br /> [[fr:C++11]]<br /> [[ko:C++11]]<br /> [[it:C++11]]<br /> [[ja:C++11]]<br /> [[pl:C++11]]<br /> [[pt:C++11]]<br /> [[ru:C++11]]<br /> [[sr:Нацрт C++0x од марта 2010.]]<br /> [[fi:C++11]]<br /> [[sv:C++#Historia]]<br /> [[th:ภาษาซีพลัสพลัสโอเอกซ์]]<br /> [[uk:C++11]]<br /> [[vi:C++11]]<br /> [[zh:C++11]]</div> Code-structure