Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the new features of Central11?

Shulou Source: shulou.com Published: 2022-06-02 09:26:29 09月25日 Update

The main content of this article is to explain "what are the new features of Category 11". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the new features of Category 11?"

What is Clear11?

Category 11, once known as C++ Technical Report 0x, is an extension and revision of the current C++ language. It not only contains new functions of the core language, but also extends C++ 's standard program library (TR1) and incorporates most C++ API 1 (TR1) libraries (except for special functions in mathematics).

Clocking 11 includes a number of new features, including lambda expressions, type derivation keywords auto, decltype, and numerous improvements to templates.

New keyword

Auto

The function of auto*** is introduced in Category 11 to automatically derive the type.

Automatic type derivation of auto, which is used to infer the data type of a variable from an initialization expression. Through the automatic type derivation of auto, our programming work can be greatly simplified.

Auto actually deduces the types of variables at compile time, so it will not adversely affect the running efficiency of the program.

In addition, it seems that auto does not affect compilation speed, because compilation time is supposed to deduce on the right and then determine whether it matches the left.

Auto a; / / error. Auto performs type derivation through initialization expressions. If there is no initialization expression, you cannot determine the type of a: auto I = 1; auto d = 1.0; auto str = "Hello World"; auto ch = 'A'; auto func = less (); vector iv; auto ite = iv.begin (); auto p = new foo () / / A pair of custom types for type derivation

Auto not only has the above applications, but also shows its skill in templates. For example, in the following example of a processed product, you must declare the template parameter Product if you do not use auto:

Template void processProduct (const Creator& creator) {Product* val = creator.makeObject (); / / do somthing with val}.

If you use auto, you can write:

Template void processProduct (const Creator& creator) {auto val = creator.makeObject (); / / do somthing with val}

Get rid of the troublesome template parameters, and the whole code becomes more correct.

Decltype

Decltype is actually a bit like the inverse function of auto. Auto allows you to declare a variable, while decltype can get a type from a variable or expression. Examples are as follows:

Int x = 3; decltype (x) y = x

Some people may ask, what is the usefulness of decltype? let's continue with the above example, what if we want to use the product as a return value in the example of a processed product above? We can write like this:

Template auto processProduct (const Creator& creator)-> decltype (creator.makeObject ()) {auto val = creator.makeObject (); / / do somthing with val}

Nullptr

Nullptr is a new type introduced to solve the ambiguity problem of NULL in C++, because NULL actually stands for 0.

Void F (int a) {cout

Tags: Types parameters expressions functions functions variables templates compilations properties code examples actual data different products multiple actually containers methods programs Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Xiaomi macOS OPPO Reno Shulou Tech Info