Boost C++ Application Development Cookbook


Boost C++ Application Development Cookbook
eBook: $29.99
Formats: PDF, PacktLib, ePub and Mobi formats
$25.49
save 15%!
Print + free eBook + free PacktLib access to the book: $79.98    Print cover: $49.99
$49.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Reviews
Support
Sample Chapters
  • 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

Book Details

Language : English
Paperback : 348 pages [ 235mm x 191mm ]
Release Date : August 2013
ISBN : 1849514887
ISBN 13 : 9781849514880
Author(s) : Antony Polukhin
Topics and Technologies : All Books, Application Development, Cookbooks, Open Source

Table of Contents

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

                          Antony Polukhin

                          Antony Polukhin was born in Russia. As a child, he could speak the Russian and Hungarian languages and learned English at school. Since his school days, he was participating in different mathematics, physics, and chemistry competitions and winning them. He was accepted into University twice: once for taking part in a city mathematics competition and again for gaining high score in an internal Universities mathematics and physics challenge. In his university life, there was not a year when he did not participate in an exam: he gained 'A's in all disciplines by writing highly difficult programs for each teacher. He met his future wife in university and graduated with honors. For more than three years, he worked in a VoIP company developing business logic for a commercial alternative to Asterisc. During those days he started contributing to Boost and became a maintainer of the Boost.LexicalCast library. He also started making translations to Russian for Ubuntu Linux at that time. Today, he develops a query engine for graph-oriented databases and continues to contribute to the open source. You may find his code in Boost libraries such as Any, LexicalCast, TypeTraits, Variant, and others. He has been happily married for a year now.

                          Code Downloads

                          Download the code and support files for this book.


                          Submit Errata

                          Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


                          Errata

                          - 17 submitted: last submission 03 Feb 2014

                          Errata type: TYPO | Page number: 8

                          $ our_program -apples=10 -oranges=20
                          should be 
                          $ our_program --apples=10 --oranges=20 

                          Errata type: TYPO | Page number: 11

                          // Adding missing options from "aples_oranges.cfg"
                          should be
                          // Adding missing options from "apples_oranges.cfg"

                          Errata type: TYPO | Page number: 34

                          "Count values greater than or equal to 5 as shown in the following code"
                          should be replaced by
                          "Count values greater than 5 as shown in the following code" 

                          Errata type: TYPO | Page number: 84

                          // 'fo' leavs scope and will be destroyed,
                          // but 'f' will be usable eve inouter scope

                          should be 

                          // 'fo' leaves scope and will be destroyed,
                          // but 'f' will be usable even in outer scope

                          Errata type: TYPO | Page number: 63

                          ...
                          ushort_[ ref(res.year) = 1 ] >> char('-')
                          >> ushort_[ ref(res.month) = 1 ] >> char('-')
                          ...

                          should be

                          ...
                          ushort_[ ref(res.year) = _1 ] >> char('-')
                          >> ushort_[ ref(res.month) = _1 ] >> char('-')
                          ... 

                          Errata type: TYPO | Page number: 99

                          "In case of serialization() function"

                          should be

                          "In case of serialize() function"

                          Errata type: TYPO | Page number: 89

                          "The std::auto_ptr method is deprecated"

                          should be

                          "The std::auto_ptr class is deprecated"

                          Errata type: CODE | Page number: 206

                          "std::string::const_iterator pos_end
                          = std::find(input.begin(), input.end(), ends);"

                          should be

                          "std::string::const_iterator pos_end
                          = std::find(pos_beg, input.end(), ends);" 

                          Errata type: CODE | page number: 208

                          "boost::string_ref::const_iterator pos_end
                          = std::find(input.cbegin(), input.cend(), ends);"
                          should be
                          "boost::string_ref::const_iterator pos_end
                          = std::find(pos_beg, input.cend(), ends);" 

                          Errata type: TYPO | page number: 256

                          "std::unordered_mutiset"
                          should be
                          "std::unordered_multiset"

                           

                          Errata type: CODE | page number: 257

                          "The boost::multi_index::hashed_non_unique type means that the index will
                          work like std::set"
                          should be
                          "The boost::multi_index::hashed_non_unique type means that the index will
                          work like std::unordered_multiset"

                          Errata type: CODE | page number: 273

                          "The BOOST_NO_CXX11_EXTERN_TEMPLATES macro is defined when the compiler has
                          support of C++11 extern templates."
                          should be
                          "The BOOST_NO_CXX11_EXTERN_TEMPLATES macro is defined when the compiler has
                          no support of C++11 extern templates."

                          Errata type: CODE | page number: 275

                          "The BOOST_NO_CXX11_CONSTEXPR macro is defined when C++11 constexpr is
                          available."

                          should be

                          "The BOOST_NO_CXX11_CONSTEXPR macro is defined when C++11 constexpr is not
                          available."

                          Errata type: CODE | page number: 275

                          "The BOOST_NO_CXX11_HDR_ARRAY macro is defined when the C++11 std::array
                          class and the <array> header are available."

                          should be

                          "The BOOST_NO_CXX11_HDR_ARRAY macro is defined when the C++11 std::array
                          class and the <array> header are not available."

                          Errata type: CODE | page number: 310

                          "Steps 2 and 3 are trivial, but at step 4"

                          should be

                          "Step 2 is trivial, but at step 3"

                          Errata type: CODE | page number: 110

                          "signatures like process_impl(T, boost::mpl::int_<8>)"
                          should be
                          "signatures like process_impl(T, boost::mpl::int_<4>)"

                          Errata type: CODE | page number: 107
                          "typename boost::disable_if_c<boost::has_plus_assign<T>::value."
                          should be
                          "typename boost::disable_if_c<boost::has_plus_assign<T>::value,T>::type."

                          Sample chapters

                          You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

                          Frequently bought together

                          Boost C++ Application Development Cookbook +    OpenCL Parallel Programming Development Cookbook =
                          50% Off
                          the second eBook
                          Price for both: $28.04

                          Buy both these recommended eBooks together and get 50% off the cheapest eBook.

                          What you will learn from this book

                          • 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
                          • Explore different helper macros used to detect compiler, platform and Boost features
                          • Use selected C++11 features in C++03

                          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.

                          Approach

                          This book follows a cookbook approach, with detailed and practical recipes that use Boost libraries.

                          Who this book is 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.

                          Code Download and Errata
                          Packt Anytime, Anywhere
                          Register Books
                          Print Upgrades
                          eBook Downloads
                          Video Support
                          Contact Us
                          Awards Voting Nominations Previous Winners
                          Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
                          Resources
                          Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software