cplusplus.co.il

Archive for the ‘stl’ Category

Tuples

Posted on: 15/01/2010

One of the containers introduced within TR1 (which is already widely available – both in gcc and Visual Studio) is a Tuple type, which is adopted from The Boost Tuple Library. Tuple types are very convenient at times; For example, it is possible to return multipe values from a function through a tuple, or write more intuitive and expressive code by utilizing tuples.

In this post we will examine the functionality offered by the new Tuple container, and have a go at profiling its performance. Actually, the results of said profiling were a small (pleasant) surprise to me.

Read the rest of this entry »

Both std::cin and std::cout provide a conversion to a void* type, but not to a boolean:

operator void* (); // zero if and only if fail()

What use does a conversion to a boolean have, and which pitfalls does the current implementation save us from?

Read the rest of this entry »

Iterating over a vector is a pretty simple task we get to do pretty often. It can be achieved in quite a few ways:

  • Using normal random access (operator[] with index).
  • Using std::iterator.
  • Using std::for_each algorithm.

I set out to check the runtime differences between all these options, and the results turned out to be a little surprising (or not).

Read the rest of this entry »


Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 27 other subscribers

Categories