Reputation: 1524
I just stumbled around in the STL for C++ and found a quite surprising exception in the vector
header.
Cleaned up from some unnecessary junk it boils down to this:
(This snippets could be found in the vector
class within the STL vector
header)
template<typename... _Args>
reference emplace_back(_Args&&... __args) {
push_back(bool(__args...));
return back();
}
void push_back(bool __x) {
if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr())
*this->_M_impl._M_finish++ = __x;
else
_M_insert_aux(end(), __x);
}
As already outlined in the title, I'm quite surprised by the bool(__args...)
expression which makes no sense for me at all.
I hope somebody could bring light into the darkness and help me out.
Solution found, I was a bit lazy.
I used my IDEs method resolver to jump to the declaration.
But sadly it directed me to the stl_bvector.h
header and the given method above.
Since it seems that this header only handles the implementation for std::vector<bool>
the code makes much more sense.
Upvotes: 2
Views: 149
Reputation: 172994
I think you're checking the implementation of std::vector<bool>
.
bool(__args...)
is constructing a temporary bool
from the parameter pack __args...
(which is expanded into comma-separated expressions), then the temporary bool
is passed to the push_back(bool)
.
Upvotes: 3