Interesting boost::shared_ptr constructor

December 25th, 2009 § 2 Comments

The future standard extension (some of it is described in the Technical Report on C++ Standard Library Extensions – TR1) is going to include many libraries already contained within boost. One such library is boost’s Smart Pointers.

In this post I would like to show an interesting use-case of the smart_ptr class, through what I consider to be a less commonly known constructor.

« Read the rest of this entry »

boost::optional and its internals

December 4th, 2009 § 11 Comments

boost::optional is a very handy generalization of returning a null when there’s nothing to return. Consider a function such as strstr – either the required sub-string is found within the given string, in which case a pointer to it is returned, or a NULL value is returned to indicate that there was no such sub-string. In terms of boost::optional we would either return the same pointer to the occurrence of that sub-string (as before), or we would simply return nothing – no value at all. In this post we will demonstrate the usage of boost::optional and discuss its implementation.

« Read the rest of this entry »

Checking sizeof or the offset of a member

October 29th, 2009 § 8 Comments

Suppose we wanted to check the sizeof or the offset of a certain member within our struct (or class), without actually having an instantiated object to run the needed operations on. How would you do that?

« Read the rest of this entry »

One-line rsort of an integer array

October 3rd, 2009 § 1 Comment

Suppose you have an array of integers and a comparator function object. Your mission, should you choose to accept it, is to sort the array in a reversed order.. Using only a single line of code.

« Read the rest of this entry »

Implementing toString() and fromString() using std::stringstream

August 16th, 2009 § 1 Comment

The classes istringstream and ostringstream can be utilized to create generic templated toString() & fromString() functions. This functionality (which is built-in in many languages, such as Java) may come in very handy, quite often.

« Read the rest of this entry »

Where Am I?

You are currently browsing entries tagged with Boost at efesx.