By examining the implementation of the vector class in the GCC headers (stl_vector.h), I found the following two member functions inside the vector base implementation class (Which I renamed in the example as Data_Class to avoid long_and_weird name).
void
_M_copy_data(Data_Class const& __x) _GLIBCXX_NOEXCEPT
{
_M_start = __x._M_start;
_M_finish = __x._M_finish;
_M_end_of_storage = __x._M_end_of_storage;
}
void
_M_swap_data(Data_Class& __x) _GLIBCXX_NOEXCEPT
{
// Do not use std::swap(_M_start, __x._M_start), etc as it loses
// information used by TBAA.
Data_Class __tmp;
__tmp._M_copy_data(*this);
_M_copy_data(__x);
__x._M_copy_data(__tmp);
}
The members (_M_start, _M_finish, _M_end_of_storage) are just pointers of some type and are the only members in the class.
The question here is what is the reason for the comment in the second function?
It may be for the same reason, but why not use std::swap for two Data_Class objects or maybe at least an automatically generated operator= to do the copying?
I feel like this could be done simpler.