Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Mastering C++ Programming
Mastering C++ Programming

Mastering C++ Programming: Modern C++ 17 at your fingertips

Arrow left icon
Profile Icon Swaminathan
Arrow right icon
Mex$631.99 Mex$902.99
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3 (2 Ratings)
eBook Sep 2017 384 pages 1st Edition
eBook
Mex$631.99 Mex$902.99
Paperback
Mex$1128.99
Subscription
Free Trial
Arrow left icon
Profile Icon Swaminathan
Arrow right icon
Mex$631.99 Mex$902.99
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3 (2 Ratings)
eBook Sep 2017 384 pages 1st Edition
eBook
Mex$631.99 Mex$902.99
Paperback
Mex$1128.99
Subscription
Free Trial
eBook
Mex$631.99 Mex$902.99
Paperback
Mex$1128.99
Subscription
Free Trial

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Mastering C++ Programming

Standard Template Library

This chapter will cover the following topics:

  • STL overview
  • STL architecture
    • Containers
    • Iterators
    • Algorithms
    • Functors
  • STL containers
    • Sequence
    • Associative
    • Unordered
    • Adaptors

Let's look into the STL topics one by one in the following sections.

The Standard Template Library architecture

The C++ Standard Template Library (STL) offers ready-made generic containers, algorithms that can be applied to the containers, and iterators to navigate the containers. The STL is implemented with C++ templates, and templates allow generic programming in C++.

The STL encourages a C++ developer to focus on the task at hand by freeing up the developer from writing low-level data structures and algorithms. The STL is a time-tested library that allows rapid application development.  

The STL is an interesting piece of work and architecture. Its secret formula is compile-time polymorphism. To get better performance, the STL avoids dynamic polymorphism, saying goodbye to virtual functions. Broadly, the STL has the following four components:

  • Algorithms
  • Functors
  • Iterators
  • Containers

The STL architecture stitches all the aforementioned...

Sequence containers

The STL supports quite an interesting variety of sequence containers. Sequence containers store homogeneous data types in a linear fashion, which can be accessed sequentially. The STL supports the following sequence containers:

  • Arrays
  • Vectors
  • Lists
  • forward_list 
  • deque

As the objects stored in an STL container are nothing but copies of the values, the STL expects certain basic requirements from the user-defined data types in order to hold those objects inside a container. Every object stored in an STL container must provide the following as a minimum requirement:

  • A default constructor
  • A copy constructor
  • An assignment operator

Let's explore the sequence containers one by one in the following subsections.

Array

...

Associative containers

Associative containers store data in a sorted fashion, unlike the sequence containers. Hence, the order in which the data is inserted will not be retained by the associative containers. Associative containers are highly efficient in searching a value with O( log n ) runtime complexity. Every time a new value gets added to the container, the container will reorder the values stored internally if required.

The STL supports the following types of associative containers:

  • Set
  • Map
  • Multiset 
  • Multimap
  • Unordered set
  • Unordered multiset
  • Unordered map
  • Unordered multimap

Associative containers organize the data as key-value pairs. The data will be sorted based on the key for random and faster access. Associative containers come in two flavors:

  • Ordered 
  • Unordered

The following associative containers come under ordered containers, as they are ordered/sorted...

Container adapters

Container adapters adapt existing containers to provide new containers. In simple terms, STL extension is done with composition instead of inheritance.

STL containers can't be extended by inheritance, as their constructors aren't virtual. Throughout the STL, you can observe that while static polymorphism is used both in terms of operator overloading and templates, dynamic polymorphism is consciously avoided for performance reasons. Hence, extending the STL by subclassing the existing containers isn't a good idea, as it would lead to memory leaks because container classes aren't designed to behave like base classes.

The STL supports the following container adapters:

  • Stack
  • Queue
  • Priority Queue

Let's explore the container adapters in the following subsections.

...

Summary

In this chapter you learned about ready-made generic containers, functors, iterators, and algorithms. You also learned set, map, multiset, and multimap associative containers, their internal data structures, and common algorithms that can be applied on them. Further you learned how to use the various containers with practical hands-on code samples.

In the next chapter, you will learn template programming, which helps you master the essentials of templates.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • ? ?Get ? ?acquainted ? ?with ? ?the ? ?latest ? ?features ? ?in ? ?C++ ? ?17
  • ? ?Take ? ?advantage ? ?of ? ?the ? ?myriad ? ?of ? ?features ? ?and ? ?possibilities ? ?that ? ?C++ offers ? ?to ? ?build ? real-world ? ?applications
  • ? ?Write ? ?clear ? ?and ? ?expressive ? ?code ? ?in ? ?C++, ? ?and ? ?get ? ?insights ? ?into ? ?how ? ?to keep ? ?your ? ?code ? ?error-free

Description

C++ ? ?has ? ?come ? ?a ? ?long ? ?way ? ?and ? ?has ? ?now ? ?been ? ?adopted ? ?in ? ?several ? ?contexts. Its ? ?key ? ?strengths ? ?are ? ?its ? ?software ? ?infrastructure ? ?and ? ?resource-constrained applications. ? ?The ?C++ ? ?17 ? ?release ? ?will ? ?change ? ?the ? ?way ? ?developers ? ?write code, ? ?and ? ?this ? ?book ? ?will ? ?help ?you ? ?master ? ?your ? ?developing ? ?skills ? ?with ? ?C++. With ? ?real-world, ? ?practical ? ?examples ? ?explaining ? ?each ? ?concept, ? ?the ? ?book ? ?will begin ? ?by ? ?introducing ? ?you ? ?to ? ?the ? ?latest ? ?features ? ?in ? ?C++ ? ?17. ? ?It ? ?encourages clean ? ?code ? ?practices ? ?in ? ?C++ ? ?in ? ?general, ? ?and ? ?demonstrates ? ?the ? ?GUI app-development ? ?options ? ?in ? ?C++. ? ?You’ll ? ?get ? ?tips ? ?on ? ?avoiding ? ?memory ? ?leaks using ? ?smart-pointers. ? ?Next, ? ?you’ll ? ?see ? ?how ? ?multi-threaded ?programming can ? ?help ? ?you ? ?achieve ? ?concurrency ? ?in ? ?your ? ?applications. Moving ? ?on, ? ?you’ll ? ?get ? ?an ? ?in-depth ? ?understanding ? ?of ? ?the ? ?C++ ? ?Standard Template ? ?Library. ? ?We ? ?show ? ?you ? ?the ? ?concepts ? ?of ? ?implementing ? ?TDD ? ?and BDD ? ?in ? ?your ? ?C++ ? ?programs, ? ?and ? ?explore ? ?template-based ? ?generic programming, ? ?giving ? ?you ? ?the ? ?expertise ? ?to ? ?build ? ?powerful ? ?applications. Finally, ? ?we’ll ? ?round ? ?up ? ?with ? ?debugging ? ?techniques ? ?and ? ?best ? ?practices.By ? ?the ? ?end ? ?of ? ?the ? ?book, ? ?you’ll ? ?have ? ?an ? ?in-depth ? ?understanding ? ?of ? ?the language ? ?and ? ?its ? ?various ? ?facets.

Who is this book for?

This ? ?book ? ?is ? ?for ? ?experienced ? ?C++ ? ?developers. ? ?If ? ?you ? ?are ? ?a ? ?novice ? ?C++ developer, ? then ? ?it’s ? ?highly ? ?recommended ? ?that ? ?you ? ?get ? ?a ? ?solid understanding ? ?of ? ?the ? ?C++ ? ?language ? ?before ? ?reading ? ?this ? ?book

What you will learn

  • ? ?Write ? ?modular ? ?C++ ? ?applications ? ?in ? ?terms ? ?of ? ?the ? ?existing ? ?and newly ? ?introduced ? ?features
  • ? ?Identify ? ?code-smells, ? ?clean ? ?up, ? ?and ? ?refactor ? ?legacy ? ?C++ applications
  • ? ?Leverage ? ?the ? ?possibilities ? ?provided ? ?by ? ?Cucumber ? ?and ? ?Google Test/Mock ? ?to automate ? ?test ? ?cases
  • ? ?Test ? ?frameworks ? ?with ? ?C++
  • ? ?Get ? ?acquainted ? ?with ? ?the ? ?new ? ?C++17 ? ?features
  • ? ?Develop ? ?GUI ? ?applications ? ?in ? ?C++
  • ? ?Build ? ?portable ? ?cross-platform ? ?applications ? ?using ? ?standard ? ?C++ features

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 01, 2017
Length: 384 pages
Edition : 1st
Language : English
ISBN-13 : 9781786461933
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : Sep 01, 2017
Length: 384 pages
Edition : 1st
Language : English
ISBN-13 : 9781786461933
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Mex$85 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Mex$85 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total Mex$ 3,262.97
Mastering C++ Programming
Mex$1128.99
Mastering C++ Multithreading
Mex$1004.99
Modern C++ Programming Cookbook
Mex$1128.99
Total Mex$ 3,262.97 Stars icon

Table of Contents

10 Chapters
C++17 Features Chevron down icon Chevron up icon
Standard Template Library Chevron down icon Chevron up icon
Template Programming Chevron down icon Chevron up icon
Smart Pointers Chevron down icon Chevron up icon
Developing GUI Applications in C++ Chevron down icon Chevron up icon
Multithreaded Programming and Inter-Process Communication Chevron down icon Chevron up icon
Test-Driven Development Chevron down icon Chevron up icon
Behavior-Driven Development Chevron down icon Chevron up icon
Debugging Techniques Chevron down icon Chevron up icon
Code Smells and Clean Code Practices Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
(2 Ratings)
5 star 50%
4 star 0%
3 star 0%
2 star 0%
1 star 50%
RPDevJesco Dec 13, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Honestly, this book is a must have for anyone interested in learning C++.
Amazon Verified review Amazon
Amazon Customer Oct 07, 2018
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
As a fan of Jegan, baught the book.But poor content for experienced guys.Request Jegan to improve the content of topics at thorough level as this book is written for experienced developers.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.