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

Pointing the Way Redux, Part 2: References

Continuing on with my series going into way more detail than anyone probably wants to go into about which reference type to use when, we now arrive at part 2: references (see motivation and part 1). Most of the time, by returning a reference to an object you’re making the statement that the object referred […]

Limited Publicity

I’ve got a class that needs to derive from enable_shared_from_this so that it can get a hold of shared_ptrs to itself. This class has private constructors and a static create method that returns a shared_ptr – doing otherwise is just suicidal: someone will create an object on the stack and then the object will blow […]

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