freepooma-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FW: gcc/stl question


From: James Crotinger
Subject: FW: gcc/stl question
Date: Thu, 19 Apr 2001 08:52:55 -0700

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:address@hidden]
Sent: Thursday, April 19, 2001 9:44 AM
To: address@hidden
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                   address@hidden
CodeSourcery, LLC               http://www.codesourcery.com


reply via email to

[Prev in Thread] Current Thread [Next in Thread]