ebook img

Antony Polukhin - Boost C++ Application Development Cookbook PDF

348 Pages·2013·3.58 MB·English
by  
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Antony Polukhin - Boost C++ Application Development Cookbook

Boost C++ Application Development Cookbook Over 80 practical, task-based recipes to create applications using Boost libraries Antony Polukhin BIRMINGHAM - MUMBAI Boost C++ Application Development Cookbook Copyright © 2013 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: August 2013 Production Reference: 1210813 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-84951-488-0 www.packtpub.com Cover Image by Suresh Mogre ([email protected]) Credits Author Project Coordinator Antony Polukhin Anugya Khurana Reviewers Proofreader Béla Tibor Bartha Stephen Silk Paul A. Bristow Indexer Acquisition Editor Monica Ajmera Mehta Akram Hussain Graphics Lead Technical Editor Abhinash Sahu Arun Nadar Ronak Druv Technical Editors Production Coordinator Sampreshita Maheshwari Conidon Miranda Vivek Pillai Cover Work Hardik B. Soni Conidon Miranda Copy Editors Adithi Shetty Laxmi Subramanian Gladson Monterio Brandt D'Mello Sayanee Mukherjee Alfida Paiva Aditya Nair About the Author 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. I would like to thank my family, especially my wife, Irina Polukhina, for drawing sketches of pictures and diagrams all through the book. Great thanks to Paul Anthony Bristow for reviewing this book and getting through the insane number of commas that I used in the first drafts. I would also like to thank all of the people from the Boost community for writing those great libraries and for opening an amazing word of C++ for me. About the Reviewers Béla Tibor Bartha is a professional software engineer working on various technologies and languages. Although in the last four years he's been working on iOS and OS X applications, C++ is his old passion along with game development as personal projects. Paul A. Bristow is a long-time member of the Boost community (and contributor to Boost. Math) who has watched with amusement and amazement at how C++ has been made to do so many wonderful things that it was never designed to do (many of which are nicely demonstrated in this book). www.PacktPub.com Support files, eBooks, discount offers and more You might want to visit www.PacktPub.com for support files and downloads related to your book. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. TM http://PacktLib.PacktPub.com Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books. Why Subscribe? f Fully searchable across every book published by Packt f Copy and paste, print and bookmark content f On demand and accessible via web browser Free Access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access. Table of Contents Preface 1 Chapter 1: Starting to Write Your Application 7 Introduction 7 Getting configuration options 8 Storing any value in a container/variable 13 Storing multiple chosen types in a variable/container 16 Using a safer way to work with a container that stores multiple chosen types 18 Returning a value or flag where there is no value 22 Returning an array from a function 25 Combining multiple values into one 28 Reordering the parameters of function 30 Binding a value as a function parameter 34 Using the C++11 move emulation 37 Making a noncopyable class 40 Making a noncopyable but movable class 42 Chapter 2: Converting Data 47 Introduction 47 Converting strings to numbers 48 Converting numbers to strings 51 Converting numbers to numbers 53 Converting user-defined types to/from strings 56 Casting polymorphic objects 59 Parsing simple input 61 Parsing input 66 Chapter 3: Managing Resources 71 Introduction 71 Managing pointers to classes that do not leave scope 72 Table of Contents Reference counting of pointers to classes used across methods 74 Managing pointers to arrays that do not leave scope 77 Reference counting pointers to arrays used across methods 79 Storing any functional objects in a variable 82 Passing a function pointer in a variable 85 Passing C++11 lambda functions in a variable 86 Containers of pointers 88 Doing something at scope exit 91 Initializing the base class by a member of the derived class 93 Chapter 4: Compile-time Tricks 97 Introduction 97 Checking sizes at compile time 98 Enabling the usage of templated functions for integral types 102 Disabling templated functions' usage for real types 106 Creating a type from number 108 Implementing a type trait 111 Selecting an optimal operator for a template parameter 113 Getting a type of expression in C++03 116 Chapter 5: Multithreading 121 Introduction 121 Creating an execution thread 122 Syncing access to a common resource 126 Fast access to common resource using atomics 131 Creating a work_queue class 134 Multiple-readers-single-writer lock 138 Creating variables that are unique per thread 141 Interrupting a thread 144 Manipulating a group of threads 146 Chapter 6: Manipulating Tasks 149 Introduction 149 Registering a task for processing an arbitrary datatype 150 Making timers and processing timer events as tasks 154 Network communication as a task 157 Accepting incoming connections 164 Executing different tasks in parallel 169 Conveyor tasks processing 171 Making a nonblocking barrier 176 Storing an exception and making a task from it 181 Getting and processing system signals as tasks 185 ii Table of Contents Chapter 7: Manipulating Strings 189 Introduction 189 Changing cases and case-insensitive comparison 189 Matching strings using regular expressions 192 Searching and replacing strings using regular expressions 196 Formatting strings using safe printf-like functions 199 Replacing and erasing strings 201 Representing a string with two iterators 203 Using a reference to string type 206 Chapter 8: Metaprogramming 211 Introduction 211 Using type "vector of types" 212 Manipulating a vector of types 217 Getting a function's result type at compile time 222 Making a higher-order metafunction 225 Evaluating metafunctions lazily 227 Converting all the tuple elements to strings 230 Splitting tuples 234 Chapter 9: Containers 239 Introduction 239 Comparing strings in an ultra-fast manner 240 Using an unordered set and map 244 Making a map, where value is also a key 248 Using multi-index containers 252 Getting the benefits of single-linked list and memory pool 258 Using flat associative containers 263 Chapter 10: Gathering Platform and Compiler Information 267 Introduction 267 Detecting int128 support 268 Detecting RTTI support 270 Speeding up compilation using C++11 extern templates 272 Writing metafunctions using simpler methods 274 Reducing code size and increasing performance of user-defined types (UDTs) in C++11 276 The portable way to export and import functions and classes 279 Detecting the Boost version and getting latest features 282 Chapter 11: Working with the System 285 Introduction 285 Listing files in a directory 286 iii

Description:
Antony_Polukhin_-_Boost_C++_Application_Development_Cookbook.pdf
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.