Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Template Metaprogramming with C++

You're reading from   Template Metaprogramming with C++ Learn everything about C++ templates and unlock the power of template metaprogramming

Arrow left icon
Product type Paperback
Published in Aug 2022
Publisher Packt
ISBN-13 9781803243450
Length 480 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Marius Bancila Marius Bancila
Author Profile Icon Marius Bancila
Marius Bancila
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Preface 1. Part 1: Core Template Concepts
2. Chapter 1: An Introduction to Templates FREE CHAPTER 3. Chapter 2: Template Fundamentals 4. Chapter 3: Variadic Templates 5. Part 2: Advanced Template Features
6. Chapter 4: Advanced Template Concepts 7. Chapter 5: Type Traits and Conditional Compilation 8. Chapter 6: Concepts and Constraints 9. Part 3: Applied Templates
10. Chapter 7: Patterns and Idioms 11. Chapter 8: Ranges and Algorithms 12. Chapter 9: The Ranges Library 13. Assignment Answers 14. Other Books You May Enjoy Appendix: Closing Notes

Advancing from abstract ranges to the ranges library

We have used the term range many times in the previous chapter. A range is an abstraction of a sequence of elements, delimited by two iterators (one to the first element of the sequence, and one to the one-past-the-last element). Containers such as std::vector, std::list, and std::map are concrete implementations of the range abstraction. They have ownership of the elements and they are implemented using various data structures, such as arrays, linked-lists, or trees. The standard algorithms are generic. They are container-agnostic. They know nothing about std::vector, std::list, or std::map. They handle range abstractions with the help of iterators. However, this has a shortcoming: we always need to retrieve a beginning and end iterator from a container. Here are some examples:

// sorts a vector
std::vector<int> v{ 1, 5, 3, 2, 4 };
std::sort(v.begin(), v.end());
// counts even numbers in an array
std::array<int, 5&gt...
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
Banner background image