Page MenuHomePhabricator

[RCU] Add an implicit converting constructor
ClosedPublic

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

Details

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

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

Repository
rABC Bitcoin ABC
Branch
rcu_implicit_converting_constructor
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 19124
Build 37996: Build Diffbuild-without-wallet · lint-circular-dependencies · build-debug · build-clang · build-diff · build-clang-tidy
Build 37995: arc lint + arc unit

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.
src/rcu.h
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

src/rcu.h
144

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

src/rcu.h
144

That's what I thought as well but my compiler disagreed. It seems you can't have a template copy constructor: https://stackoverflow.com/questions/55845896/why-doesnt-the-standard-consider-a-template-constructor-as-a-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.