Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Data Structures and Algorithms with the C++ STL

You're reading from   Data Structures and Algorithms with the C++ STL A guide for modern C++ practitioners

Arrow left icon
Product type Paperback
Published in Feb 2024
Publisher Packt
ISBN-13 9781835468555
Length 458 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
John Farrier John Farrier
Author Profile Icon John Farrier
John Farrier
Arrow right icon
View More author details
Toc

Table of Contents (30) Chapters Close

Preface 1. Part 1: Mastering std::vector FREE CHAPTER
2. Chapter 1: The Basics of std::vector 3. Chapter 2: Mastering Iterators with std::vector 4. Chapter 3: Mastering Memory and Allocators with std::vector 5. Chapter 4: Mastering Algorithms with std::vector 6. Chapter 5: Making a Case for std::vector 7. Part 2: Understanding STL Data Structures
8. Chapter 6: Advanced Sequence Container Usage 9. Chapter 7: Advanced Ordered Associative Container Usage 10. Chapter 8: Advanced Unordered Associative Container Usage 11. Chapter 9: Advanced Container Adaptor Usage 12. Chapter 10: Advanced Container View Usage 13. Part 3: Mastering STL Algorithms
14. Chapter 11: Fundamental Algorithms and Searching 15. Chapter 12: Manipulation and Transformation 16. Chapter 13: Numeric and Range -Based Operations 17. Chapter 14: Permutations, Partitions, and Heaps 18. Chapter 15: STL with Ranges 19. Part 4: Creating STL-Compatible Types and Algorithms
20. Chapter 16: Creating STL-Types Containers 21. Chapter 17: Creating STL -Compatible Algorithms 22. Chapter 18: Type Traits and Policies 23. Part 5: STL Data Structures and Algorithms: Under the Hood
24. Chapter 19: Exception Safety 25. Chapter 20: Thread Safety and Concurrency with the STL 26. Chapter 21: STL Interaction with Concepts and Coroutines 27. Chapter 22: Parallel Algorithms with the STL 28. Index 29. Other Books You May Enjoy

Manipulating vectors

Vectors in C++ are dynamic arrays that not only store data but offer a suite of operations to manipulate that data, especially when paired with the algorithms provided by the STL. These algorithms allow developers to optimize data movement and transformation tasks with elegance. Let’s delve into the art of manipulating std::vector with some powerful algorithms.

Transforming with std::copy

Imagine you’ve got one vector and wish to copy its elements to another. Simple looping might come to mind, but there’s a more efficient and expressive way: std::copy.

Consider two vectors as shown in the following code:

std::vector<int> source = {1, 2, 3, 4, 5};
std::vector<int> destination(5);

Copying the elements is as straightforward as shown in the following:

std::copy(source.begin(), source.end(), destination.begin());

destination holds {1, 2, 3, 4, 5}. It’s worth noting that the destination vector should have enough...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime