-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: support any allocator in offset_ptr_stl_allocator
#63
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx for PR. Looks good already, I would mainly sharpen the interface of offset_ptr_stl_allocator. With the requested changes, we could rename it to offset_ptr_allocator or offset_ptr_allocator_wrapper.
constexpr offset_ptr_stl_allocator &operator=(offset_ptr_stl_allocator &&other) noexcept(std::is_nothrow_move_assignable_v<upstream_allocator_type>) = default; | ||
|
||
explicit constexpr offset_ptr_stl_allocator(upstream_allocator_type const &upstream) noexcept(std::is_nothrow_copy_constructible_v<upstream_allocator_type>) | ||
: inner_{upstream} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only activate if upstream_allocator_type is copy constructible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there allocators that are not copy constructible? Would that work? I think all containers assume that they are copy constructible.
The only thing I'm aware of is allocators that are not assignable or swappable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- There are only constants to customize assignment and swap behaviour
- There is also
select_on_container_copy_construction
which is required to create a new instance. - all container ctors take allocator by
const &
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
about copy construction: you are right "(Note: Every Allocator also satisfies CopyConstructible.)" from https://en.cppreference.com/w/cpp/named_req/Allocator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewing the link above I come to the conclusion that every allocator must have move/copy assignment and copy ctor. I couldn't find anything about move ctor but I think it is safe to assume that it will always be present if there is already a move assignment operator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are wrong about assignment, there is nothing about assignment being required on that page you sent me. Only move+copy ctors.
This can also be confirmed by looking at std::pmr::polymorphic_allocator
as it does not have any operator=
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I've now defaulted the copy and move ctor, as it does not make sense to implement them manually
Support any
stl
-like allocator inoffset_ptr_stl_allocator
not juststd::allocator