O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Boost C++ Application Development Cookbook - Second Edition

Book Description

Learn to build applications faster and better by leveraging the real power of Boost and C++

About This Book

  • Learn to use the Boost libraries to simplify your application development
  • Learn to develop high quality, fast and portable applications
  • Learn the relations between Boost and C++11/C++4/C++17

Who This Book Is For

This book is for developers looking to improve their knowledge of Boost and who would like to simplify their application development processes. Prior C++ knowledge and basic knowledge of the standard library is assumed.

What You Will Learn

  • Get familiar with new data types for everyday use
  • Use smart pointers to manage resources
  • Get to grips with compile-time computations and assertions
  • Use Boost libraries for multithreading
  • Learn about parallel execution of different task
  • Perform common string-related tasks using Boost libraries
  • Split all the processes, computations, and interactions to tasks and process them independently
  • Learn the basics of working with graphs, stacktracing, testing and interprocess communications
  • Explore different helper macros used to detect compiler, platform and Boost features

In Detail

If you want to take advantage of the real power of Boost and C++ and avoid the confusion about which library to use in which situation, then this book is for you.

Beginning with the basics of Boost C++, you will move on to learn how the Boost libraries simplify application development. You will learn to convert data such as string to numbers, numbers to string, numbers to numbers and more. Managing resources will become a piece of cake. You’ll see what kind of work can be done at compile time and what Boost containers can do. You will learn everything for the development of high quality fast and portable applications. Write a program once and then you can use it on Linux, Windows, MacOS, Android operating systems. From manipulating images to graphs, directories, timers, files, networking – everyone will find an interesting topic.

Be sure that knowledge from this book won’t get outdated, as more and more Boost libraries become part of the C++ Standard.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Conventions 
    6. Reader feedback
    7. Customer support
      1. Downloading the example code 
      2. Errata
      3. Piracy
      4. Questions
  2. Starting to Write Your Application
    1. Introduction
    2. Getting configuration options
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Storing any value in a container/variable
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Storing multiple chosen types in a container/variable
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Using a safer way to work with a container that stores multiple chosen types
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Returning a value or flag where there is no value
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Returning an array from a function
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Combining multiple values into one
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    9. Binding and reordering function parameters
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    10. Getting a human-readable type name
      1. Getting ready
      2. How to do it
      3. How it works...
      4. There's more...
      5. See also
    11. Using the C++11 move emulation
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    12. Making a noncopyable class
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    13. Making a noncopyable but movable class
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    14. Using C++14 and C++11 algorithms
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  3. Managing Resources
    1. Introduction
    2. Managing local pointers to classes that do not leave scope
      1. Getting started
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Reference counting of pointers to classes used across functions
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Managing pointers to arrays that do not leave scope
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Reference counting of pointers to arrays used across functions
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Storing any functional objects in a variable
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Passing function pointer in a variable
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Passing C++11 lambda functions in a variable
      1. Getting ready
      2. How to do it...
      3. There's more...
      4. See also
    9. Containers of pointers
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    10. Do it at scope exit!
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    11. Initializing the base class by the member of the derived class
      1. Getting started
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  4. Converting and Casting
    1. Introduction
    2. Converting strings to numbers
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Converting numbers to strings
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Converting numbers to numbers
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Converting user-defined types to/from strings
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    6. Converting smart pointers
      1. Getting started
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Casting polymorphic objects
      1. Getting started
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Parsing simple input
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    9. Parsing complex input
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  5. Compile-Time Tricks
    1. Introduction
    2. Checking sizes at compile time
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Enabling function template usage for integral types
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Disabling function template usage for real types
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Creating a type from a number
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Implementing a type trait
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Selecting an optimal operator for a template parameter
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Getting a type of expression in C++03
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  6. Multithreading
    1. Introduction
    2. Creating a thread of execution
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Syncing access to a common resource
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Fast access to common resource using atomics
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Creating work_queue class
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Multiple-readers-single-writer lock
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Creating variables that are unique per thread
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Interrupting a thread
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    9. Manipulating a group of threads
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    10. Initializing a shared variable safely
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more..
      5. See also
    11. Locking multiple mutexes
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  7. Manipulating Tasks
    1. Introduction
      1. Before you start
    2. Registering a task for an arbitrary data type processing
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Making timers and processing timer events as tasks
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Network communication as a task
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Accepting incoming connections
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Executing different tasks in parallel
      1. Getting started
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Pipeline tasks processing
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Making a nonblocking barrier
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    9. Storing an exception and making a task from it
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    10. Getting and processing system signals as tasks
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There is more...
      5. See also
  8. Manipulating Strings
    1. Introduction
    2. Changing cases and case-insensitive comparison
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Matching strings using regular expressions
      1. Getting started
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Searching and replacing strings using regular expressions
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Formatting strings using safe printf-like functions
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Replacing and erasing strings
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Representing a string with two iterators
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Using a reference to string type
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  9. Metaprogramming
    1. Introduction
    2. Using type vector of types
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Manipulating a vector of types
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Getting a function's result type at compile time
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Making a higher-order metafunction
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Evaluating metafunctions lazily
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also...
    7. Converting all the tuple elements to strings
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Splitting tuples
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    9. Manipulating heterogeneous containers in C++14
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  10. Containers
    1. Introduction
    2. Storing a few elements in a sequence container
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Storing at most N elements in the sequence container
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Comparing strings in an ultra-fast manner
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Using an unordered set and map
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Making a map, where value is also a key
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Using multi-index containers
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Getting benefits of a single linked list and memory pool
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    9. Using flat associative containers
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  11. Gathering Platform and Compiler Information
    1. Introduction
    2. Detecting an OS and compiler
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Detecting int128 support
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Detecting and bypassing disabled RTTI
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Writing metafunctions using simpler methods
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Reducing code size and increasing performance of user-defined types (UDTs) in C++11
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. The portable way to export and import functions and classes
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Detecting the Boost version and getting latest features
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  12. Working with the System
    1. Introduction
    2. Listing files in a directory
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Erasing and creating files and directories
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Writing and using plugins
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Getting backtrace – current call sequence
      1. Getting started
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Passing data quickly from one process to another
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Syncing interprocess communications
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Using pointers in a shared memory
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    9. The fastest way to read files
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    10. Coroutines - saving the state and postponing the execution
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  13. Scratching the Tip of the Iceberg
    1. Introduction
    2. Working with graphs
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Visualizing graphs
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Using a true random number generator
      1. Getting started
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Using portable math functions
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    6. Writing test cases
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Combining multiple test cases in one test module
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Manipulating images
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also