售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Learning Boost C++ Libraries
Table of Contents
Learning Boost C++ Libraries
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Introducing Boost
How it all started
What is Boost?
Getting started with Boost libraries
Necessary software
Linux toolchain
Windows toolchain
Obtaining and building Boost libraries
Planning your Boost sandbox
Library naming conventions
Library name components
Library name layouts
Versioned layout
System layout
Tagged layout
Installing a Boost binary distribution
Installing on Windows
Installing on Linux
Building and installing the Boost libraries from source
Optional packages
Building the Boost libraries on Linux
Building the Boost libraries on Windows
Using Boost libraries in your projects
Linking against Boost libraries on Linux
Linking against Boost libraries on Windows
Building the code listings in this book
CMake
Code examples
Self-test questions
Summary
2. The First Brush with Boost's Utilities
Simple data structures
Boost.Optional
Accessing values stored in boost::optional
get_value_or
Boost.Optional versus pointers
Boost.Tuple
Creating tuples
Accessing tuple elements
Comparing tuples
Writing generic code using tuples
Working with heterogeneous values
Boost.Variant
Accessing values in a variant
Compile-time visitation
Generic visitors
Applying visitors to variants in a container
Defining recursive variants
The JSON format
Representing JSON content with recursive variants
Visiting recursive variants
Boost.Any
Boost.Conversion
lexical_cast
Handling command-line arguments
Designing command-line options
The diff command – a case study
Using Boost.Program_Options
Parsing positional parameters
Multiple option values
Other utilities and compile-time checks
BOOST_CURRENT_FUNCTION
Boost.Swap
Compile-time asserts
Diagnostics using preprocessor macros
Self-test questions
Summary
References
3. Memory Management and Exception Safety
Dynamic memory allocation and exception safety
Exception safety and RAII
Smart pointers
Unique ownership semantics
boost::scoped_ptr
Uses of scoped_ptr
Creating exception-safe scopes
Transferring object ownership across functions
As a class member
boost::scoped_array
std::unique_ptr
Ownership transfer using unique_ptr
Wrapping arrays in unique_ptr
make_unique in C++14
Shared ownership semantics
boost::shared_ptr and std::shared_ptr
Uses of shared_ptr
As a class member
Storing dynamically-allocated objects in Standard Library containers
Nonowning aliases – boost::weak_ptr and std::weak_ptr
A shared_ptr critique – make_shared and enable_shared_from_this
Intrusive smart pointers – boost::intrusive_ptr
Using intrusive_ptr
shared_array
Managing non-memory resources using smart pointers
Self-test questions
Summary
References
4. Working with Strings
Text processing with Boost String Algorithms library
Using Boost String Algorithms
Find algorithms
find_first
find_all
find_token
iter_find
find
find_head and find_tail
Other algorithms for testing string properties
Case-conversion and trimming algorithms
Case-conversion algorithms
Trimming algorithms
The replace and erase algorithms
The split and join algorithms
Splitting text using the Boost Tokenizer library
Tokenizing based on separators
Tokenizing records with fields containing metacharacters
Tokenizing records with fixed-length fields
Writing your own tokenizer functions
Regular expressions using Boost.Regex
Regular expression syntax
Atoms
Quantifiers
Character classes
Anchors
Sub-expressions
Disjunctions
Using Boost.Regex to parse regular expressions
Matching text
Searching text
Tokenizing text using regex
Replacing text
Self-test questions
Summary
5. Effective Data Structures beyond STL
Boost Container library
Move-awareness and in-place construction
Nonstandard containers
Flat associative containers
slist
Splicing
stable_vector
static_vector
Fast lookups using Boost Unordered containers
Containers for dynamically-allocated objects
Ownership semantics of pointer containers
Null pointers in pointer containers
Expressive initialization and assignment using Boost.Assign
Assigning lists of values to containers
Initializing containers with lists of values
Initializing pointer containers and assigning values
Iteration patterns using Boost.Iterator
Smart iteration using Boost.Iterator
Filter Iterator
Transform Iterator
Function Output Iterator
Creating conforming iterators for custom classes
Self-test questions
Summary
References
6. Bimap and Multi-index Containers
Containers for multi-criteria lookups
Boost Multi-index containers
Index types
Range lookups using lambda
Insertions and updates
Boost Bimap
Collection types
More ways to use bimaps
Tagged access
Projections
Self-test questions
Summary
References
7. Higher Order and Compile-time Programming
Higher order programming with Boost
Function objects
Lambdas – unnamed function literals
Lambda captures
Delegates and closures
Partial function application
Compile-time programming with Boost
Basic compile-time control flow using templates
Branching
Recursion
Boost Type Traits
SFINAE and enable_if / disable_if
The Boost Metaprogramming Library (MPL)
Metafunctions
Using MPL metafunctions
Domain Specific Embedded Languages
Lazy evaluation
Expression templates
Boost Phoenix
Boost Spirit Parser Framework
Using Spirit Qi
Predefined parsers
The parsing API
Parser operators and expressions
Parsing directives
Semantic actions
Rules
Parsing timestamps
Self-test questions
Summary
References
8. Date and Time Libraries
Date and time calculations with Boost Date Time
Dates from the Gregorian calendar
Creating date objects
Handling date durations
Date periods
Posix time
Constructing time points and durations
Resolution
Time periods
Time iterator
Using Chrono to measure time
Durations
Duration arithmetic
Clocks and time points
Measuring program performance using Boost Timer
cpu_timer
auto_cpu_timer
Self-test questions
Summary
References
9. Files, Directories, and IOStreams
Managing files and directories with Boost Filesystem
Manipulating paths
Printing paths
Constructing paths
Breaking paths into components
Traversing directories
Querying filesystem entries
Performing operations on files
Creating directories
Creating symbolic links
Copying files
Moving and deleting files
Path-aware fstreams
Extensible I/O with Boost IOStreams
Architecture of Boost IOStreams
Using devices
Devices for file I/O
Devices for reading and writing to memory
Using filters
Basic filters
Filters for compression and decompression
Composing filters
Pipelining
Branching data streams with tee
Self-test questions
Summary
10. Concurrency with Boost
Creating concurrent tasks with Boost Thread
Using Boost Threads
Moving threads and waiting on threads
Thread IDs
Cores and threads
Managing shared data
Creating and coordinating concurrent tasks
boost::future and boost::promise
Waiting for future
Throwing exceptions across threads
shared_future
std::future and std::promise
std::packaged_task and std::async
std::packaged_task
std::async
Launch policy
Lock-based thread synchronization methods
Data races and atomic operations
Mutual exclusion and critical sections
boost::lock_guard
boost::unique_lock
Deadlocks
Synchronizing on conditions
Condition variables and producer-consumer problem
Condition variable nuances
The Readers-Writers problem
Upgradable locks
Performance of shared_mutex
Standard Library primitives
Boost Coroutine
Asymmetric coroutines
Self-test questions
Summary
References
11. Network Programming Using Boost Asio
Task execution with Asio
IO Service, queues, and handlers
Handler states – run_one, poll, and poll_one
post versus dispatch
Concurrent execution via thread pools
io_service::work
Serialized and ordered execution via strands
Network I/O using Asio
UDP and TCP
IP addresses
IPv4 addresses
Subnets
Special addresses
Handling IPv4 addresses with Boost
IPv6 addresses
Address classes, scopes, and subnets
Special addresses
Handling IPv6 addresses with Boost
Endpoints, sockets, and name resolution
Ports
Sockets
Hostnames and domain names
Name resolution
Buffers
Buffer sequences for vectored I/O
Synchronous and asynchronous communications
Asio deadline timer
Asynchronous logic using Asio coroutines
UDP
Synchronous UDP client and server
Asynchronous UDP server
Asynchronous UDP server using completion handler chains
Asynchronous UDP server using coroutines
Performance and concurrency
TCP
Establishing a TCP connection
Client- and server-side calls
Synchronous TCP client and server
Concurrency and performance
Asynchronous TCP server
Asynchronous TCP server using coroutines
Asynchronous TCP server without coroutines
Lifetime of TCPAsyncConnection
Performance and concurrency
Inversion of control flow
Self-test questions
Summary
References
A. C++11 Language Features Emulation
RAII
Copy semantics
The nothrow swap
Move semantics and rvalue references
rvalue references
rvalue-reference overloads
Move assignment
xvalues
Move emulation using Boost.Move
C++11 auto and Boost.Auto
Type deduction rules
Common uses
Boost.Auto
Range-based for-loops
Boost.Foreach
C++11 exception-handling improvements
Storing and rethrowing exceptions
Storing and rethrowing exception using Boost
Self-test questions
References
Index
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜