Remove ambiguity in construction of prevector#14030
Conversation
The call with this default argument is redundant with prevector(size_type).
|
Note the effective implementation of change_capacity(n);
_size += n;
fill(item_ptr(0), n); |
Note to reviewers: This pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
| } | ||
|
|
||
| explicit prevector(size_type n, const T& val = T()) : _size(0) { | ||
| explicit prevector(size_type n, const T& val) : _size(0) { |
There was a problem hiding this comment.
The explicit keyword is also redundant for constructions with >1 argument.
There was a problem hiding this comment.
FYI: looks like this will change post C++11:
https://en.cppreference.com/w/cpp/language/explicit
https://en.cppreference.com/w/cpp/language/converting_constructor
There was a problem hiding this comment.
Neat!
It's not really relevant here, but I'll expand on @Empact's comment because it's something I didn't know, maybe others will benefit as well.
Post c++11:
using ScriptType = prevector<28, unsigned char>;
ScriptType vec{1, 255}; // always works
vec = ScriptType{1, 255}; // always works
vec = {1, 255}; // only works if prevector's ctor is not explicit.caveat: the 3rd example above does not actually work because of prevector's templated iterator ctor, but that's unrelated.
|
utACK |
|
utACK 497e90c. For reference, with c++11, std::vector's matching constructor also removed its default argument and dropped the explicit qualifier. |
497e90c Remove default argument to prevector constructor to remove ambiguity (Ben Woosley) Pull request description: The call with this default argument is redundant with `prevector(size_type)` on line 251. Tree-SHA512: 4d22e6f4cd56e4b700596d7f5afc945ec6684636a94690fa16a1bbb34e4f53b6340f53a6c314fea213359426474125228ba7193388789f8a13308506358e92db
497e90c Remove default argument to prevector constructor to remove ambiguity (Ben Woosley) Pull request description: The call with this default argument is redundant with `prevector(size_type)` on line 251. Tree-SHA512: 4d22e6f4cd56e4b700596d7f5afc945ec6684636a94690fa16a1bbb34e4f53b6340f53a6c314fea213359426474125228ba7193388789f8a13308506358e92db
The call with this default argument is redundant with
prevector(size_type)on line 251.