Boost logo

Boost Users :

From: bernhard.maeder_at_[hidden]
Date: 2006-05-24 08:07:56

Hello everyone

I'm trying to use the boost.multi_array's iterators and came across a
problem: calling end() on a certain multi_array_view only yields the
same iterator, if it is called on exactly the same instance of the
view. When, however, the view is created twice (using the same
expression, of course), end() produces an iterator that doesn't
compare to the first one.

In other words:
            != m_a[indices[index_range()][1]].end()

I'm not sure whether this is just me, trying to use something in a way
it shouldn't be used, or if this is a limitation of the multi_array
library. I'd appreciate your opinion!

Thanks a lot!

Bernhard Maeder

Following is the code that produces an error due to using the
multi_array in the above manner:


#include <iostream>
#include <boost/multi_array.hpp>

using namespace boost;
typedef boost::multi_array_types::index_range index_range;
using boost::indices;

template<typename IteratorType>
void output(IteratorType begin, IteratorType end)
    for (IteratorType it = begin; it != end; ++it)
        std::cout << *it << std::endl;

template<typename ArrayType>
void output(ArrayType const & ar)
   std::cout << "----------" << std::endl;
   std::cout << (ar.end() == ar.end()) << std::endl;
   std::cout << "----------" << std::endl;
   output(ar.begin(), ar.end());

int main()
    typedef boost::multi_array<double, 2> array_type;

    // Create a 3x3 array:
    array_type m_a(boost::extents[3][3]);

    for (std::size_t i=0; i<9; i++)[i] = static_cast<double>(i);

    // Works:
    std::cout << "Use a sub_array:" << std::endl;

    // Works:
    std::cout << "Use a multi_array_view:" << std::endl;

    // Doesn't work:
    std::cout << "Use subsequent versions of a multi_array_view:" <<
    // This returns false:
    std::cout << "----------" << std::endl;
    std::cout << (
         == m_a[indices[index_range()][1]].end()
          ) << std::endl;
    std::cout << "----------" << std::endl;

    output( m_a[indices[index_range()][1]].begin()
          , m_a[indices[index_range()][1]].end()

    return 0;


Diese Mitteilung ist nur fuer die Empfaengerin / den Empfaenger

Fuer den Fall, dass sie von nichtberechtigten Personen empfangen wird,
bitten wir diese hoeflich, die Mitteilung an die ZKB zurueckzusenden
und anschliessend die Mitteilung mit allen Anhaengen sowie allfaellige
Kopien zu vernichten bzw. zu loeschen. Der Gebrauch der Information
ist verboten.

This message is intended only for the named recipient and may contain
confidential or privileged information.

If you have received it in error, please advise the sender by return
e-mail and delete this message and any attachments. Any unauthorised
use or dissemination of this information is strictly prohibited.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at