This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: slices ; Stroustrup & libstdc++


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
| libstdc++.so.3.0.0) wrong, or am i missing something?
| 
| greetings,
| -gerhard

-- 
Damon Brent Verner
Cracker JackŪ Certified Professional
brent@rcfile.org, brent@linux1.org

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]