Mastering C++ Programming
eBook - ePub

Mastering C++ Programming

  1. 384 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Mastering C++ Programming

Book details
Book preview
Table of contents
Citations

About This Book

Take your C++ coding to the next level by leveraging the latest features and advanced techniques to building high performing, reliable applications. About This Bookā€¢ 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-freeWho This Book Is ForThis 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 In DetailC++ 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. Style and approachThis straightforward guide will help you level up your skills in C++ programming, be it for enterprise software or for low-latency applications like games. Filled with real-world, practical examples, this book will take you gradually up the steep learning curve that is C++.

Frequently asked questions

Simply head over to the account section in settings and click on ā€œCancel Subscriptionā€ - itā€™s as simple as that. After you cancel, your membership will stay active for the remainder of the time youā€™ve paid for. Learn more here.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Both plans give you full access to the library and all of Perlegoā€™s features. The only differences are the price and subscription period: With the annual plan youā€™ll save around 30% compared to 12 months on the monthly plan.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, weā€™ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes, you can access Mastering C++ Programming by Jeganathan Swaminathan in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming in C++. We have over one million books available in our catalogue for you to explore.

Information

Year
2017
ISBN
9781786461933
Edition
1

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 four components together. It has many commonly used algorithms with performance guarantees. The interesting part about STL algorithms is that they work seamlessly without any knowledge about the containers that hold the data. This is made possible due to the iterators that offer high-level traversal APIs, which completely abstracts the underlying data structure used within a container. The STL makes use of operator overloading quite extensively. Let's understand the major components of STL one by one to get a good grasp of the STL conceptually.

Algorithms

The STL algorithms are powered by C++ templates; hence, the same algorithm works irrespective of what data type it deals with or independently of how the data is organized by a container. Interestingly, the STL algorithms are generic enough to support built-in and user-defined data types using templates. As a matter of fact, the algorithms interact with the containers via iterators. Hence, what matters to the algorithms is the iterator supported by the container. Having said that, the performance of an algorithm depends on the underlying data structure used within a container. Hence, certain algorithms work only on selective containers, as each algorithm supported by the STL expects a certain type of iterator.

Iterators

An iterator is a design pattern, but interestingly, the STL work started much before
Gang of Four published their design patterns-related work to the software community. Iterators themselves are objects that allow traversing the containers to access, modify, and manipulate the data stored in the containers. Iterators do this so magically that we don't realize or need to know where and how the data is stored and retrieved.
The following image visually represents an iterator:
From the preceding image, you can understand that every iterator supports the begin() API, which returns the first element position, and the end() API returns one position past the last element in the container.
The STL broadly supports the following five types of iterators:
  • Input iterators
  • Output iterators
  • Forward iterators
  • Bidirectional iterators
  • Random-access iterators
The container implements the iterator to let us easily retrieve and manipulate the data, without delving much into the technical details of a container.
The following table explains each of the five iterators:
The type of iterator
Description
Input iterator
  • It is used to read from the pointed element
  • It is valid for single-time navigation, and once it reaches the end of the container, the iterator will be invalidated
  • It supports pre- and post-increment operators
  • It does not support decrement operators
  • It supports dereferencing
  • It supports the == and != operators to compare with the other iterators
  • The istream_iterator iterator is an input iterator
  • All the containers support this iterator
Output iterator
  • It is used to modify the pointed element
  • It is valid for single-time navigation, and once it reaches the end of the container, the iterator will be invalidated
  • It supports pre- and post-increment operators
  • It does not support decrement operators
  • It supports dereferencing
  • It doesn't support the == and != operators
  • The ostream_iterator, back_inserter, front_inserter iterators are examples of output iterators
  • All the containers support this iterator
Forward iterator
  • It supports the input iterator and out...

Table of contents

  1. Title Page
  2. Copyright
  3. Credits
  4. About the Author
  5. About the Reviewer
  6. www.PacktPub.com
  7. Customer Feedback
  8. Dedication
  9. Preface
  10. C++17 Features
  11. Standard Template Library
  12. Template Programming
  13. Smart Pointers
  14. Developing GUI Applications in C++
  15. Multithreaded Programming and Inter-Process Communication
  16. Test-Driven Development
  17. Behavior-Driven Development
  18. Debugging Techniques
  19. Code Smells and Clean Code Practices