-
Notifications
You must be signed in to change notification settings - Fork 1.5k
added SmallVector alias with conditional boost::container version #3799
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
Conversation
d3c781c to
49c93da
Compare
|
approach looks ok to me. |
|
I am still testing the follow-up PR which brings the improvements and I might need to adjust the alias still. |
|
|
||
| #include <cstddef> | ||
|
|
||
| static constexpr std::size_t DefaultSmallVectorSize = 0; |
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.
Wouldnt we want to default to be something like 4?
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.
Will be adjusted when the actual usage is added. Seems we will end up with 5 for that.
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 you going to set this to 5?
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.
Like I said I will do this in the follow-up(s) (one will drop shortly after this is in, the other in the following days). Currently nobody is using it and I want those changes tied together.
lib/smallvector.h
Outdated
| #include <vector> | ||
|
|
||
| template<typename T, std::size_t N = DefaultSmallVectorSize> | ||
| using SmallVector = std::vector<T>; |
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.
This should use a custom allocator so we can catch mismatches even when we aren't using boost small_vector:
template<class T, std::size_t N>
struct TaggedAllocator : std::allocator<T>
{
template<class... Ts>
TaggedAllocator(Ts&&... ts)
: std::allocator<T>(std::forward<Ts>(ts)...)
{}
};
template<typename T, std::size_t N = DefaultSmallVectorSize>
using SmallVector = std::vector<T, TaggedAllocator<T, N>>;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.
Alright. Let me test that.
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.
Looks fine. Makes it also slightly faster with GCC.
7f47ec2 to
5abb905
Compare
Co-authored-by: Ken-Patrick Lehrmann <kp.lehrmann+github@gmail.com>
|
@pfultz2 Does this look okay now? |
danmar
left a comment
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.
if @pfultz2 is happy I am happy
|
Yea LGTM |
Currently not used in CI.
Have a follow-up PR which switches the most obvious case to SmallVector.