Subscribe
- Follow Andrzej's C++ blog on WordPress.com
-
Recent Posts
Archives
Tag Archives: value semantics
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
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 Boost, C++11, stating intentions, type erasure, type system, value semantics
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
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
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
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
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 C++11, concepts, generic programming, type erasure, value semantics
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
Value-initialization with C++
Update. I made an error in the original text: empty braces are sometimes treated as a zero-size initializer list. Some time ago, I showed how boost::value_initialized can be used to value-initialize objects in generic components in C++03. In C++11 it … Continue reading