Add tutorial on narrowing conversions for wide pointers - #184
Draft
jbcoe wants to merge 3 commits into
Draft
Conversation
jbcoe
commented
Aug 27, 2026
| // Handles an AnimalPtr by looking up (or, on first use, building) a | ||
| // cached BirdVtable for its vtable_, rather than owning one itself or | ||
| // wrapping the AnimalPtr. | ||
| BirdPtr(AnimalPtr* animal) |
Owner
Author
There was a problem hiding this comment.
This needs to be AnimalPtr - take pointers, even wide pointers, by value.
jbcoe
commented
Aug 27, 2026
| EXPECT_EQ(bird.noise(), "Screech"); | ||
| }); | ||
| } | ||
| // jthreads join automatically when destroyed, so no explicit join loop. |
Owner
Author
There was a problem hiding this comment.
Remove this redundant comment.
jbcoe
commented
Aug 27, 2026
| AnimalPtr eagle_view(&eagle); | ||
|
|
||
| // Two lookups against the same AnimalPtr share a cache entry; a | ||
| // different AnimalPtr gets its own. |
Owner
Author
There was a problem hiding this comment.
Remove this redundant comment.
jbcoe
commented
Aug 27, 2026
| EXPECT_EQ(duck_view.noise(), "Quack"); | ||
| EXPECT_EQ(duck_view.identity(), "Duck"); | ||
|
|
||
| // Constructed from a pointer to duck_view, not from `duck` itself. |
Owner
Author
There was a problem hiding this comment.
Remove this redundant comment.
jbcoe
commented
Aug 27, 2026
| std::string_view identity() const { return "Eagle"; } | ||
| }; | ||
|
|
||
| // BirdVtable is narrower than AnimalVtable in the same way a Bird is a |
Owner
Author
There was a problem hiding this comment.
Rewrite this mostly redundant comment.
jbcoe
commented
Aug 27, 2026
Comment on lines
+29
to
+30
|
|
||
| // A follow-up to the tutorial on polymorphism. We construct a narrow |
Owner
Author
There was a problem hiding this comment.
Rewrite this comment to avoid clumsy overloading and re-use of wide and narrow.
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.
No description provided.