On 1/27/2016 5:53 PM, Daniel wrote:
> On Wednesday, January 27, 2016 at 11:20:53 AM UTC-5, Alf P. Steinbach wrote:
>> On 1/27/2016 1:17 AM, Daniel wrote:
>>> So regarding copy and move constructors, how does it fit in that since C++
>>> 11, the standard library container copy and move constructors also take an
>>> allocator parameter?
>>
>> They don't.
>>
>
> They do :-)
Uhm, not sure how you arrive at that conclusion, so not sure what to
explain.
Regarding terminology, a “copy constructor” for class T is one that can
be called with a single argument of type T, where the formal argument
type is one 4 allowed by the standard. It's not enough that a
constructor copies a T instance. It must be callable with single arg.
And ditto for move constructor.
Let's consider a concrete example, std::vector.
C++11 §23.3.6.1 provides a class declaration, with the following
constructors that can be passed a std::vector as first argument:
vector(const vector<T,Allocator>& x);
vector(vector&&);
vector(const vector&, const Allocator&);
vector(vector&&, const Allocator&);
The first one is the copy constructor. It has /a single formal argument/
of vector type. The standard's requirement of a copy constructor for
class T is that it can be called with a single argument of type T. The
standard lists 4 possible formal argument types for that first argument,
and those include pass by ref to const, as above.
The second one is the move constructor.
The third and fourth have allocator arguments. They are neither copy nor
move constructors, because they do not conform to the requirements on a
copy or move constructor. They can't be called with single argument.
Summing up, AFAIK there are no copy or move constructors in the standard
library with allocator as extra argument.
If there were then, as I mentioned in the original response, the
allocator argument would have to be defaulted.