Internal typedefs in C++ – good style or bad style?

Something I have found myself doing often lately is declaring typedefs relevant to a particular class inside that class, i.e. class Lorem { typedef boost::shared_ptr<Lorem> ptr; typedef std::vector<Lorem::ptr> vector; // // … // }; These types are then used elsewhere in the code: Lorem::vector lorems; Lorem::ptr lorem( new Lorem() ); lorems.push_back( lorem ); Reasons I … Read more

Why can lambdas be better optimized by the compiler than plain functions?

In his book The C++ Standard Library (Second Edition) Nicolai Josuttis states that lambdas can be better optimized by the compiler than plain functions. In addition, C++ compilers optimize lambdas better than they do ordinary functions. (Page 213) Why is that? I thought when it comes to inlining there shouldn’t be any difference any more. … Read more

What are some uses of decltype(auto)?

In c++14 the decltype(auto) idiom is introduced. Typically its use is to allow auto declarations to use the decltype rules on the given expression. Searching for examples of “good” usage of the idiom I can only think of things like the following (by Scott Meyers), namely for a function’s return type deduction: template<typename ContainerType, typename … Read more

How do C++ class members get initialized if I don’t do it explicitly?

Suppose I have a class with private memebers ptr, name, pname, rname, crname and age. What happens if I don’t initialize them myself? Here is an example: class Example { private: int *ptr; string name; string *pname; string &rname; const string &crname; int age; public: Example() {} }; And then I do: int main() { … Read more

pinpointing “conditional jump or move depends on uninitialized value(s)” valgrind message

So I’ve been getting some mysterious uninitialized values message from valgrind and it’s been quite the mystery as of where the bad value originated from. Seems that valgrind shows the place where the unitialised value ends up being used, but not the origin of the uninitialised value. ==11366== Conditional jump or move depends on uninitialised … Read more