Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Modern C++: Efficient and Scalable Application Development

You're reading from   Modern C++: Efficient and Scalable Application Development Leverage the modern features of C++ to overcome difficulties in various stages of application development

Arrow left icon
Product type Course
Published in Dec 2018
Publisher
ISBN-13 9781789951738
Length 702 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Richard Grimes Richard Grimes
Author Profile Icon Richard Grimes
Richard Grimes
Marius Bancila Marius Bancila
Author Profile Icon Marius Bancila
Marius Bancila
Arrow right icon
View More author details
Toc

Table of Contents (24) Chapters Close

Title Page
Copyright
About Packt
Contributors
Preface
1. Understanding Language Features FREE CHAPTER 2. Working with Memory, Arrays, and Pointers 3. Using Functions 4. Classes 5. Using the Standard Library Containers 6. Using Strings 7. Diagnostics and Debugging 8. Learning Modern Core Language Features 9. Working with Numbers and Strings 10. Exploring Functions 11. Standard Library Containers, Algorithms, and Iterators 12. Math Problems 13. Language Features 14. Strings and Regular Expressions 15. Streams and Filesystems 16. Date and Time 17. Algorithms and Data Structures 1. Other Books You May Enjoy Index

Using vector<bool> for variable-size sequences of bits


In the previous recipe, we looked at using std::bitset for fixed-size sequences of bits. Sometimes, however, an std::bitset is not a good choice because you do not know the number of bits at compile time, and just defining a set of a large enough number of bits is not a good idea because you can get into a situation when the number is not actually large enough. The standard alternative for this is to use the std::vector<bool> container that is a specialization of std::vector with space and speed optimizations, as implementations do not actually store Boolean values, but individual bits for each element.

Note

For this reason, however, std::vector<bool> does not meet the requirements of a standard container or sequential container, nor does std::vector<bool>::iterator meet the requirements of a forward iterator. As a result, this specialization cannot be used in generic code where a vector is expected. On the other...

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
Visually different images