Category programming

STM, For Reals

In an earlier post post I mentioned software transactional memory (STM) as an alternative to using locks that maintains one’s ability to compose solutions to problems. That’s all well and good, but does anyone actually use it other than as a research toy? The answer to that question is yes: the team that I work […]

Pointing the Way Redux Done

So it didn’t end up taking years as I first thought it might. Instead, just a little over six months later, I’ve finished my more excruciating detail than anyone would want to read about which reference type to use when series. I covered the seven types that I feel every C++ programmer working with C++11 […]

Pointing the Way Redux, Part 7: boost::optional

In the last installment of my more info then you ever wanted about which reference to use when series – that has also covered values, references, bare pointers, shared_ptr and unique_ptr – I covered the last of the smart pointers: weak_ptr. This time we’ll cap off the series with boost::optional. While it’s not part of […]

Pointing the Way Redux, Part 6: weak_ptr

shared_ptr was the latest installment in my more info then you ever wanted about which reference to use when series that has also covered values, references, bare pointers, and unique_ptr. This time I’ll be covering the last of the smart pointer trifecta: weak_ptr. Among the smart pointers weak_ptr is sort of the odd one out […]

Pointing the Way Redux, Part 4: unique_ptr

So far in my series on what reference types to use when we’ve seen values, references and bare pointers. The first makes a strong statement about ownership when used as a return value: returning by value tells the caller that they own the object being returned. The other two are wishy-washy about ownership, but in […]

Pointing The Way Redux, Part 3: Bare Pointers

The next stop in my ongoing series going into too much detail about what type of reference to use when is bare pointers (see motivation and parts 1 and 2). Even though we now have an abundance of smart pointers to choose from – about which I’ll have more to say in future installments – […]

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 […]