This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [RFC] libstdc++/9626 and std::vector constructors
On Sat, Feb 08, 2003 at 04:50:27PM +0100, Paolo Carlini wrote:
> However, I'm still puzzled as regards why, in our implementation,
> we have:
>
> ...
> explicit
> vector(size_type __n);
>
> instead of:
>
> explicit
> vector(size_type __n, const value_type& __value = value_type(),
> const allocator_type& __a = allocator_type());
>
> according to the letter of the standard.
>
> Are they equivalent or not?
They are not equivalent, but the standard explicitly allows specified
default-argument functions to be expanded into overloads. Wherever
practical, our library should do it. We should do it as much as
possible now, because it risks breaking the ABI to do it later.
Breaking up the interface very often creates optimization opportunities.
Not breaking it up may foreclose those opportunities until the next time
we choose to break the ABI.
In the case of the vector constructor, *not* overloading would mean that
you construct an extra copy of the object, unnecessarily.
Nathan Myers
ncm@cantrip.org