Topic: slice_array<T> and operator[]


Author: Kresimir Fresl <fresl@grad.hr>
Date: 1997/09/11
Raw View
Here is an example from (sub)section `Slice_array'
(22.4.6, page 671) of the 3rd edition of Bjarne
Stroustrup's `The C++ Programming Language':

  void f (valarray<double>& d)
  {
    slice_array<double>& v = d[slice (0, d.size()/2, 2)];
    v[3] = 7.7;        // assign to d[6]
    double x = v[5];   // read from d[10]
    // ...
  }

But `slice_array<T>' doesn't have `operator[]'.
(Its interface, same as in section 26.3.5 of CD2,
is shown on the same page.) Did I miss something
obvious? Where is `slice_array<T>::operator[]'
declared?

BTW, I always thought that `slice_array's, as defined
in working papers (previous versions as well as the
last one) are almost useless without `operator[]'.


Two more questions about `slice_array<T>':

(1) Why it has `operator= (const valarray<T>&)'
    but `fill (const T&)' -- in `valarray<T>' both
    assignments are performed with `operator='?

(2) Why there are only computed assignmets with
    `valarray<T>' arguments, and not also with
    scalar arguments?


fres

fresl@grad.hr
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]