Why do signatures of make_shared and allocate_shared differ for the args to be forwarded?

196 views Asked by At

In order to create a std::shared_ptr for a given type T, there are two ways among the others: std::allocate_shared and std::make_shared.
The main difference (or at least, the one I'm interested in for this question) is that the former does all memory allocations by means of a copy of a given allocator.

From the documentation, std::allocate_shared has the following signature:

template< class T, class Alloc, class... Args >
shared_ptr<T> allocate_shared( const Alloc& alloc, Args... args );

On the other side, std::make_shared is depicted as:

template< class T, class... Args >
shared_ptr<T> make_shared( Args&&... args );

For both of them it is stated that:

args... - list of arguments with which an instance of T will be constructed.

Everything seems right since now (the extra allocator, the arguments, and so on).
Anyway, as far as I've understood, both of them should declare arguments as universal references and this is not the case (at least, from what I see in the documentation).

In other terms, shouldn't the signature of std::allocate_shared be the following?

template< class T, class Alloc, class... Args >
shared_ptr<T> allocate_shared( const Alloc& alloc, Args&&... args );

Is it right for them to be different or is it a mistake of that site?
If that's the first case, what have I missed in my reasoning?

0

There are 0 answers