Skip to content

Add a tutorial on allocator support - #140

Merged
jbcoe merged 21 commits into
mainfrom
allocator-tutorial
Aug 19, 2026
Merged

Add a tutorial on allocator support#140
jbcoe merged 21 commits into
mainfrom
allocator-tutorial

Conversation

@RyanJK5

@RyanJK5 RyanJK5 commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

First draft of a tutorial. Walks through adding basic default-initialized allocator support, then stateful allocators and copy semantics, and finally allocator-aware move and swap semantics.

Closes #139.

@RyanJK5
RyanJK5 requested a review from jbcoe as a code owner August 13, 2026 21:28
@RyanJK5
RyanJK5 marked this pull request as draft August 13, 2026 21:29
@RyanJK5
RyanJK5 changed the base branch from main to polymorphism-tutorial August 13, 2026 21:31
@RyanJK5

RyanJK5 commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator Author

@jbcoe I put together this draft of the tutorial, but it definitely needs some work. Do you have any suggestions to avoid duplicating Owner between each of the steps of the tutorial? I considered out-of-line definitions, but I'm concerned it may be a bit overwhelming to show the entire allocator-aware class definition right after step 1. That being said, it may be less confusing than rewriting the class like I'm doing now.

@jbcoe
jbcoe force-pushed the polymorphism-tutorial branch from e431370 to d46e9af Compare August 14, 2026 01:06

@jbcoe jbcoe left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great on a first pass.

Maybe we could introduce the allocator-extended constructors as a step on their own?

Comment thread tutorials/allocators.cc Outdated
@RyanJK5

RyanJK5 commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator Author

@jbcoe Do we care about the exception guarantee for this demonstration? Right now it's using the basic guarantee because it made showcasing a little simpler, but if protocol is going to use a strong guarantee, I could change the tutorial to match.

Base automatically changed from polymorphism-tutorial to main August 14, 2026 14:08
@RyanJK5
RyanJK5 requested a review from jbcoe August 14, 2026 14:18
@RyanJK5
RyanJK5 marked this pull request as ready for review August 17, 2026 23:10
@jbcoe

jbcoe commented Aug 18, 2026

Copy link
Copy Markdown
Owner

@jbcoe Do we care about the exception guarantee for this demonstration? Right now it's using the basic guarantee because it made showcasing a little simpler, but if protocol is going to use a strong guarantee, I could change the tutorial to match.

It might be useful to add as another stage. We would like a strong exception guarantee if possible.

@jbcoe

jbcoe commented Aug 18, 2026

Copy link
Copy Markdown
Owner

@jbcoe I put together this draft of the tutorial, but it definitely needs some work. Do you have any suggestions to avoid duplicating Owner between each of the steps of the tutorial? I considered out-of-line definitions, but I'm concerned it may be a bit overwhelming to show the entire allocator-aware class definition right after step 1. That being said, it may be less confusing than rewriting the class like I'm doing now.

I would not worry about duplicating Owner. We do similar things in other tutorials, although for smaller classes.

@jbcoe

jbcoe commented Aug 18, 2026

Copy link
Copy Markdown
Owner

@RyanJK5 I merged main, please let me know if you'd rather that I did not do this.

Comment thread tutorials/allocators.cc Outdated

@jbcoe jbcoe left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this.

@RyanJK5
RyanJK5 requested a review from jbcoe August 19, 2026 05:18
@RyanJK5

RyanJK5 commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

Sorry to re-request, but the exception section turned out to be fairly sizable.

@jbcoe

jbcoe commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Sorry to re-request, but the exception section turned out to be fairly sizable.

Happy to re-review.

Comment thread tutorials/allocators.cc

Owner()
requires std::default_initializable<Alloc>
= default;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting here is not ideal. Not blocking but I wonder if our .clang-format settings can be improved?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I would expect the requires clause to be on the same line as the constructor.

@jbcoe jbcoe left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

@jbcoe
jbcoe merged commit a186e5f into main Aug 19, 2026
66 of 71 checks passed
@jbcoe
jbcoe deleted the allocator-tutorial branch August 19, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a tutorial on allocator support

2 participants