Tag Archives: value semantics

The double life of objects

Some common knowledge: the lifetime of the object starts when its initialization is complete. Based on this we can get some further expectations: an object becomes const only after its initialization is complete. But this lifetime property of objects becomes … Continue reading

Posted in programming | Tagged , | 2 Comments

A moved-from optional

This post is in response to claims, that I have heard number of times, that the semantics of optional’s move operations are wrong: Some people are surprised that the second assert holds: the unfulfilled expectation is that moving from an … Continue reading

Posted in programming | Tagged , , , | 2 Comments

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 , , , , , | 22 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 , , | 24 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 , , , | 30 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 , , | 11 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 , , , | 26 Comments