Boost logo

Boost :

From: Kresimir Fresl (fresl_at_[hidden])
Date: 2002-06-30 10:12:34

David Abrahams wrote:

> From: "Joerg Walter"

>>I'm not sure about this. valarray<>'s greatest weakness w.r.t. uBLAS is,
>>that iterators are missing.

> Plain pointers should make fine valarray iterators, FWIW.

Yes, but valarray<> hasn't member functions begin() and end().

There are three possibilities then:

1) to use numerics::array_adaptor<>, as Joerg proposed in
another post (thread ``uBLAS and valarray'');

2) to write specializations of numerics::vector<> and
numerics::matrix<> for valarray<>;

3) to use some traits class, eg. Dietmar Kuehl's array_traits<>
extended with valarray<> specialization, but then all
occurances of `v.begin()' and `v.end()' in uBLAS classes
must be changed to `begin (v)' and `end (v)' (more precisely,
to `boost::begin (v)' and `boost::end (v)').

There's one more thing with second and third approach:
const version of valarray<T>::operator[]() returns `T' and not
`T const&'. Therefore, specializations for `const valarray<>'
should be something like:
// fictitious extension of Dietmar Kuehl's array_traits<>
   template <typename T>
   struct array_traits<std::valarray<T> const> {
       typedef T const* iterator;
       // other typedefs
       static iterator begin (std::valarray<T> const& cva) {
         std::valarray<T>& va = const_cast<std::valarray<T>&> (cva);
         return &va[0];
       static iterator end (std::valarray<T> const& cva) {
         std::valarray<T>& va = const_cast<std::valarray<T>&> (cva);
         return &va[0] + va.size();
       // ...


Boost list run by bdawes at, gregod at, cpdaniel at, john at