This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: egcs-1.0.2 STL problem?
- To: oliva at dcc dot unicamp dot br
- Subject: Re: egcs-1.0.2 STL problem?
- From: "Pinwu Xu" <pinwu_xu at hotmail dot com>
- Date: Wed, 25 Mar 1998 13:45:41 PST
- Cc: egcs at cygnus dot com
>Pinwu Xu writes:
>
>> vector<int> a_i_vec(5, 0);
>
>This is a common STL gotcha. Standard template class vector provides
>several different constructors, and two of them are viable:
>
> explicit vector(size_type n, const T& value);
> template <class InputIterator>
> vector(InputIterator first, InputIterator last);
>
>simplyfing for the case of vector<int> and instantiating the template
>constructor for InputIterator=int, we get:
>
> vector(size_type, const int&);
> vector(int, int);
>
>Since size_type is size_t, which is unsigned int, the second
>constructor is preferred over the first one, since it is an exact
>match.
>
>> int dummy_int(0);
>> vector<int> a_i_vec(5, dummy_int);
>
>> it works.
>
>egcs's STL is broken in this respect, because it defines two
>non-standard constructors:
>
> vector(int n, const T& value) { fill_initialize(n, value); }
> vector(long n, const T& value) { fill_initialize(n, value); }
>
>Now, since dummy_int is an lvalue (0 was not, so these constructors
>were not selected because they would involve the creation of
>temporaries), the first of these two constructors is selected as an
>exact match. But there constructors should not be defined, since they
>break ANSI/ISO C++ compliance.
>
>Unfortunately, stl_vector is imported as-is from the SGI
>implementation of STL. Would someone who is in touch with SGI
>developers please forward this message to them?
Thanks for all who answered, and helped. Though I put what I found
working to the list, it is clumsy, comparing to
vector<int> aIntV(5U, 0);
I was also curious how other people deal with this problem, cause
I felt that this was a quite common one.
Later.
Pinwu
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com