Uninitialized_copy / fill (First, In last, For dest, A & a) oversight in the C ++ standard?

I like to know how everything works, and as such went into the standard C ++ library. Something happened to me the other day.

Restraint devices (for example:) are required to std::vector<int, std::allocator<int> >use the valve specified for the distributions. In particular, the standard says:

23.1.8

Copy the constructors for all container types defined in this section the dispenser argument from their respective first parameters. All other constructors for these container types accept Allocator & argument (20.1.5), a dispenser whose value type matches the type of container value type. A copy of this argument is used for any memory functions performed by these constructors and all participants during the lifetime of each container object. In general, the container types defined in this section, the get_allocator () member returns a copy of the Allocator object used to build the container.

In addition, in the standard, he says (in several different places, but I will take one) such things:

explicit deque(size_type n, const T& value = T(), const Allocator& = Allocator());

Effects: Creates a deque with n copies of the value using the specified allocator.

Ok, so to my question.

std::vector, - :

vector<T, A>::vector(const vector& x)

:

template <class T, class A>
vector<T, A>::vector(const vector& x)  {
    pointer p = alloc_.allocate(x.size());
    std::uninitialized_copy(x.begin(), x.end(), p);
    first_ = p;
    last_  = p + x.size();
    end_   = p + x.size();
}

, . - new value_type[x.size()], !

, ...

, - :

while(first != last) {
    alloc_.construct(&*dest++, *first++);
}

, std::uninitialized_copy, , .

, , ( , ) , :

template <class In, class For, class A>
For uninitialized_copy(In first, In last, For dest, A &a);

template <class In, class Size, class For, class A>
For uninitialized_copy_n(In first, Size count, For dest, A &a);

template <class For, class T, class A>
void uninitialized_fill(For first, For last, const T& x, A &a);

template <class For, class Size, class T, class A>
void uninitialized_fill_n(For first, Size count, const T& x, A &a);

, ( ... ) , .

?

+3
2

, "", .

, . , .

@MarkB , ( ). , .

uninitialized_copy , , . for.

+2

, , , . , , .

+1

All Articles