New Features of C ++ 11

Source: Internet
Author: User

 

1. Right Value reference and mobile construction semantics:

For the problem that C ++ can only use a value or a common reference form as a function argument for temporary variables, the reference of a temporary variable object can be used on the right, with this feature, we can implement a new copy semantics of mobile constructor to avoid the overhead of copying a large number of objects under the object copy assignment. Http://bbs.chinaunix.net/thread-1251475-1-1.html2.use extern to modify a template class and inform the compiler that the template does not need to be instantiated in the current compilation unit. The compiler has already implemented the template before the 11 standard. 3. Lambda representation: defines anonymous function objects, which greatly reduces the overhead of defining predicates (such as in STL) and is easier to be optimized by the compiler. 4. type inference: in 11, the semantics of the auto keyword has changed. the right value of the expression is used to automatically deduce the type of the Left value and define the template, alternatively, you can easily obtain the types of anonymous objects such as lambda expressions. 5. syntax for post-return function declaration: similar to the return value definition method in lambda expressions, templates and common functions can also use similar syntax to specify the return value. For example:

Template <class LHS, class RHS>
AutoAdding_func (const LHS & LHS, const RHS & RHs)-> Decltype (LHS + RHs){Return LHS + RHS ;}

Obviously, this syntax is mainly used to help with the type inference when the template is defined-in the above example, because the "LHS" and "RHS" of the return type are in "adding_func (...) "is not defined before, so the definition of the return value type must be delayed after the parameter list.

It should be noted that when this post syntax is used, the position of the function that originally specified the return value type must be recorded as "Auto ".

6. How does a function template and a generic function template differentiate function objects from function pointers.

7. shared_ptr <t> the smart pointer references the counting shared object and can pass the revocation policy to the constructor to facilitate sharing of resources such as file pointers. (Weak_ptr, Todo)

-----

Compiler support reference: http://www.csdn.net/article/2012-08-13/2808540

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.