slices ; Stroustrup & libstdc++
llewelly@dbritsch.dsl.xmission.com
llewelly@dbritsch.dsl.xmission.com
Sat Jun 17 04:08:00 GMT 2000
On Sat, 17 Jun 2000, brent verner wrote:
> on Fri, Jun 16, 2000 at 12:59:00PM +0200, Gerhard Wesp typed aloud:
> | hi all,
> |
> | i just tried a slice_array example from stroustrup, 3rd ed., p. 671
> | which fails with the following error:
> |
> | grisu ~/c++% cat slice.cc
> | #include <valarray>
> |
> | void f(std::valarray<double>& d)
> | {
> | std::slice_array<double>& v_even = d[std::slice(0,d.size()/2,2)];
> | }
>
> I'm seeing the same error. I've spent the evening digging around
> valarray & friends. I can't even decide if the code above _should_
> work or not -- have you found out anything more? Would someone
> enlighten us? I've compared the code to the standard, and everything
> _looks_ OK (by the std).
>
> FWIW, the following code _does_ work.
>
> #include <valarray>
> #include <iostream>
>
> void
> f(std::valarray<double>& d)
> {
> std::slice oh(0,d.size()/2,2);
> d[oh] = 100;
> // d[oh] += d; // uncomment this to see its effect... i'm not
> // sure it is correct. :\ .
> }
>
> int
> main()
> {
> std::valarray<double> a(10);
> f(a);
> for(unsigned i = 0; i < a.size(); ++i)
> std::cout << "a[" << i << "] = " << a[i] << std::endl;
> return 0;
> }
>
> | grisu ~/c++% g++ -fhonor-std -c slice.cc
> | slice.cc: In function `void f(std::valarray<double> &)':
> | slice.cc:5: initialization of non-const reference type `class std::slice_array<double> &'
> | slice.cc:5: from rvalue of type `std::slice_array<double>'
> | grisu ~/c++% g++ -v
> | Reading specs from /usr/local/lib/gcc-lib/i586-pc-linux-gnu/2.95.2/specs
> | gcc version 2.95.2 19991024 (release)
> |
> | is stroustrup wrong, or is libstdc++ (i'm using version
It might be worthwhile to check the errata for 3rd edition, at
www.research.att.com/~bs/3rd_errata.html ; there are several errors
mentioned on pgs 670-671.
unfortunately, I cannot find my copy of 3rd edition, and the errata are
hard to read without one; I cannot tell what might be relevant.
> | libstdc++.so.3.0.0) wrong, or am i missing something?
> |
> | greetings,
> | -gerhard
>
>
More information about the Libstdc++
mailing list