Boost bind and smart pointers

I’ve seen this several times causing troubles: boost::shared_ptr<Foo> p(new Foo); boost::thread t(boost::bind(&Foo::method, p.get())) This prevents the livecycle management of shared_ptr or any other smart pointer to be effective in the thread. Hence, p may get destructed even though the thread is still active. Boost bind can handle smart pointers, so instead use the smart pointer itself as the instance argument for bind: boost::thread t(boost::bind(&Foo::method, p))

January 9, 2011 · updated April 30, 2021 · 1 min

Using googlemock with the Boost Test Library

googlemock is a framework that allows generating mock objects for unit tests. I’ve decided to use this framework as it looks wells designed and maintained. The default is to use googlemock with Google’s unit testing framework googletest, but as I was already using the Boost Testing Library, I was searching for a solution to use googlemock in Boost Test. Fortunately this isn’t to hard to accomplish. You only have to create a TestEventListener that forwards all results supplied by googletest to the Boost Testing Framework: ...

April 13, 2010 · updated April 30, 2021 · 2 min

Highlights aus der Boost Graph Library

Template Programming to the Extreme… Manchmal macht es echt eine Freude den Quellcode der BGL (Boost Graph Library) zu lesen. Hier ein paar Highlights: typename T::ThereReallyIsNoMemberByThisNameInT vertices(T const&); // The graph is passed by *const* reference so that graph adaptors // (temporaries) can be passed into this function. However, the // graph is not really const since we may write to property maps // of the graph. Spaßig sind aber auch die Compiler-Fehlermeldungen: ...

July 30, 2009 · updated April 30, 2021 · 9 min