Boost C++ Application Development Cookbook

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

With Boost libraries you can really unleash the power of C++. Learn to build applications faster and better through a cookbook approach that uses tons of recipes to make it all so easy to assimilate and apply. Overview - Explores how to write a program once and then use it on Linux, Windows, MacOS, and Android operating systems - Includes everyday use recipes for multithreading, networking, metaprogramming, and generic programming from a Boost library developer - Take advantage of the real power of Boost and C++, to get a good grounding in using it in any project In Detail Boost libraries are developed by professionals, tested on multiple platforms and processor architectures, and contain reliable solutions for a wide range of tasks. This Cookbook takes you on a journey of simplifying the process of application development and guides you through writing perfect applications fast. "Boost C++ Application Development Cookbook" provides you with a number of clear step-by-step recipes that will help you take advantage of the real power of Boost and C++, while giving you a good grounding in using it in any project. "Boost C++ Application Development Cookbook" looks at the Boost libraries, and breaks down the mystery and confusion about which library to use in which situation. It will take you through a number of clear, practical recipes that will help you to take advantage of the readily available solutions. Boost C++ Application Development Cookbook starts with teaching the basics of Boost libraries that are now mostly part of C++11 and leave no chance for memory leaks. Managing resources will become a piece of cake. We’ll see what kind of work can be done at compile time and what Boost containers can do. Do you think multithreading is a burden? Not with Boost. Think writing portable and fast servers is impossible? You’ll be surprised! Compilers and operating systems differ too much? Not with Boost. From manipulating images to graphs, directories, timers, files, strings – everyone will find an interesting topic. 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. What you will learn from this book Get familiar with new data types for everyday use Use 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 Explore different helper macros used to detect compiler, platform and Boost features Use selected C++11 features in C++03 Approach This book follows a cookbook approach, with detailed and practical recipes that use Boost libraries. Who this book is written for This book is great for developers new to Boost, and who are looking to improve their knowledge of Boost and see some undocumented details or tricks. It’s assumed that you will have some experience in C++ already, as well being familiar with the basics of STL. A few chapters will require some previous knowledge of multithreading and networking. You are expected to have at least one good C++ compiler and compiled version of Boost (1.53.0 or later is recommended), which will be used during the exercises within this book.

Author(s): Antony Polukhin
Publisher: Packt>
Year: 2017

Language: English
Pages: 747

Table of Contents

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