Tag Archives: value semantics

Another polymorphism

In this post we will try to see by a practical example what Boost.Variant is for. You can sometimes see examples that use type variant<int, double, string>, but to me they are artificial: I never needed to use something that … Continue reading

Posted in programming | Tagged , , , , , | 20 Comments

A gotcha with ptr_vector

Recently I came across an interesting gotcha with Boost.Pointer Container library in my project. Making some incorrect assumptions as to what the library does could cause a bug. What would you use boost::ptr_vector for? Why would you need to have … Continue reading

Posted in programming | Tagged , , | 23 Comments

Common optimizations

Language designers, compiler and library vendors make a great effort to make your programs run faster and faster. This post is a tour of some common performance optimizations in C++. Consider the following code that deals with std::string: std::string is … Continue reading

Posted in programming | Tagged , , , | 28 Comments

Type erasure — Part IV

Update. The information about boost::hold_any was imprecise. This tool does not work just for any type, but requires that the type provides operators << and >> for writing into and reading it from IOStreams. In this post we will be … Continue reading

Posted in programming | Tagged , , | 8 Comments

Type erasure — Part III

Update. My advice about using Boost.Pointer Container library was based on the false understanding of the library. It could even cause bugs. This has now been corrected. This is the third part of the series of posts on type erasure. … Continue reading

Posted in programming | Tagged , , | 15 Comments

Type erasure — Part II

In the previous post, we have seen that there is a number of ways to erase the type of an object while still holding a “handle” to it and being able to make use of it. This can be summarized … Continue reading

Posted in programming | Tagged , , , , | 6 Comments

Type erasure — Part I

Have you ever came across term type erasure in C++? This “pattern” or “technique” is growing more and more popular. In this post I will try to describe what it is. Note that it is something different than a similar … Continue reading

Posted in programming | Tagged , , , | 15 Comments