• Complain

Björn Karlsson - Beyond the C++ Standard Library: An Introduction to Boost

Here you can read online Björn Karlsson - Beyond the C++ Standard Library: An Introduction to Boost full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2005, publisher: Addison-Wesley Professional, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Björn Karlsson Beyond the C++ Standard Library: An Introduction to Boost
  • Book:
    Beyond the C++ Standard Library: An Introduction to Boost
  • Author:
  • Publisher:
    Addison-Wesley Professional
  • Genre:
  • Year:
    2005
  • Rating:
    4 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 80
    • 1
    • 2
    • 3
    • 4
    • 5

Beyond the C++ Standard Library: An Introduction to Boost: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Beyond the C++ Standard Library: An Introduction to Boost" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Introducing the Boost libraries: the next breakthrough in C++ programming Boost takes you far beyond the C++ Standard Library, making C++ programming more elegant, robust, and productive. Now, for the first time, a leading Boost expert systematically introduces the broad set of Boost libraries and teaches best practices for their use. Writing for intermediate-to-advanced C++ developers, Bj?rn Karlsson briefly outlines all 58 Boost libraries, and then presents comprehensive coverage of 12 libraries youre likely to find especially useful. Karlssons topics range from smart pointers and conversions to containers and data structures, explaining exactly how using each library can improve your code. He offers detailed coverage of higher-order function objects that enable you to write code that is more concise, expressive, and readable. He even takes you behind the scenes with Boost, revealing tools and techniques for creating your own generic libraries. Coverage includes Smart pointers that provide automatic lifetime management of objects and simplify resource sharing Consistent, best-practice solutions for performing type conversions and lexical conversions Utility classes that make programming simpler and clearer Flexible container libraries that solve common problems not covered by the C++ Standard Library Powerful support for regular expressions with Boost.Regex Function objects defined at the call site with Boost.Bind and Boost.Lambda More flexible callbacks with Boost.Function Managed signals and slots (a.k.a. the Observer pattern) with Boost.Signals The Boost libraries are proving so useful that many of them are planned for inclusion in the next version of the C++ Standard Library. Get your head start now, with Beyond the C++ Standard Library.

Björn Karlsson: author's other books


Who wrote Beyond the C++ Standard Library: An Introduction to Boost? Find out the surname, the name of the author of the book and a list of all author's works by series.

Beyond the C++ Standard Library: An Introduction to Boost — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Beyond the C++ Standard Library: An Introduction to Boost" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Index
[]accessingstored valuesadaptersStandard Libraryadvantagesalgorithmsanyempty valuespointersstored valuesvaluesAny librarytypesany_out classapplicationsargumentsplaceholders forarithmetic operationsarraysarugument bindingassertionsassignmentstypes
Index
[]variablesbehaviorBindbindBindbindersfunction objectsbindsvirtual functionsblocksdisable_if]BoostUtilitychecked_array_delete
Index
[]C++C++ Standard Librarycallingfunctionscastingcastscharacter classeschecked_array_deletecheckingclass templateclassesany_outenablingproperty classesclasssescodecompile timecompliancecomposingobjectscompositioncomputationconceptsconnectingconstructingconstructorscopyshared_ptrtypescontrol structuresconversionscopy assignment operationscopy construction operationscopyingcountingvaluescreatingcriteriasorting criteriacustom deleterscustomizing
Library 1. Smart_ptr
Endnotes

Boost.Bind is just such a library.

How Does the Smart_ptr Library Improve Your Programs?
  • Automatic lifetime management of objects with shared_ptr makes shared ownership of resources effective and safe.

  • Safe observation of shared resources through weak_ptr avoids dangling pointers.

  • Scoped resources using scoped_ptr and scoped_array make the code easier to write and maintain, and helps in writing exception-safe code.

Smart pointers solve the problem of managing the lifetime of resources (typically dynamically allocated objects

[1] Just about any type of resource can be handled by a generic smart pointer type.

Smart_ptr Summary

This chapter has introduced the Boost smart pointers, a contribution to the C++ community that can hardly be overestimated. For a smart pointer library to be successful, it must take into consideration and correctly handle a great number of factors. I'm sure you have seen quite a number of smart pointers, and you might have even been involved in their creation, so you are aware of the effort involved to get things right. Not many smart pointers are as smart as they should be, and that makes the value of a proven library such as Boost.Smart_ptr immense.

Being such a central component of software engineering, the smart pointers in Boost have obviously received a lot of attention and thorough review. It is therefore hard to give credit to all who deserve it. Many have contributed valuable opinions and have been part of shaping the current smart pointer library. However, a few exceptional people and efforts must be mentioned here:

  • Greg Colvin, the father of auto_ptr , also suggested counted_ptr , which later became what we now call shared_ptr .

  • Beman Dawes revived the discussion about smart pointers and proposed that the original semantics as suggested by Greg Colvin be considered.

  • Peter Dimov redesigned the smart pointer classes, adding thread safety, intrusive_ptr , and weak_ptr .

It is intriguing that such a well-known concept continues to evolve. There will undoubtedly be more progress in the domain of smart pointers or maybe, smart resources, but just as important is the quality of smart pointers that are used today . It's survival of the fittest, and that's why people are using Smart_ptr. The Boost smart pointers are a fine, assorted selection of delicious software chocolate, and I eat them regularly (you should, too). We'll soon see some of them become part of the C++ Standard Library, as they have been accepted into the Library Technical Report.

When Do We Need Smart Pointers?

There are three typical scenarios when smart pointers are appropriate:

  • Shared ownership of resources

  • When writing exception-safe code

  • Avoiding common errors, such as resource leaks

Shared ownership is the case when two or more objects must use a third object. How (or rather when) should that third object be deallocated? To be sure that the timing of deallocation is right, every object referring to the shared resource would have to know about each other to be able to correctly time the release of that resource. That coupling is not viable from a design or a maintenance point of view. The better approach is for the owners to delegate responsibility for lifetime management to a smart pointer. When no more shared owners exist, the smart pointer can safely free the resource.

Exception safety at its simplest means not leaking resources and preserving program invariants when an exception is thrown. When an object is dynamically allocated, it won't be deleted when an exception is thrown. As the stack unwinds and the pointer goes out of scope, the resource is possibly lost until the program is terminated (and even resource reclamation upon termination isn't guaranteed by the language). Not only can the program run out of resources due to memory leaks, but the program state can easily become corrupt. Smart pointers can automatically release those resources for you, even in the face of exceptions.

Avoiding common errors. Forgetting to call delete is the oldest mistake in the book (at least in this book). A smart pointer doesn't care about the control paths in a program; it only cares about deleting a pointed-to object at the end of its lifetime. Using a smart pointer eliminates your need to keep track of when to delete objects. Also, smart pointers can hide the deallocation details, so that clients don't need to know whether to call delete , some special cleanup function, or not delete the resource at all.

Safe and efficient smart pointers are vital weapons in the programmer's arsenal. Although the C++ Standard Library offers std::auto_ptr , that's not nearly enough to fulfill our smart pointer needs. For example, auto_ptr s cannot be used as elements of STL containers. The Boost smart pointer classes fill a gap currently left open by the Standard.

The main focus of this chapter is on . Although the complementary scoped_array and shared_array are sometimes useful, they are not used nearly as frequently, and they are so similar to those covered that it would be too repetitive to cover them at the same level of detail.

How Does Smart_ptr Fit with the Standard Library?

The Smart_ptr library has been proposed for inclusion in the Standard Library, and there are primarily three reasons for this:

  • The Standard Library currently offers only auto_ptr , which is but one type of smart pointer, covering only one part of the smart pointer spectrum. shared_ptr offers different, arguably even more important, functionality.

  • The Boost smart pointers are specifically designed to work well with, and be a natural extension to, the Standard Library. For example, before shared_ptr , there were no standard smart pointers that could be used as elements in containers.

  • Real-world programmers have proven these smart pointer classes through heavy use in their own programs for a long time.

The preceding reasons make the Smart_ptr library a very useful addition to the C++ Standard Library. Boost.Smart_ptr's shared_ptr (and the accompanying helper enable_shared_from_this ) and weak_ptr have been accepted for the upcoming Library Technical Report.

scoped_ptr
Header: "boost/scoped_ptr.hpp"

boost::scoped_ptr is used to ensure the proper deletion of a dynamically allocated object. scoped_ptr has similar characteristics to std::auto_ptr , with the important difference that it doesn't transfer ownership the way an auto_ptr does. In fact, a scoped_ptr cannot be copied or assigned at all! A scoped_ptr assumes ownership of the resource to which it points, and never accidentally surrenders that ownership. This property of scoped_ptr improves expressiveness in our code, as we can select the smart pointer ( scoped_ptr or auto_ptr ) that best fits our needs.

Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Beyond the C++ Standard Library: An Introduction to Boost»

Look at similar books to Beyond the C++ Standard Library: An Introduction to Boost. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Beyond the C++ Standard Library: An Introduction to Boost»

Discussion, reviews of the book Beyond the C++ Standard Library: An Introduction to Boost and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.