Page MenuHomePhabricator

[RCU] Add an implicit converting constructor

Authored by Fabien on May 20 2022, 14:25.


Group Reviewers
Restricted Project
rABC7b1b9f8c381c: [RCU] Add an implicit converting constructor

This will create an RCUPtr<T> from an RCUPtr<U> if U * is implicitely convertible to T *. This will come in handy for converting RCUPtr<T> to RCUPtr<const T>.

Test Plan
ninja check

Diff Detail

rABC Bitcoin ABC
Lint Not Applicable
Tests Not Applicable

Event Timeline

Fabien requested review of this revision.May 20 2022, 14:25
deadalnix requested changes to this revision.May 20 2022, 14:47
deadalnix added a subscriber: deadalnix.
deadalnix added inline comments.
159 ↗(On Diff #33642)

This needs to go as the copy constructor, and so you also need an assignment operator to go with this.

This revision now requires changes to proceed.May 20 2022, 14:47

Move to the copy section and add a converting assignment operator as well

144 ↗(On Diff #33646)

This works also if U == T, no? Why is the non template copy constructor needed?

144 ↗(On Diff #33646)

That's what I thought as well but my compiler disagreed. It seems you can't have a template copy constructor:

Also what happens here if you remove that copy constructor is that it is implicitly deleted because there is also a move constructor defined, and this implicitly deleted copy constructor takes precedence to the template resolution so your compiler will refuse to build.

This revision is now accepted and ready to land.May 21 2022, 23:25
This revision was automatically updated to reflect the committed changes.