FW: gcc/stl question
James Crotinger
JimC at proximation.com
Thu Apr 19 15:52:55 UTC 2001
Mark suggested continuing this discussion on pooma-dev.
Mark, does this mean that
vector<int> a(10,5);
will select the template constructor (since 10 is not an unsigned int)? I
could have sworn that special things were supposed to be done to make this
do what people expected it to do, and I just figured that the pointer case
would be similarly handled.
(BTW, is my recollection correct that I can safely leave the initialization
off in the test below - vector always initializes its memory with the
default constructor, right?)
Jim
---------------------------------------------------
James A. Crotinger
Software Research Scientist
Proximation, LLC
-----Original Message-----
From: Mark Mitchell [mailto:mark at codesourcery.com]
Sent: Thursday, April 19, 2001 9:44 AM
To: JimC at proximation.com
Subject: Re: gcc/stl question
Mark, should the following code work:
#include <vector>
using std::vector;
struct Foo { };
void main()
{
vector<Foo*> table(100,0);
}
No, that code is broken.
The problem is that there are two relevant constructors required by
the standard:
explicit vector(size_type n, const T& value = T(),
const Allocator& = Allocator());
template <class InputIterator>
vector(InputIterator first, InputIterator last,
const Allocator& = Allocator());
The template clearly matches, with InputIterator = `int'.
The other case requires two conversionts "int -> size_t" and "int ->
Foo*". Those are both "Promotions" according to the overloading
rules, as opposed to "Exact Matches", so the template case wins.
BTW, does gcc's STL not have a vector<T*> specialization that implements
everything with a void*? I thought this was fairly common, but the above
makes it look like it is instantiating things specific for Foo*.
You're correct on both points. GCC's implementation could/should be
optimized to ue less code space by collapsing some common types in
this way.
By the way, you might as well ask these questions on pooma-dev; I bet
you're not the only one that would benefit from picking up a few more
bits of C++ arcana.
--
Mark Mitchell mark at codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sourcerytools.com/pipermail/pooma-dev/attachments/20010419/3419a534/attachment.html>
More information about the pooma-dev
mailing list