Boost Writing better code faster with Boost. Boost Introduction Collection of C++ libraries Boost...

12
Boost Boost Writing better code faster with Boost

Transcript of Boost Writing better code faster with Boost. Boost Introduction Collection of C++ libraries Boost...

Page 1: Boost Writing better code faster with Boost. Boost Introduction Collection of C++ libraries Boost 1.30.2 includes 52 libraries, 1.31 will have at least.

BoostBoost

Writing better code faster with Boost

Page 2: Boost Writing better code faster with Boost. Boost Introduction Collection of C++ libraries Boost 1.30.2 includes 52 libraries, 1.31 will have at least.

Boost Introduction Boost Introduction

Collection of C++ libraries Boost 1.30.2 includes 52 libraries, 1.31 will have

at least 53 All are peer-reviewed, all are well-debugged, all

are well-thought-out Excellent cross-platform/cross-compiler support Designed to integrate well with the C++ Standard

Library, and add new functionality to it Can be thought of as a “training ground” for

additions to the C++ Standard Library

Page 3: Boost Writing better code faster with Boost. Boost Introduction Collection of C++ libraries Boost 1.30.2 includes 52 libraries, 1.31 will have at least.

AgendaAgenda

We will have overviews of:– Function and Bind Libraries– Smart Pointers– Miscellaneous Utilities– Preprocessor Library

We will also have an in-depth view of Boost Lambda Library

Page 4: Boost Writing better code faster with Boost. Boost Introduction Collection of C++ libraries Boost 1.30.2 includes 52 libraries, 1.31 will have at least.

Overview Overview

STL and Boost are like Chris Page and Dylan

Boost helps you create simpler, more robust code

Parts of Boost help you use STL more easily and effectively

Other parts help with exception safety, help prevent errors, and help with code generation

Page 5: Boost Writing better code faster with Boost. Boost Introduction Collection of C++ libraries Boost 1.30.2 includes 52 libraries, 1.31 will have at least.

Function and Bind LibrariesFunction and Bind Libraries

Function – like a function pointer and like a functor template parameter: the best of both worlds

Bind – generalized version of bind1st, bind2nd, mem_fun, mem_fun_ref, ptr_fun, all rolled into one

Example: int_wrapperExercise: access

Page 6: Boost Writing better code faster with Boost. Boost Introduction Collection of C++ libraries Boost 1.30.2 includes 52 libraries, 1.31 will have at least.

Smart PointersSmart Pointers

Assists in creating exception-safe and robust code

Better and more complete than std::auto_ptr

Example

Page 7: Boost Writing better code faster with Boost. Boost Introduction Collection of C++ libraries Boost 1.30.2 includes 52 libraries, 1.31 will have at least.

Miscellaneous UtilitiesMiscellaneous Utilities

noncopyable, static_assert – catch programming errors at compile time

type_traits – determine attributes of types for catching errors, generating better error messages, template metaprogramming

Example

Page 8: Boost Writing better code faster with Boost. Boost Introduction Collection of C++ libraries Boost 1.30.2 includes 52 libraries, 1.31 will have at least.

Preprocessor LibraryPreprocessor Library

Used for generating code with the preprocessor

This is useful for generating purely repetitive code that templates can’t handle

Even better for generating enumerations: for example, overloads of a function that takes from 0 to N parameters

Example: create

Page 9: Boost Writing better code faster with Boost. Boost Introduction Collection of C++ libraries Boost 1.30.2 includes 52 libraries, 1.31 will have at least.

Lambda LibraryLambda Library

Used for creating “lambdas” – unnamed local functions

Perfect solution for creating functors for STL algorithms

Clearly not as good as a language extension, but very nice, nonetheless

Trivial example - outputting a vectorfor_each(v.begin(), v.end(), cout << _1 << ‘ ’);

Page 10: Boost Writing better code faster with Boost. Boost Introduction Collection of C++ libraries Boost 1.30.2 includes 52 libraries, 1.31 will have at least.

More Lambda LibraryMore Lambda Library

Has facilities for most operators, solutions for those that are prevented by language constraints

Lambdas can access localsHas its own bindHas control structures - if/else, while,

do/while, for, switchHas facilities for exception handling

Page 11: Boost Writing better code faster with Boost. Boost Introduction Collection of C++ libraries Boost 1.30.2 includes 52 libraries, 1.31 will have at least.

SummarySummary

We have covered some of my favorite parts of Boost, but there are over 40 more libraries

Starting today: use Boost’s smart pointers and noncopyable in your C++ code

Move on to the other parts as you need them

Feedback time!

Page 12: Boost Writing better code faster with Boost. Boost Introduction Collection of C++ libraries Boost 1.30.2 includes 52 libraries, 1.31 will have at least.

Where to Get More InformationWhere to Get More Information

Boost: http://www.boost.org/(plug) Vanteon: http://www.vanteon.com/