Topic: Is valarray an STL container?


Author: shepherd@debussy.sbi.com (Marc Shepherd)
Date: 1995/05/23
Raw View
Is the 'valarray' template an STL-compliant container?  My impression is
that it is not, and therefore, STL algorithms and iterators cannot be expected
to work on 'valarray' objects.  Specifically, valarray does not have a 'begin'
or an 'end' method, nor does it define 'value_type', 'reference', 'const_reference',
etc., as described in "Container requirements" on page 23-2 of the standard.

Is there any reason why valarray *couldn't* be STL-compliant?  Valarray strikes
me simply as a container that provides some extra features not found in other
containers.  It seems to me that it could be modified to comply with the STL
container requirements, and thereby mesh better with the rest of the library.

---
Marc Shepherd
Salomon Brothers Inc
shepherd@schubert.sbi.com The opinions I express are no one's but mine!






Author: jbuck@synopsys.com (Joe Buck)
Date: 1995/05/24
Raw View
shepherd@debussy.sbi.com writes:
>Is the 'valarray' template an STL-compliant container?  My impression is
>that it is not, and therefore, STL algorithms and iterators cannot be expected
>to work on 'valarray' objects.

While valarray does not have a begin or end method, you can obtain
corresponding pointers: if a is a valarray<T> for some T, &a[0] points to
the beginning, and &a[0]+a.length() points one past the end.  Since STL
algorithms work with pointers, this would let you use them.  But it would
seem reasonable to define begin() and end(), since they wouldn't add
significantly to the complexity or cost.
--
-- Joe Buck  <jbuck@synopsys.com> (not speaking for Synopsys, Inc)
Phone: +1 415 694 1729