Data Structures and Algorithms with the C++ STL A Guide for Modern C++ Practitioners

Explore the C++ STL with practical guidance on vectors, algorithms, and custom types for intermediate developers, enriched by real-world examples. Key Features Master the std::vector and understand why it should be your default container of choice Understand each STL algorithm and its practical appl...

Descripción completa

Detalles Bibliográficos
Otros Autores: Farrier, John, author (author)
Formato: Libro electrónico
Idioma:Inglés
Publicado: Birmingham, England : Packt Publishing [2024]
Edición:First edition
Materias:
Ver en Biblioteca Universitat Ramon Llull:https://discovery.url.edu/permalink/34CSUC_URL/1im36ta/alma991009805127206719
Tabla de Contenidos:
  • Intro
  • Title page
  • Copyright and credits
  • Dedication
  • Contributors
  • Table of Contents
  • Preface
  • Part 1: Mastering std::vector
  • Chapter 1: The Basics of std::vector
  • Technical requirements
  • The significance of std::vector
  • A basic comparison of C-style arrays and std::vector
  • Comparison of C-style arrays and std::vector for memory management
  • Declaring and initializing std::vector
  • Declaring a vector
  • Initializing a vector
  • Accessing elements
  • Random access
  • Accessing the first and last elements
  • Vector size
  • Adding and removing elements
  • Adding elements
  • Removing elements
  • Capacity
  • Prefer using empty() when possible
  • Clearing all elements
  • Summary
  • Chapter 2: Mastering Iterators with std::vector
  • Technical requirements
  • Types of iterators in the STL
  • Input iterators
  • Output iterators
  • Forward iterators
  • Reverse iterators
  • Bidirectional iterators
  • Random access iterators
  • Basic iteration techniques with std::vector
  • Iterating over std::vector
  • Basic iteration using iterators
  • Using constant iterators
  • Benefits of iteration
  • Using std::begin and std::end
  • Understanding iterator requirements
  • Range-based for loops
  • Overview of range-based for loops
  • When to use range-based for loops
  • Modifying elements during iteration
  • Creating a custom iterator
  • The appeal of custom iterators
  • Core requirements
  • Iterator categories and their specialties
  • A custom iterator example
  • Custom iterator challenges and use cases
  • Illustrative use cases of custom iterators
  • Summary
  • Chapter 3: Mastering Memory and Allocators with std::vector
  • Technical requirements
  • Understanding capacity versus size
  • Revisiting the basics
  • What exactly is capacity?
  • Why this distinction matters
  • Looking under the hood
  • Resizing and reserving memory.
  • The power of resize()
  • Enter reserve()
  • Optimizing with shrink_to_fit()
  • Real-world relevance
  • Custom allocator basics
  • The role and responsibility of an allocator
  • Under the hood - the allocator interface
  • Trade-offs and the need for custom allocators
  • Choosing std::allocator over new, delete, and managed pointers
  • Creating a custom allocator
  • Custom allocators - the heart of memory flexibility
  • Understanding the motivation behind custom allocators
  • Memory pools - a popular custom allocator strategy
  • Unlocking the potential of custom allocators
  • Allocators and container performance
  • Why allocators matter in performance
  • The performance characteristics of std::allocator
  • When to consider alternative allocators
  • Profiling - the key to making informed decisions
  • Summary
  • Chapter 4: Mastering Algorithms with std::vector
  • Technical requirements
  • Sorting a vector
  • Getting started with std::sort
  • The engine under the hood - introsort
  • Efficiency unparalleled - O(n log n)
  • Sorting in descending order
  • Sorting custom data types
  • Pitfalls and precautions
  • Searching elements
  • Linear search with std::find
  • Binary search techniques
  • Using std::lower_bound and std::upper_bound
  • Binary search versus linear search - efficiency and versatility
  • Manipulating vectors
  • Transforming with std::copy
  • Reversing elements with std::reverse
  • Rotating vectors with std::rotate
  • Filling a vector with std::fill
  • Putting manipulation to use
  • Considerations in manipulation
  • Custom comparators and predicates
  • Understanding comparators
  • The power of predicates
  • Crafting effective comparators and predicates
  • User-defined structs and classes
  • Understanding container invariants and iterator invalidation
  • Understanding iterator invalidation
  • Strategies to counteract invalidation.
  • Dealing with invalidation in multi-threaded scenarios
  • Summary
  • Chapter 5: Making a Case for std::vector
  • Performance considerations
  • Comparison with other containers
  • The memory advantage
  • The takeaway
  • Practical use cases
  • A resizable dynamic array at heart
  • Data processing and analytics
  • Graphics and game development
  • Beyond just containers
  • Versatility and efficiency
  • A testament to versatility
  • Efficiency isn't just about speed
  • A safe default, but not the only option
  • Summary
  • Part 2: Understanding STL Data Structures
  • Chapter 6: Advanced Sequence Container Usage
  • Technical requirements
  • std::array
  • Purpose and suitability
  • Ideal use cases
  • Performance
  • Memory management
  • Thread safety
  • Extensions and variants
  • Sorting and searching complexity
  • Interface and member functions
  • Comparisons
  • Interactions with algorithms
  • Exceptions
  • Customization
  • Example
  • Best practices
  • std::vector
  • Purpose and suitability
  • Ideal use cases
  • Performance
  • Memory management
  • Thread safety
  • Extensions and variants
  • Sorting and searching complexity
  • Special interface and member functions
  • Comparisons
  • Interactions with algorithms
  • Exceptions
  • Customization
  • Example
  • Best practices
  • std::deque
  • Purpose and suitability
  • Ideal use cases
  • Performance
  • Memory management
  • Thread safety
  • Extensions and variants
  • Sorting and searching complexity
  • Interface and member functions
  • Comparisons
  • Interactions with algorithms
  • Exceptions
  • Customization
  • Example
  • Best practices
  • std::list
  • Purpose and suitability
  • Ideal use cases
  • Performance
  • Memory management
  • Thread safety
  • Extensions and variants
  • Sorting and searching complexity
  • Interface and member functions
  • Comparisons
  • Interactions with algorithms
  • Exceptions.
  • Customization
  • Example
  • Best practices
  • std::forward_list
  • Purpose and suitability
  • Ideal use cases
  • Performance
  • Memory management
  • Thread safety
  • Extensions and variants
  • Sorting and searching complexity
  • Special interface and member functions
  • Comparisons
  • Interactions with algorithms
  • Exceptions
  • Customization
  • Example
  • Best practices
  • std::string
  • Purpose and suitability
  • Ideal use cases
  • Performance
  • Memory management
  • Thread safety
  • Extensions and variants
  • Sorting and searching complexity
  • Special interface and member functions
  • Comparisons
  • Interactions with algorithms
  • Exceptions
  • Customization
  • Example
  • Best practices
  • Chapter 7: Advanced Ordered Associative Container Usage
  • Technical requirements
  • std::set
  • Purpose and suitability
  • Ideal use cases
  • Performance
  • Memory management
  • Thread safety
  • Extensions and variants
  • Sorting and searching complexity
  • Special interface and member functions
  • Comparisons
  • Interactions with algorithms
  • Exceptions
  • Customization
  • Example
  • Best practices
  • std::map
  • Purpose and suitability
  • Ideal use cases
  • Performance
  • Memory management
  • Thread safety
  • Extensions and variants
  • Sorting and searching complexity
  • Special interface and member functions
  • Comparisons
  • Interactions with algorithms
  • Exceptions
  • Customization
  • Example
  • Best practices
  • std::multiset
  • Purpose and suitability
  • Ideal use cases
  • Performance
  • Memory management
  • Thread safety
  • Extensions and variants
  • Sorting and searching complexity
  • Special interface and member functions
  • Comparisons
  • Interactions with algorithms
  • Exceptions
  • Customization
  • Example
  • Best practices
  • std::multimap
  • Purpose and suitability
  • Ideal use cases
  • Performance
  • Memory management
  • Thread safety.
  • Extensions and variants
  • Sorting and searching complexity
  • Special interface and member functions
  • Comparisons
  • Interactions with algorithms
  • Exceptions
  • Customization
  • Example
  • Best practices
  • Chapter 8: Advanced Unordered Associative Container Usage
  • Technical requirements
  • std::unordered_set
  • Purpose and suitability
  • Ideal use cases
  • Performance
  • Memory management
  • Thread safety
  • Extensions and variants
  • Sorting and searching complexity
  • Special interface and member functions
  • Comparisons
  • Interactions with algorithms
  • Exceptions
  • Customization
  • Example
  • Best practices
  • std::unordered_map
  • Purpose and suitability
  • Ideal use cases
  • Performance
  • Memory management
  • Thread safety
  • Extensions and variants
  • Sorting and searching complexity
  • Special interface and member functions
  • Comparisons
  • Interactions with algorithms
  • Exceptions
  • Customization
  • Example
  • Best practices
  • std::unordered_multiset
  • Purpose and suitability
  • Ideal use cases
  • Performance
  • Memory management
  • Thread safety
  • Extensions and variants
  • Sorting and searching complexity
  • Special interface and member functions
  • Comparisons
  • Interactions with algorithms
  • Exceptions
  • Customization
  • Example
  • Best practices
  • std::unordered_multimap
  • Purpose and suitability
  • Ideal use cases
  • Performance
  • Memory management
  • Thread safety
  • Extensions and variants
  • Sorting and searching complexity
  • Special interface and member functions
  • Comparisons
  • Interactions with algorithms
  • Exceptions
  • Customization
  • Example
  • Best practices
  • Chapter 9: Advanced Container Adaptor Usage
  • Technical requirements
  • std::stack
  • Purpose and suitability
  • Ideal use cases
  • Performance
  • Memory management
  • Thread safety
  • Extensions and variants.
  • Sorting and searching complexity.