Learning from scratch with SLAM (4) C ++ new features do not want to learn?

Article Directory


  This article numbers issued to the public: Computer Vision life.
  Original link: to learn from scratch with SLAM | C ++ new features do not want to learn?

 

To learn from scratch together SLAM | C ++ new features do not want to learn?

  Learning SLAM, C ++ programming skills are necessary. However, we learn in school books generally older, mainly those same old C ++ 98.

  The so-called new features of C ++ This article refers to 14, C ++ 17 added new keywords and syntax features new C ++ 11 and beyond C ++. Where C ++ 11 is the most important one since 98 changes in C ++, and the subsequent C ++ 14, C ++ 17 is the perfect complement and the foundation.

  So, the question is, if I do not want to learn the new features, or it can be programmed as before?

  The answer is: Yes, but it's like people are already using iron tool to cut a melon, you're still using Stone Age stone tools, you say, efficiency can be the same?

  Consider the following in your heart have the answer.

Why learn the new features?

  1, can greatly improve programming efficiency, cut melon more 6

  C ++ adds many new features very efficient keywords and syntax, such as std :: swap, swap the previous 11 C ++ memory copy operation is performed three times, this unnecessary memory operations will affect the efficiency. And C ++ swap after 11 introduces the concept of data and the reference values ​​of the right movement, instead of using memory pipette unnecessary memory copying, greatly improving the efficiency.

  2, worry and effort, reduce hair loss

  For chestnuts. C ++ before 11 if we are to define and initialize a new variable, must know and define its type, which in many cases are very complicated, such as using an iterator, and C ++ introduced after 11 automatic type inference, a auto solve everything, you do not care about the type, the compiler will automatically help you to deduce the type.

  3, able to read other people's code, not to abandon the new era

  Because of the above advantages, many open-source code is in C ++ new features, work and study we all use the new features, if you do not understand these new features, expected to be difficult to understand someone else's code, tanks rumbling times will put you abandoned.

  Here are a few typical new features frequently used for your entry.

Commonly used C ++ new features

1 more convenient list initialization

  C ++ 11 just before the array can be used to initialize the list. The C ++ 11 after most types of lists can be initialized, very convenient. As follows.

Here Insert Picture Description

2 worry and effort automatic type inference

  C ++ 11 introduces auto, can be used for automatic type inference, do not care about data types, the compiler will help you derive good, and in this way does not affect the compilation speed.

  For example, after the iterator uses automatic type inference, I felt much cleaner, as shown below:

Here Insert Picture Description

  However, there are caveats when auto use:

  Such as auto variables can not represent an actual type declaration, auto declaration must be initialized immediately

  See below:

Here Insert Picture Description

  More details can be online, if too lazy to look for can refer to:

https://blog.csdn.net/m_buddy/article/details/72828576

3 simple and comfortable loop

  The for loop is to use very high frequency cycle way, we did not need to use every increment or decrement way as before in the index where the new features, combined with the previously described auto, we can greatly simplify the cycle way ,As shown below:

Here Insert Picture Description

  And this cycle support most data types, such as arrays, container, string, like the iterator.

Here Insert Picture Description

4 compact lambda expressions

  lambda expression can be programmed such that very simple, especially for simple functions, the following general form:

  [Object function parameters] (operator overloading function parameters) -> Return Value {} function body

  Here are a few examples and explanations:

Here Insert Picture Description

5 arbitrary variable length parameter template

  In Python and MATLAB can be very convenient to use variable length parameter, C ++ introduced after 11 tuple, can achieve similar functions, and may pass a plurality of different types of data, as shown in FIG.

Here Insert Picture Description

6 Other new features

  Learn it yourself

  In addition to several kinds of new features introduced above, there are many new features, such as:

  decltype: Like auto reverse function can be obtained from the type of a variable or expression;
  nullptr: to solve the problem of ambiguity of the original C ++, NULL;
  STL containers, smart pointers, multi-thread-related new features

  A lot of information can be found on the Internet, if too lazy to look for, you can look at the following two links.

https://www.cnblogs.com/feng-sc/p/5710724.html

http://towriting.com/blog/2013/08/01/what-is-cpp11/

Exercises

  Please use the following rewrite the new features of C ++ functions. The Function: unordered set of coordinates in accordance with a "Z" shape sorting, and output.

This program learning objectives:

  Familiar with the characteristics of the new C ++ (cycle simplified, automatic type inference, list initialization, lambda function)

  topic:

Here Insert Picture Description

  Correct output:

Here Insert Picture Description

Guess you like

Origin blog.csdn.net/wb790238030/article/details/88241994