Boost C++ Application Development Cookbook: Recipes to simplify your application development. 2 Ed

Boost C++ Application Development Cookbook: Recipes to simplify your application development. 2 Ed

Boost C++ Application Development Cookbook: Recipes to simplify your application development. 2 Ed
Автор: Polukhin Antony
Дата выхода: 2017
Издательство: Packt Publishing Limited
Количество страниц: 433
Размер файла: 2.3 MB
Тип файла: PDF
Добавил: codelibs
 Проверить на вирусы

Cover....1

Title Page....2

Copyright....3

Credits....4

About the Author....5

About the Reviewer....7

www.PacktPub.com....8

Customer Feedback....9

Table of Contents....10

Preface....27

Chapter 1: Starting to Write Your Application....33

Introduction....33

Getting configuration options....34

Getting ready....34

How to do it.......34

How it works.......36

There's more.......36

See also....39

Storing any value in a container/variable....39

Getting ready....39

How to do it.......40

How it works.......40

There's more.......41

See also....42

Storing multiple chosen types in a container/variable....42

Getting ready....43

How to do it.......43

How it works.......44

There's more.......44

See also....45

Using a safer way to work with a container that stores multiple chosen types....45

Getting ready....47

How to do it.......47

How it works.......49

There's more.......49

See also....50

Returning a value or flag where there is no value....50

Getting ready....50

How to do it.......50

How it works.......52

There's more.......52

See also....53

Returning an array from a function....53

Getting ready....53

How to do it.......53

How it works.......54

There's more.......54

See also....55

Combining multiple values into one....55

Getting ready....55

How to do it.......56

How it works.......57

There's more.......57

See also....58

Binding and reordering function parameters....59

Getting ready....59

How to do it.......59

How it works.......61

There's more.......61

See also....62

Getting a human-readable type name....63

Getting ready....63

How to do it....64

How it works.......64

There's more.......64

See also....65

Using the C++11 move emulation....65

Getting ready....65

How to do it.......65

How it works.......68

There's more.......68

See also....68

Making a noncopyable class....69

Getting ready....69

How to do it.......70

How it works.......70

See also....71

Making a noncopyable but movable class....71

Getting ready....71

How to do it.......72

How it works.......74

There's more.......74

See also....76

Using C++14 and C++11 algorithms....76

Getting ready....76

How to do it.......77

How it works.......77

There's more.......77

See also....78

Chapter 2: Managing Resources....79

Introduction....79

Managing local pointers to classes that do not leave scope....80

Getting started....81

How to do it.......81

How it works.......82

There's more.......83

See also....84

Reference counting of pointers to classes used across functions....84

Getting ready....85

How to do it.......85

How it works.......86

There's more.......86

See also....88

Managing pointers to arrays that do not leave scope....88

Getting ready....88

How to do it.......89

How it works.......89

There's more.......90

See also....90

Reference counting of pointers to arrays used across functions....91

Getting ready....91

How to do it.......92

How it works.......94

There's more.......94

See also....95

Storing any functional objects in a variable....95

Getting ready....96

How to do it.......96

How it works.......97

There's more.......97

See also....98

Passing function pointer in a variable....98

Getting ready....98

How to do it.......98

How it works.......98

There's more.......99

See also....99

Passing C++11 lambda functions in a variable....99

Getting ready....99

How to do it.......100

There's more.......100

See also....101

Containers of pointers....101

Getting ready....103

How to do it.......103

How it works.......104

There's more.......104

See also....105

Do it at scope exit!....105

Getting ready....106

How to do it.......106

How it works.......106

There's more.......107

See also....108

Initializing the base class by the member of the derived class....108

Getting started....109

How to do it.......109

How it works.......110

There's more.......110

See also....111

Chapter 3: Converting and Casting....112

Introduction....112

Converting strings to numbers....113

Getting ready....113

How to do it.......114

How it works.......114

There's more.......115

See also....116

Converting numbers to strings....116

Getting ready....116

How to do it.......117

How it works.......118

There's more.......118

See also....119

Converting numbers to numbers....119

Getting ready....120

How to do it.......120

How it works.......121

There's more.......121

See also....122

Converting user-defined types to/from strings....122

How to do it.......123

How it works.......124

There's more.......124

See also....125

Converting smart pointers....126

Getting started....126

How to do it.......127

How it works.......127

There's more.......128

See also....128

Casting polymorphic objects....128

Getting started....129

How to do it.......129

How it works.......129

There's more.......130

See also....130

Parsing simple input....130

Getting ready....131

How to do it.......132

How it works.......133

There's more.......134

See also....136

Parsing complex input....137

Getting ready....137

How to do it.......137

How it works.......140

There's more.......141

See also....142

Chapter 4: Compile-Time Tricks....143

Introduction....143

Checking sizes at compile time....144

Getting ready....144

How to do it.......145

How it works.......145

There's more.......147

See also....149

Enabling function template usage for integral types....149

Getting ready....149

How to do it.......150

How it works.......151

There's more.......152

See also....153

Disabling function template usage for real types....153

Getting ready....154

How to do it.......154

How it works.......155

There's more.......156

See also....156

Creating a type from a number....157

Getting ready....157

How to do it.......157

How it works.......158

There's more.......159

See also....160

Implementing a type trait....160

Getting ready....160

How to do it.......160

How it works.......161

There's more.......161

See also....161

Selecting an optimal operator for a template parameter....162

Getting ready....162

How to do it.......162

How it works.......164

There's more.......164

See also....166

Getting a type of expression in C++03....166

Getting ready....166

How to do it.......166

How it works.......167

There's more.......167

See also....169

Chapter 5: Multithreading....170

Introduction....170

Creating a thread of execution....171

Getting ready....171

How to do it.......171

How it works.......172

There's more.......173

See also....175

Syncing access to a common resource....175

Getting ready....176

How to do it.......177

How it works.......178

There's more.......179

See also....180

Fast access to common resource using atomics....181

Getting ready....181

How to do it.......181

How it works.......182

There's more.......183

See also....184

Creating work_queue class....184

Getting ready....184

How to do it.......185

How it works.......187

There's more.......188

See also....189

Multiple-readers-single-writer lock....190

Getting ready....191

How to do it.......191

How it works.......192

There's more.......192

See also....193

Creating variables that are unique per thread....193

Getting ready....194

How to do it.......194

How it works.......194

There's more.......195

See also....195

Interrupting a thread....196

Getting ready....196

How to do it.......196

How it works.......197

There's more.......197

See also....198

Manipulating a group of threads....198

Getting ready....199

How to do it.......199

How it works.......199

There's more.......200

See also....200

Initializing a shared variable safely....200

Getting ready....201

How to do it.......202

How it works.......202

There's more......203

See also....204

Locking multiple mutexes....204

Getting ready....205

How to do it.......205

How it works.......206

There's more.......207

See also....207

Chapter 6: Manipulating Tasks....208

Introduction....208

Before you start....209

Registering a task for an arbitrary data type processing....209

Getting ready....209

How to do it.......209

How it works.......212

There's more.......213

See also....213

Making timers and processing timer events as tasks....214

Getting ready....214

How to do it.......215

How it works.......217

There's more.......219

See also....219

Network communication as a task....219

Getting ready....220

How to do it.......220

How it works.......224

There's more.......228

See also....229

Accepting incoming connections....229

Getting ready....230

How to do it.......230

How it works.......232

There's more.......233

See also....234

Executing different tasks in parallel....234

Getting started....234

How to do it.......234

How it works.......235

There's more.......236

See also....236

Pipeline tasks processing....236

Getting ready....238

How to do it.......238

How it works.......241

There's more.......242

See also....242

Making a nonblocking barrier....242

Getting ready....244

How to do it.......244

How it works.......245

There's more.......246

See also....246

Storing an exception and making a task from it....247

Getting ready....247

How to do it.......247

How it works.......249

There's more.......250

See also....250

Getting and processing system signals as tasks....251

Getting ready....251

How to do it.......252

How it works.......254

There is more.......254

See also....254

Chapter 7: Manipulating Strings....256

Introduction....256

Changing cases and case-insensitive comparison....256

Getting ready....257

How to do it.......257

How it works.......258

There's more.......259

See also....259

Matching strings using regular expressions....259

Getting started....259

How to do it.......260

How it works.......263

There's more.......263

See also....263

Searching and replacing strings using regular expressions....264

Getting ready....264

How to do it.......264

How it works.......265

There's more.......266

See also....267

Formatting strings using safe printf-like functions....267

Getting ready....267

How to do it.......267

How it works.......268

There's more.......269

See also....269

Replacing and erasing strings....270

Getting ready....270

How to do it.......270

How it works.......271

There's more.......272

See also....272

Representing a string with two iterators....273

Getting ready....273

How to do it.......273

How it works.......275

There's more.......275

See also....276

Using a reference to string type....276

Getting ready....277

How to do it.......277

How it works.......279

There's more.......280

See also....281

Chapter 8: Metaprogramming....282

Introduction....282

Using type vector of types....283

Getting ready....283

How to do it.......283

How it works.......286

There's more.......287

See also....288

Manipulating a vector of types....288

Getting ready....288

How to do it.......289

How it works.......291

There's more.......292

See also....293

Getting a function's result type at compile time....293

Getting ready....294

How to do it.......294

How it works.......296

There's more.......296

See also....296

Making a higher-order metafunction....296

Getting ready....297

How to do it.......297

How it works.......299

There's more.......299

See also....299

Evaluating metafunctions lazily....299

Getting ready....300

How to do it.......300

How it works.......302

There's more.......303

See also.......303

Converting all the tuple elements to strings....304

Getting ready....304

How to do it.......304

How it works.......306

There's more.......307

See also....308

Splitting tuples....308

Getting ready....308

How to do it.......309

How it works.......310

There's more.......311

See also....312

Manipulating heterogeneous containers in C++14....312

Getting ready....313

How to do it.......313

How it works.......314

There's more.......315

See also....316

Chapter 9: Containers....317

Introduction....317

Storing a few elements in a sequence container....318

Getting ready....319

How to do it.......319

How it works.......319

There's more.......320

See also....321

Storing at most N elements in the sequence container....321

Getting ready....321

How to do it.......322

How it works.......322

There's more.......323

See also....323

Comparing strings in an ultra-fast manner....324

Getting ready....325

How to do it.......325

How it works.......326

There's more.......328

See also....328

Using an unordered set and map....328

Getting ready....329

How to do it.......329

How it works.......329

There's more.......332

See also....333

Making a map, where value is also a key....333

Getting ready....333

How to do it.......333

How it works.......336

There's more.......337

See also....337

Using multi-index containers....337

Getting ready....338

How to do it.......338

How it works.......341

There's more.......343

See also....343

Getting benefits of a single linked list and memory pool....343

Getting ready....344

How to do it.......344

How it works.......346

There's more.......347

See also....348

Using flat associative containers....348

Getting ready....348

How to do it.......348

How it works.......350

There's more.......351

See also....352

Chapter 10: Gathering Platform and Compiler Information....353

Introduction....353

Detecting an OS and compiler....354

Getting ready....354

How to do it.......354

How it works.......355

There's more.......355

See also....356

Detecting int128 support....356

Getting ready....356

How to do it.......356

How it works.......357

There's more.......358

See also....358

Detecting and bypassing disabled RTTI....358

Getting ready....359

How to do it.......359

How it works.......360

There's more.......361

See also....361

Writing metafunctions using simpler methods....362

Getting ready....362

How to do it.......362

How it works.......363

There's more.......363

See also....364

Getting ready....364

How to do it.......365

How it works.......365

There's more.......366

See also....366

The portable way to export and import functions and classes....366

Getting ready....367

How to do it.......367

How it works.......369

There's more.......370

See also....370

Detecting the Boost version and getting latest features....370

Getting ready....370

How to do it.......371

How it works.......372

There's more.......372

See also....372

Chapter 11: Working with the System....373

Introduction....373

Listing files in a directory....373

Getting ready....374

How to do it.......374

How it works.......375

There's more.......376

See also....377

Erasing and creating files and directories....377

Getting ready....377

How to do it.......378

How it works.......379

There's more.......379

See also....380

Writing and using plugins....380

Getting ready....380

How to do it.......380

How it works.......382

There's more.......382

See also....383

Getting backtrace – current call sequence....383

Getting started....383

How to do it.......384

How it works.......385

There's more.......386

See also....386

Passing data quickly from one process to another....386

Getting ready....387

How to do it.......387

How it works.......388

There's more.......389

See also....390

Syncing interprocess communications....390

Getting ready....390

How to do it.......390

How it works.......393

There's more.......393

See also....394

Using pointers in a shared memory....394

Getting ready....395

How to do it.......395

How it works.......396

There's more.......396

See also....397

The fastest way to read files....397

Getting ready....397

How to do it.......397

How it works.......398

There's more.......399

See also....399

Coroutines - saving the state and postponing the execution....400

Getting ready....400

How to do it.......400

How it works.......402

There's more.......403

See also....404

Chapter 12: Scratching the Tip of the Iceberg....405

Introduction....405

Working with graphs....406

Getting ready....406

How to do it.......406

How it works.......408

There's more.......410

See also....410

Visualizing graphs....411

Getting ready....411

How to do it.......411

How it works.......413

There's more.......413

See also....414

Using a true random number generator....414

Getting started....414

How to do it.......414

How it works.......415

There's more.......416

See also....416

Using portable math functions....416

Getting ready....417

How to do it.......417

How it works.......417

There's more.......418

See also....418

Writing test cases....419

Getting ready....419

How to do it.......419

How it works.......420

There's more.......421

See also....421

Combining multiple test cases in one test module....421

Getting ready....422

How to do it.......422

How it works.......423

There's more.......423

See also....423

Manipulating images....424

Getting ready....424

How to do it.......424

How it works.......427

There's more.......428

See also....428

Index....429

If you want to take advantage of the real power of Boost and C++ and avoid the confusion about which library to use in which situation, then this book is for you.

Beginning with the basics of Boost C++, you will move on to learn how the Boost libraries simplify application development. You will learn to convert data, such as string to numbers, numbers to string, numbers to numbers, and more. Managing resources will become a piece of cake. You'll see what kind of work can be done at compile time and what Boost containers can do. 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, and Android operating systems. From manipulating images to graphs, directories, timers, files, and networking, everyone will find an interesting topic.

Note that the knowledge from this book won't get outdated, as more and more Boost libraries become part of the C++ Standard.

Who this book is for

This book is for developers looking to improve their knowledge of Boost and who would like to simplify their application development processes. Prior C++ knowledge and basic knowledge of the standard library is assumed.


Похожее:

Список отзывов:

Нет отзывов к книге.