core: add shared_ptr overload for Bridge::switchBackend - #32
Open
Yaraslaut wants to merge 1 commit into
Open
Conversation
switchBackend previously only took a unique_ptr, so it could not express re-installing a backend instance the caller still owns -- e.g. an app that holds one long-lived remote backend for the process lifetime and toggles the bridge between it and a local fallback as connectivity comes and goes had to either give up ownership on the first switch (with nothing to switch back to) or reconstruct the remote backend on every transition, discarding its connection state. Add switchBackend(shared_ptr<IBackend>); the unique_ptr overload now converts and delegates to it. That overload is templated on the concrete backend type rather than taking unique_ptr<IBackend> directly: a non-template unique_ptr<IBackend> overload would tie with the new shared_ptr<IBackend> overload for a unique_ptr<Concrete> argument (both are one equally-ranked user-defined conversion), making every existing call site -- e.g. switchBackend(std::make_unique<LocalBackend>(...)) -- ambiguous. The template version is an exact match and wins cleanly. Closes #22 Signed-off-by: Yaraslau Tamashevich <yaraslau.tamashevich@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Bridge::switchBackendonly took aunique_ptr, so it could not express re-installing a backend instance the caller still owns (e.g. toggling between a long-lived remote backend and a local fallback as connectivity comes and goes).switchBackend(shared_ptr<IBackend>). Theunique_ptroverload is now a template on the concrete backend type that converts and delegates to theshared_ptroverload — templating it (rather than takingunique_ptr<IBackend>directly) is required to avoid an overload-resolution ambiguity: a plainunique_ptr<IBackend>overload ties with the newshared_ptr<IBackend>overload for calls likeswitchBackend(std::make_unique<LocalBackend>(...)), since both require one equally-ranked user-defined conversion. The template version is an exact match instead.unique_ptrcall sites are unaffected (verified — the full suite already relies on this pattern in several tests).Test plan
tests/test_switch_backend.cpp: one re-installs the same caller-ownedshared_ptrbackend after switching away (use_count() > 1throughout, no ownership transfer, subsequent execute still works), one confirms the templatedunique_ptroverload still works and delegates correctly../build/tests/morph_tests— all 813 test cases / 8289 assertions pass.Closes #22
🤖 Generated with Claude Code