Modern C++: Efficient and Scalable Application Development

Book description

Create apps in C++ and leverage its latest features using modern programming techniques.

Key Features

  • Develop strong C++ skills to build a variety of applications
  • Explore features of C++17, such as containers, algorithms, and threads
  • Grasp the standard support for threading and concurrency and use them in basic daily tasks

Book Description

C++ is one of the most widely used programming languages. It is fast, flexible, and used to solve many programming problems.

This Learning Path gives you an in-depth and hands-on experience of working with C++, using the latest recipes and understanding most recent developments. You will explore C++ programming constructs by learning about language structures, functions, and classes, which will help you identify the execution flow through code. You will also understand the importance of the C++ standard library as well as memory allocation for writing better and faster programs.

Modern C++: Efficient and Scalable Application Development deals with the challenges faced with advanced C++ programming. You will work through advanced topics such as multithreading, networking, concurrency, lambda expressions, and many more recipes.

By the end of this Learning Path, you will have all the skills to become a master C++ programmer.

This Learning Path includes content from the following Packt products:

  • Beginning C++ Programming by Richard Grimes
  • Modern C++ Programming Cookbook by Marius Bancila
  • The Modern C++ Challenge by Marius Bancila

What you will learn

  • Become familiar with the structure of C++ projects
  • Identify the main structures in the language: functions and classes
  • Learn to debug your programs
  • Leverage C++ features to obtain increased robustness and performance
  • Explore functions and callable objects with a focus on modern features
  • Serialize and deserialize JSON and XML data
  • Create client-server applications that communicate over TCP/IP
  • Use design patterns to solve real-world problems

Who this book is for

This Learning Path is designed for developers who want to gain a solid foundation in C++. The desire to learn how to code in C++ is all you need to get started with this Learning Path

Table of contents

  1. Title Page
  2. Copyright
    1. Modern C++: Efficient and Scalable Application Development
  3. About Packt
    1. Why Subscribe?
    2. Packt.com
  4. Contributors
    1. About the Authors
    2. About the Reviewers
    3. Packt Is Searching for Authors Like You
  5. Preface
    1. Who This Book Is For
    2. What This Book Covers
    3. To Get the Most out of This Book
      1. How to generate projects for Visual Studio 2017
      2. Download the Example Code Files
      3. Download the color images
      4. Conventions Used
    4. Get in Touch
      1. Reviews
  6. Understanding Language Features
    1. Writing C++
      1. Using whitespace
      2. Formatting Code
      3. Writing Statements
        1. Working with Expressions
        2. Using the Comma Operator
      4. Using Types and Variables
      5. Using constants and literals
        1. Defining constants
        2. Using Constant Expressions
        3. Using Enumerations
        4. Declaring Pointers
      6. Using Namespaces
      7. C++ Scoping of Variables
    2. Using Operators
      1. Exploring the Built-in Operators
        1. Arithmetic Operators
        2. Increment and Decrement Operators
        3. Bitwise Operators
        4. Boolean Operators
        5. Bitwise Shift Operators
        6. Assignment Operators
    3. Controlling Execution Flow
      1. Using Conditional Statements
      2. Selecting
      3. Looping
        1. Looping with Iteration
        2. Conditional Loops
      4. Jumping
    4. Using C++ language features
    5. Summary
  7. Working with Memory, Arrays, and Pointers
    1. Using memory in C++
      1. Using C++ pointer syntax
      2. Using Null Pointers
      3. Types of Memory
      4. Pointer Arithmetic
    2. Using Arrays
      1. Function parameters
      2. Multidimensional Arrays
      3. Passing Multidimensional Arrays to Functions
      4. Using arrays of characters
        1. Comparing strings
        2. Preventing Buffer Overruns
    3. Using Pointers in C++
      1. Accessing out of Bounds
      2. Pointers to Deallocated Memory
      3. Converting Pointers
        1. Constant Pointers
        2. Changing the Type Pointed To
    4. Allocating memory in code
      1. Allocating individual objects
      2. Allocating Arrays of Objects
      3. Handling failed allocations
      4. Using Other Versions of the New Operator
      5. Memory lifetime
      6. The Windows SDK and Pointers
    5. Memory and the C++ Standard Library
      1. Standard Library arrays
        1. Using the stack-based array class
        2. Using the Dynamically Allocated Vector Class
    6. References
      1. Constant References
      2. Returning References
      3. Temporaries and References
      4. The rvalue References
      5. Ranged for and References
    7. Using Pointers in Practice
      1. Creating the Project
      2. Adding a Task Object to the List
      3. Deleting the task list
      4. Iterating the task list
      5. Inserting Items
    8. Summary
  8. Using Functions
    1. Defining C++ functions
      1. Declaring and defining functions
      2. Specifying linkage
      3. Inlining
      4. Determining the return type
      5. Naming the function
      6. Function parameters
      7. Specifying exceptions
      8. Function body
    2. Using function parameters
      1. Passing Initializer lists
      2. Using default parameters
      3. Variable number of parameters
        1. Initializer lists
        2. Argument lists
    3. Function features
      1. Call stack
      2. Specifying calling conventions
        1. Using C linkage
        2. Specifying how the stack Is maintained
      3. Using recursion
      4. Overloading functions
      5. Functions and scope
      6. Deleted functions
      7. Passing by value and passing by reference
    4. Designing functions
      1. Pre- and post-conditions
      2. Using invariants
    5. Function pointers
      1. Remember the parentheses!
      2. Declaring function pointers
      3. Using function pointers
    6. Templated functions
      1. Defining templates
      2. Using template parameter values
      3. Specialized templates
      4. Variadic templates
    7. Overloaded operators
      1. Function objects
      2. Introducing lambda expressions
    8. Using functions in C++
    9. Summary
  9. Classes
    1. Writing classes
      1. Reviewing structures
      2. Defining classes
      3. Defining class behavior
        1. Using the this pointer
        2. Using the scope resolution operator
        3. Defining class state
      4. Creating objects
        1. Construction of objects
        2. Defining constructors
        3. Delegating constructors
        4. Copy constructor
        5. Converting between types
        6. Making friends
        7. Marking constructors as explicit
        8. Destructing objects
        9. Assigning objects
        10. Move semantics
      5. Declaring static members
        1. Defining static members
        2. Using static and global objects
        3. Named constructors
      6. Nested classes
      7. Accessing const objects
    2. Using objects with pointers
      1. Getting pointers to object members
      2. Operator overloading
      3. Defining function classes
      4. Defining conversion operators
      5. Managing resources
      6. Writing wrapper classes
      7. Using smart pointers
        1. Managing exclusive ownership
        2. Sharing ownership
        3. Handling dangling pointers
    3. Templates
    4. Using classes
    5. Summary
  10. Using the Standard Library Containers
    1. Working with pairs and tuples
    2. Containers
      1. Sequence containers
        1. List
        2. Forward list
        3. Vector
        4. Deque
      2. Associative containers
        1. Maps and multimaps
        2. Sets and multisets
        3. Unordered containers
      3. Special purpose containers
      4. Using iterators
        1. Input and output iterators
        2. Stream iterators
        3. Using iterators with the C Standard Library
    3. Algorithms
      1. Iteration of items
      2. Getting information
      3. Comparing containers
      4. Changing Items
      5. Finding Items
      6. Sorting items
    4. Using the numeric libraries
      1. Compile time arithmetic
      2. Complex numbers
    5. Using the Standard Library
    6. Summary
  11. Using Strings
    1. Using the string class as a container
      1. Getting information about a string
      2. Altering strings
      3. Searching strings
    2. Internationalization
      1. Using facets
    3. Strings and numbers
      1. Converting strings to numbers
      2. Converting numbers to strings
    4. Using stream classes
      1. Outputting floating point numbers
      2. Outputting integers
      3. Outputting time and money
      4. Converting numbers to strings using streams
      5. Reading numbers from strings using streams
    5. Using regular expressions
      1. Defining regular expressions
      2. Standard Library classes
        1. Matching expressions
        2. Using iterators
        3. Replacing strings
    6. Using strings
      1. Creating the project
      2. Processing header subitems
    7. Summary
  12. Diagnostics and Debugging
    1. Preparing your code
      1. Invariants and conditions
      2. Conditional compilation
      3. Using pragmas
      4. Adding informational messages
      5. Compiler switches for debugging
      6. Pre-processor symbols
      7. Producing diagnostic messages
        1. Trace messages with the C runtime
        2. Tracing messages with Windows
      8. Using asserts
    2. Application termination
    3. Error values
      1. Obtaining message descriptions
      2. Using the Message Compiler
    4. C++ exceptions
      1. Exception specifications
      2. C++ exception syntax
      3. Standard exception classes
      4. Catching exceptions by type
      5. Function try blocks
      6. System errors
      7. Nested exceptions
      8. Structured Exception Handling
      9. Compiler exception switches
      10. Mixing C++ and SEH exception handling
      11. Writing exception-safe classes
    5. Summary
  13. Learning Modern Core Language Features
    1. Using auto whenever possible
      1. How to do it...
      2. How it works...
      3. See also
    2. Creating type aliases and alias templates
      1. How to do it...
      2. How it works...
    3. Understanding uniform initialization
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more
      5. See also
    4. Understanding the various forms of non-static member initialization
      1. How to do it...
      2. How it works...
    5. Controlling and querying object alignment
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Using scoped enumerations
      1. How to do it...
      2. How it works...
    7. Using override and final for virtual methods
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Using range-based for loops to iterate on a range
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    9. Enabling range-based for loops for custom types
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    10. Using explicit constructors and conversion operators to avoid implicit conversion
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    11. Using unnamed namespaces instead of static globals
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    12. Using inline namespaces for symbol versioning
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    13. Using structured bindings to handle multi-return values
      1. Getting ready
      2. How to do it...
      3. How it works...
  14. Working with Numbers and Strings
    1. Converting between numeric and string types
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    2. Limits and other properties of numeric types
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Generating pseudo-random numbers
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Initializing all bits of internal state of a pseudo-random number generator
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Creating cooked user-defined literals
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Creating raw user-defined literals
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    7. Using raw string literals to avoid escaping characters
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Creating a library of string helpers
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    9. Verifying the format of a string using regular expressions
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    10. Parsing the content of a string using regular expressions
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    11. Replacing the content of a string using regular expressions
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    12. Using string_view instead of constant string references
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  15. Exploring Functions
    1. Defaulted and deleted functions
      1. Getting started
      2. How to do it...
      3. How it works...
    2. Using lambdas with standard algorithms
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Using generic lambdas
      1. Getting started
      2. How to do it...
      3. How it works...
      4. See also
    4. Writing a recursive lambda
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Writing a function template with a variable number of arguments
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Using fold expressions to simplify variadic function templates
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Implementing higher-order functions map and fold
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Composing functions into a higher-order function
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    9. Uniformly invoking anything callable
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  16. Standard Library Containers, Algorithms, and Iterators
    1. Using vector as a default container
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There’s more...
      5. See also
    2. Using bitset for fixed-size sequences of bits
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Using vector<bool> for variable-size sequences of bits
      1. Getting ready...
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Finding elements in a range
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Sorting a range
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Initializing a range
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    7. Using set operations on a range
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Using iterators to insert new elements in a container
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    9. Writing your own random access iterator
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    10. Container access with non-member functions
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  17. Math Problems
    1. Problems
      1. 1. Sum of naturals divisible by 3 and 5
      2. 2. Greatest common divisor
      3. 3. Least common multiple
      4. 4. Largest prime smaller than given number
      5. 5. Sexy prime pairs
      6. 6. Abundant numbers
      7. 7. Amicable numbers
      8. 8. Armstrong numbers
      9. 9. Prime factors of a number
      10. 10. Gray code
      11. 11. Converting numerical values to Roman
      12. 12. Largest Collatz sequence
      13. 13. Computing the value of Pi
      14. 14. Validating ISBNs
    2. Solutions
      1. 1. Sum of naturals divisible by 3 and 5
      2. 2. Greatest common divisor
      3. 3. Least common multiple
      4. 4. Largest prime smaller than given number
      5. 5. Sexy prime pairs
      6. 6. Abundant numbers
      7. 7. Amicable numbers
      8. 8. Armstrong numbers
      9. 9. Prime factors of a number
      10. 10. Gray code
      11. 11. Converting numerical values to Roman
      12. 12. Largest Collatz sequence
      13. 13. Computing the value of Pi
      14. 14. Validating ISBNs
  18. Language Features
    1. Problems
      1. 15. IPv4 data type
      2. 16. Enumerating IPv4 addresses in a range
      3. 17. Creating a 2D array with basic operations
      4. 18. Minimum function with any number of arguments
      5. 19. Adding a range of values to a container
      6. 20. Container any, all, none
      7. 21. System handle wrapper
      8. 22. Literals of various temperature scales
    2. Solutions
      1. 15. IPv4 data type
      2. 16. Enumerating IPv4 addresses in a range
      3. 17. Creating a 2D array with basic operations
      4. 18. Minimum function with any number of arguments
      5. 19. Adding a range of values to a container
      6. 20. Container any, all, none
      7. 21. System handle wrapper
      8. 22. Literals of various temperature scales
  19. Strings and Regular Expressions
    1. Problems
      1. 23. Binary to string conversion
      2. 24. String to binary conversion
      3. 25. Capitalizing an article title
      4. 26. Joining strings together separated by a delimiter
      5. 27. Splitting a string into tokens with a list of possible delimiters
      6. 28. Longest palindromic substring
      7. 29. License plate validation
      8. 30. Extracting URL parts
      9. 31. Transforming dates in strings
    2. Solutions
      1. 23. Binary to string conversion
      2. 24. String to binary conversion
      3. 25. Capitalizing an article title
      4. 26. Joining strings together separated by a delimiter
      5. 27. Splitting a string into tokens with a list of possible delimiters
      6. 28. Longest palindromic substring
      7. 29. License plate validation
      8. 30. Extracting URL parts
      9. 31. Transforming dates in strings
  20. Streams and Filesystems
    1. Problems
      1. 32. Pascal's triangle
      2. 33. Tabular printing of a list of processes
      3. 34. Removing empty lines from a text file
      4. 35. Computing the size of a directory
      5. 36. Deleting files older than a given date
      6. 37. Finding files in a directory that match a regular expression
      7. 38. Temporary log files
    2. Solutions
      1. 32. Pascal's triangle
      2. 33. Tabular printing of a list of processes
      3. 34. Removing empty lines from a text file
      4. 35. Computing the size of a directory
      5. 36. Deleting files older than a given date
      6. 37. Finding files in a directory that match a regular expression
      7. 38. Temporary log files
  21. Date and Time
    1. Problems
      1. 39. Measuring function execution time
      2. 40. Number of days between two dates
      3. 41. Day of the week
      4. 42. Day and week of the year
      5. 43. Meeting time for multiple time zones
      6. 44. Monthly calendar
    2. Solutions
      1. 39. Measuring function execution time
      2. 40. Number of days between two dates
      3. 41. Day of the week
      4. 42. Day and week of the year
      5. 43. Meeting time for multiple time zones
      6. 44. Monthly calendar
  22. Algorithms and Data Structures
    1. Problems
      1. 45. Priority queue
      2. 46. Circular buffer
      3. 47. Double buffer
      4. 48. The most frequent element in a range
      5. 49. Text histogram
      6. 50. Filtering a list of phone numbers
      7. 51. Transforming a list of phone numbers
      8. 52. Generating all the permutations of a string
      9. 53. Average rating of movies
      10. 54. Pairwise algorithm
      11. 55. Zip algorithm
      12. 56. Select algorithm
      13. 57. Sort algorithm
      14. 58. The shortest path between nodes
      15. 59. The Weasel program
      16. 60. The Game of Life
    2. Solutions
      1. 45. Priority queue
      2. 46. Circular buffer
      3. 47. Double buffer
      4. 48. The most frequent element in a range
      5. 49. Text histogram
      6. 50. Filtering a list of phone numbers
      7. 51. Transforming a list of phone numbers
      8. 52. Generating all the permutations of a string
      9. 53. Average rating of movies
      10. 54. Pairwise algorithm
      11. 55. Zip algorithm
      12. 56. Select algorithm
      13. 57. Sort algorithm
      14. 58. The shortest path between nodes
      15. 59. The Weasel program
      16. 60. The Game of Life
  23. Other Books You May Enjoy
    1. Leave a Review - Let Other Readers Know What You Think

Product information

  • Title: Modern C++: Efficient and Scalable Application Development
  • Author(s): Richard Grimes, Marius Bancila
  • Release date: December 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781789951738