Category boost

Functional Stalemate

The other day I had occasion to write something along the lines of struct SomeClass { std::function<void ()> m_thisWillBeCalledLater; void SetFunc(std::function<void ()> func) { m_thisWillBeCalledLater = std::move(func); } }; class Foo; struct HandleUnique { HandleUnique (std::unique_ptr<Foo> foo_p): m_foo_p (std::move (foo_p)) {} std::unique_ptr<Foo> m_foo_p; void operator()() const { m_foo_p->Frobnobicate(); } }; SomeClass obj; obj.SetFunc(HandleUnique(std::make_unique<Foo>())); This code […]

Pointing the Way

While doing a code review the other day I came across something like this (names have been changed to protect the proprietary) class Foo { private: Bar m_bar; public: std::shared_ptr<Bar> GetBar() const { return std::make_shared<Bar>(m_bar); } }; Needless to say the code in question did not pass review. Between the unescessary copying of m_bar and […]


About once a year I end up thinking that using boost::enable_shared_from_this is a good idea. And every time it ends up wasting almost an hour of my time. You see there’s a restriction on shared_from_this that disallows its use in the constructor of the object that is being shared from this. Unfortunately this restriction is […]