-
Recent Posts
Recent Comments
Archives
Categories
Category Archives: C++
How stupid is initializing a vector from the concatenation of 2 other vectors?
Recently, I wanted to construct quickly a constant vector being the result of the concatenation of two other vectors using a one liner code, and if possible, without rewriting the concatenation by myself. I am a very very very lazy … Continue reading
Posted in C++
Leave a comment
Avoid finding twice the same key in the map (part 2)
Later, I found the following code:
1 2 3 4 5 6 |
auto p = map.find(key); if (p != map.end()) { throw std::runtime_error(...); } prepare(value); map[key] = value; |
Posted in C++, C++11, STL
Leave a comment
Avoid finding twice the same key in the map (part 1)
This is unfortunate, but I regularly still see the following piece of code:
1 2 3 4 5 |
auto p = map.find(key); // (1) if (p != map.end()) { throw std::runtime_error(...); } map[key] = value; // (2) |
Posted in C++, C++11, STL
Leave a comment
An optional member of an optional object
My colleague told me that boost::optional suffers from missing the ability of building an optional of a member from an optional of its parent object.
Posted in boost, C++, C++11, optional
Leave a comment
Implementing comparators with tuple
C++11 introduces the interesting std::tuple feature. Here, I will present the usage of std::tie to implement comparison operators in a class.
Posted in C++, C++11
Leave a comment
Memory size of unique_ptr with custom deleter
About the memory size of a unique_ptr with a custom deleter … Continue reading