Home 30 items of modern C++ (from c++ 11 to c++20)(English)
Post
Cancel

30 items of modern C++ (from c++ 11 to c++20)(English)

Introduction to C++

C++ is a general-purpose, statically typed programming language that supports multiple paradigms. It is known for its efficiency, scalability, and flexibility, and is commonly used in fields such as system development, game development, embedded systems, and high-performance computing. C++ was initially developed by Bjarne Stroustrup in the 1980s, building upon and enhancing the foundation of the C language.

Advantages: It runs very fast (although that doesn’t mean you can code quickly!) Disadvantages: It’s challenging to learn! This is due to its rich language features, complex syntax and concepts, the need for a deep understanding of low-level details, and extensive standard libraries and tools.

Desktop View

Reference: Tiobe Index

Summary of C++

Why summarize? Because C++ continues to evolve, making it more modern, secure, and user-friendly, with significant changes occurring almost every 3 to 4 years. Below is a summary of the important milestones in modern C++ (post-C++11, including C++11, C++14, C++17, C++20), totaling 30 items.

30 items of modern C++

  1. Automatic type inference (auto keyword): Allows the compiler to deduce the type of a variable based on the type of the initialization expression.(𝘊++ 11)
  2. Range-based for loop: Allows convenient iteration over elements in a container using syntax like for (auto& x : vec).(𝘊++ 11)
  3. Move semantics: Introduces rvalue references (&&) and move constructors to efficiently move temporary objects, improving performance.(𝘊++ 11)
  4. New container types: Introduces new standard containers like std::array, std::unordered_map, etc.(𝘊++ 11)
  5. Lambda expressions: Similar to anonymous functions, can be used where function objects are needed.(𝘊++ 11)
  6. Null pointer constant (nullptr): Used to represent null pointers, replacing the traditional NULL macro.(𝘊++ 11)
  7. Smart pointers: std::unique_ptr and std::shared_ptr provide safer and more convenient memory management.(𝘊++ 11)
  8. Enhanced support for multithreading: Introduces multithreading-related libraries like std::thread, std::mutex, etc.(𝘊++ 11)
  9. constexpr: Used for compile-time evaluation of constant expressions, improving performance.(𝘊++ 11)
  10. static_assert: Used for static assertions at compile-time to check code consistency.(𝘊++ 11)

  11. Binary literals: Allows the use of 0b or 0B as prefixes to represent binary numbers.(𝘊++ 14)
  12. Generic lambda expressions: Lambda expressions can use auto in parameter lists, facilitating the creation of generic function objects.(𝘊++ 14)
  13. Return type deduction: Allows the return type of functions to be deduced using auto.(𝘊++ 14)
  14. Initialization capture: In lambda expressions, variables can be captured by initialization (e.g., [x = std::move(x)]).(𝘊++ 14)
  15. Constexpr functions: Allows the use of if statements and local variables in constexpr functions.(𝘊++ 14)

  16. Fold expressions: Introduces new syntax for simplifying traversal and operations on parameter packs.(𝘊++ 17)
  17. Enhance shared_ptr: shared_ptr supports for creating dynamic arrays(𝘊++ 17)
  18. Initialization in if statements: Allows direct initialization of variables in if and switch statements.(𝘊++ 17)
  19. Structured bindings: Allows unpacking of tuples or other types of objects into multiple variables.(𝘊++ 17)
  20. constexpr if: Introduces new syntax for compile-time selection based on conditions.(𝘊++ 17)
  21. New features for aggregate classes: Relaxes restrictions on aggregate classes, allowing base classes, additional non-static data members, etc.(𝘊++ 17)
  22. reduce: perform reduction operations on a range of elements(𝘊++ 17)

  23. Concepts: Introduces new syntax for defining constraints on template formal parameters to improve the readability and error messages of template code.(𝘊++ 20)
  24. Operations on ranges: Introduces new libraries for defining and manipulating the concept of ranges.(𝘊++ 20)
  25. Coroutines: Introduces new syntax and libraries for supporting coroutines, making asynchronous programming more convenient.(𝘊++ 20)
  26. Range-based for Loop Enhancements: supports initialization statements and initializers in the range-based for loop(𝘊++ 20)
  27. Modules: Introduces new syntax and standard libraries for defining and using modules to address issues with traditional header file inclusion mechanisms.(𝘊++ 20)
  28. Designated initializer: Explicitly specify how each member of a structure or union is initialized when using an initializer list.(𝘊++ 20)
  29. three-way comparison operator: It simplifies and unifies comparison operations between objects, allowing the generation of all comparison operators at once.(𝘊++ 20)
  30. likely and unlikely Attributes: provide the compiler with additional information to better improve performance.(𝘊++ 20)

Rest assured! Each item will have code and usage explanations! ^ ^

☝ツ☝

This post is licensed under CC BY 4.0 by the author.

👈 ツ 👍