added SmallVector alias with conditional boost::container version#3799
added SmallVector alias with conditional boost::container version#3799firewave merged 3 commits intocppcheck-opensource:mainfrom
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.
Wouldnt we want to default to be something like 4?
There was a problem hiding this comment.
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.
Are you going to set this to 5?
There was a problem hiding this comment.
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.
| #include <vector> | ||
|
|
||
| template<typename T, std::size_t N = DefaultSmallVectorSize> | ||
| using SmallVector = std::vector<T>; |
There was a problem hiding this comment.
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.
Alright. Let me test that.
There was a problem hiding this comment.
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? |
|
Yea LGTM |
Currently not used in CI.
Have a follow-up PR which switches the most obvious case to SmallVector.