Venkatesh Maharajan

  1. Move Semantics
    Allows transferring resources instead of copying them, improving performance in large data structures.

    #include <iostream>
    #include <vector>
    
    std::vector<int> createLargeVector() {
        std::vector<int> v(1000000, 42);
        return v; // Uses move semantics, avoids expensive copy
    }
    
    int main() {
        auto data = createLargeVector();
        std::cout << "Size: " << data.size() << "\n";
    }
  2. Smart Pointers
    Provides safe memory management using std::unique_ptr and std::shared_ptr, avoiding manual delete.

    #include <memory>
    #include <iostream>
    
    struct Foo {
        Foo() { std::cout << "Foo created\n"; }
        ~Foo() { std::cout << "Foo destroyed\n"; }
    };
    
    int main() {
        std::unique_ptr<Foo> ptr = std::make_unique<Foo>();
        // Automatic cleanup, no need for delete
    }
  3. constexpr for Compile-Time Computation
    Enables functions to be evaluated at compile time for improved performance and safety.

    constexpr int square(int x) {
        return x * x;
    }
    
    int main() {
        constexpr int result = square(5);
        static_assert(result == 25);
    }
  4. Comparison With Rust

    FeatureC++Rust
    Memory SafetyManual / Smart PointersBorrow Checker + Ownership
    Concurrency SafetyOptional LibrariesBuilt-in with Send and Sync
    Compile-Time Constconstexprconst fn
  5. Inline Images
    Example:
    Memory Layout

  6. Blockquotes for Notes

    Pro Tip: Always prefer std::make_unique over new for exception safety.

  7. Lists and Sub-Lists

    • Move semantics
    • RAII (Resource Acquisition Is Initialization)
    • Strong type safety
      • enum class
      • auto type deduction
  8. Conclusion
    Modern C++ provides safer and more expressive constructs while keeping its low-level control. Rust offers memory safety guarantees without garbage collection, making it worth evaluating for new projects.