You are previewing Boost C++ Application Development Cookbook.
O'Reilly logo
Boost C++ Application Development Cookbook

Book Description

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.

  • 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.

    Table of Contents

    1. Boost C++ Application Development Cookbook
      1. Table of Contents
      2. Boost C++ Application Development Cookbook
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. 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 variable/container
          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. Reordering the parameters of function
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        10. Binding a value as a function parameter
          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
      9. 2. Converting Data
        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. Casting polymorphic objects
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. Parsing simple input
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        8. Parsing input
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      10. 3. Managing Resources
        1. Introduction
        2. Managing pointers to classes that do not leave scope
          1. Getting ready
          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 methods
          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 pointers to arrays used across methods
          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 a 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. Doing something 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 a member of the derived class
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      11. 4. 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 the usage of templated functions for integral types
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Disabling templated functions' 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 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
      12. 5. Multithreading
        1. Introduction
        2. Creating an execution thread
          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 a 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. How to do it...
          2. How it works...
          3. There's more...
          4. 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
      13. 6. Manipulating Tasks
        1. Introduction
          1. Before you start
        2. Registering a task for processing an arbitrary datatype
          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 ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. Conveyor 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's more...
          5. See also
      14. 7. 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 ready
          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
      15. 8. 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
      16. 9. Containers
        1. Introduction
        2. 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
        3. 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
        4. 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
        5. Using multi-index containers
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Getting the benefits of 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
        7. Using flat associative containers
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      17. 10. Gathering Platform and Compiler Information
        1. Introduction
        2. Detecting int128 support
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Detecting RTTI support
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Speeding up compilation using C++11 extern templates
          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
      18. 11. 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. 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
        5. Syncing interprocess communications
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Using pointers in shared memory
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. 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
        8. 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
      19. 12. 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 ready
          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
      20. Index