Blitz logo

Blitz Devel :

From: Tom Hilinski (tom.hilinski_at_[hidden])
Date: 2003-01-03 08:28:10


I would like to consider providing operator[] for Array, identical to
operator() (my idea is to simply call operator(), all inline).

The reason is to provide compatibilty with std:: containers (vector, deque)
that provide operator[], and allow Array to be used interchangably with them
via a template parameter. We have a small template class framework that can
accept a container to use for its internal storage, but it must provide
element access via operator[] (as well as iterator's, already available in
Array).

An additional benefit would be the tremendous ease of modifying our existing
models to use blitz Arrays rather conventional dynamically allocated arrays,
which are often indexed by [].

For example, the following functions show how I propose implementing these:

template<class P_numtype, int N_rank>
class Array : public MemoryBlockReference<P_numtype>
{
    .....
    T_numtype operator[](int i0) const
    {
        return operator() (i0);
    }

    T_array operator[](Range r0) const
    {
        return operator() (r0);
    }

    template<class T1, class T2>
    _bz_typename SliceInfo<T_numtype,T1,T2>::T_slice
    operator[](T1 r1, T2 r2) const
    {
        return operator() (r1, r2);
    }

etc.

I see in the 0.6 source that operator[] is overloaded once to accept a std
container:

    template<class T_indexContainer>
    IndirectArray<T_array, T_indexContainer>
    operator[](const T_indexContainer& index)

I don't think this should cause an issue with my proposed operator[]'s.

Do you have any ideas on the implications and issues I would face by
providing operator[]?

Tom Hilinski

Natural Resource Ecology Laboratory
Colorado State University
E-mail: Tom.Hilinski_at_[hidden]