Sobes.tech
Junior — Middle

What improvements have been made to the C++ language with the introduction of the C++11 standard?

sobes.tech AI

Answer from AI

The C++11 standard introduced many improvements and new features, including:

  • Type inference (auto) — simplifies variable declarations.
  • Smart pointers (std::unique_ptr, std::shared_ptr) — for safe management of dynamic memory.
  • Lambda expressions — allow writing anonymous functions directly at the point of use.
  • Constant expressions (constexpr) — compile-time computations.
  • Range-based for loops — simplify iteration over collection elements.
  • Multithreading — introduced standard threads (std::thread), mutexes, and other synchronization tools.
  • Move semantics and rvalue references — optimize resource transfer.
  • Fixed-width integer types (<cstdint>) — for more precise control over types.

Example of a lambda expression:

#include <iostream>
#include <vector>

int main() {
    std::vector<int> v = {1, 2, 3, 4, 5};
    int sum = 0;
    std::for_each(v.begin(), v.end(), [&sum](int n) { sum += n; });
    std::cout << "Sum: " << sum << std::endl;
    return 0;
}