This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
Re: valarray problem with gcc-2.95.1
- To: Serge Barral <sbarral at ippt dot gov dot pl>
- Subject: Re: valarray problem with gcc-2.95.1
- From: Gabriel Dos Reis <dosreis at cmla dot ens-cachan dot fr>
- Date: 03 Nov 1999 17:45:39 +0100
- Cc: libstdc++ at sourceware dot cygnus dot com
- Organization: CMLA, ENS Cachan -- CNRS URA 1611 (France)
- References: <38200FE3.B2BE92F0@ippt.gov.pl>
- Reply-To: libstdc++ at sourceware dot cygnus dot com
Serge Barral <sbarral@ippt.gov.pl> writes:
| Hi,
|
| I'm using libsdc++-2.90.6 with gcc-2.95.1, and I have problems when
| slicing a valarray. For instance this code:
|
| #include <valarray>
|
| using namespace std;
|
| int main()
| {
| slice range(1,2,1);
| double l[]={1.0 , 2.0 , 3.0 , 4.0};
| valarray<double> c(l,4);
| valarray<double> b(2);
|
| b=c[range]+c[range]; // error here
|
| return 0;
| }
|
|
| gives the following compile error:
|
| >rien.cpp:In function `int main()':
| >rien.cpp:12: no match for `slice_array<double> + slice_array<double>'
|
|
| It looks like gcc does not choose the right signature for 'operator[]'
| of class valarray, which I think in this case should be:
| _Expr<_SClos<_ValArray,_Tp>, _Tp> operator[](slice) const;
| and not:
| slice_array<_Tp> operator[](slice);
Welcome to C++.
First some C++ rules recollection: when a member function is
overloaded using 'const', the const version is selected only when the
expression used to invoke it is 'const'. Thus 'c[range]' in
c[range] + c[range]
is of type slice_array<double> and not valarray<double>.
Yes, C++ is not intuitive.
| Surprisingly, if I comment out the second signature in the file
| 'std_valarray.h', the code compiles. However, an expression like
| 'b=exp(c[slice(..,..,..])' will still not compile.
|
| I'm quite new to c++, so maybe I'm missing something?
| Is it really a problem with gcc? In this case, should I try gcc-2.95.0
| or 2.95.2?
It isn't a porblem in GCC. It is the way C++ rules goes.
I agree with you there ought to be ways to add slice_array<T>s but the
Standard says otherwise.
-- Gaby