2 options
Data Structures and Algorithms with the C++ STL : A Guide for Modern C++ Practitioners / John Farrier.
- Format:
- Book
- Author/Creator:
- Farrier, John, author.
- Language:
- English
- Subjects (All):
- C++ (Computer program language).
- Data structures (Computer science).
- Object-oriented programming (Computer science).
- Physical Description:
- 1 online resource (458 pages)
- Edition:
- First edition.
- Place of Publication:
- Birmingham, England : Packt Publishing, [2024]
- Summary:
- 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 applications Gain insights into advanced topics such as exception guarantees and thread safety Purchase of the print or Kindle book includes a free PDF eBook Book Description While the Standard Template Library (STL) offers a rich set of tools for data structures and algorithms, navigating its intricacies can be daunting for intermediate C++ developers without expert guidance. This book offers a thorough exploration of the STL's components, covering fundamental data structures, advanced algorithms, and concurrency features. Starting with an in-depth analysis of the std::vector, this book highlights its pivotal role in the STL, progressing toward building your proficiency in utilizing vectors, managing memory, and leveraging iterators. The book then advances to STL's data structures, including sequence containers, associative containers, and unordered containers, simplifying the concepts of container adaptors and views to enhance your knowledge of modern STL programming. Shifting the focus to STL algorithms, you'll get to grips with sorting, searching, and transformations and develop the skills to implement and modify algorithms with best practices. Advanced sections cover extending the STL with custom types and algorithms, as well as concurrency features, exception safety, and parallel algorithms. By the end of this book, you'll have transformed into a proficient STL practitioner ready to tackle real-world challenges and build efficient and scalable C++ applications. What you will learn Streamline data handling using the std::vector Master advanced usage of STL iterators Optimize memory in STL containers Implement custom STL allocators Apply sorting and searching with STL algorithms Craft STL-compatible custom types Manage concurrency and ensure thread safety in STL Harness the power of parallel algorithms in STL Who this book is for This book is for intermediate-level C++ developers looking to enhance their software development skills. Familiarity with basic C++ syntax and object-oriented programming (OOP) as well as some exposure to data structures and algorithms is assumed. Tailored to software engineers, computer science students, and hobbyist programmers, this book delves into C++ STL for practical application, performance enhancement, and efficient coding practices.
- Contents:
- 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
- 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
- Chapter 3: Mastering Memory and Allocators with std::vector
- 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
- Chapter 4: Mastering Algorithms with std::vector
- 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
- 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
- Part 2: Understanding STL Data Structures
- Chapter 6: Advanced Sequence Container Usage
- 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
- Special interface and member functions
- std::deque
- std::list
- Exceptions.
- Customization
- std::forward_list
- std::string
- Chapter 7: Advanced Ordered Associative Container Usage
- std::set
- std::map
- std::multiset
- std::multimap
- Thread safety.
- Extensions and variants
- Chapter 8: Advanced Unordered Associative Container Usage
- std::unordered_set
- std::unordered_map
- std::unordered_multiset
- std::unordered_multimap
- Chapter 9: Advanced Container Adaptor Usage
- std::stack
- Extensions and variants.
- Sorting and searching complexity.
- Notes:
- Description based on publisher supplied metadata and other sources.
- Description based on print version record.
- ISBN:
- 9781835469071
- 1835469078
- OCLC:
- 1422746383
The Penn Libraries is committed to describing library materials using current, accurate, and responsible language. If you discover outdated or inaccurate language, please fill out this feedback form to report it and suggest alternative language.