-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
r0d wrote:
Hello everybody,
i'm trying to use boost::multi_array objects with functions of the
<algorithm> stl lib. That's why i need to use the iterators of the
multi_arrays. But i don't understand the doc about them, and i can't find
any example of source code that use them.
Could anyone here show me an example of use, or explain me a little bit how
they work?
Thank you.
Iterators aren't pretty on multi_array - you have to bear in mind that
each dimension has a subarray. The best place to look for code is the
test cases:
http://www.boost.org/doc/libs/1_35_0/libs/multi_array/doc/test_cases.html
They are somewhat obfuscated by all the typedefs so I've put together a
typedef free testcase for you:
TEST(multi_array_iterator)
{
boost::multi_array myArray ( boost::extents[3][3] );
int values = 0;
for(boost::multi_array::index i = 0; i != 3; ++i)
{
for(boost::multi_array::index j = 0; j != 3; ++j)
{
myArray[i][j] = values++;
}
}
boost::multi_array::iterator it_begin=myArray.begin();
boost::multi_array::iterator it_end=myArray.end();
CHECK(it_begin::iterator columnIterator = it_begin;
columnIterator != it_end; ++columnIterator)
{
for (boost::multi_array::subarray<1>::type::iterator
rowIterator=(*columnIterator).begin();
rowIterator!=(*columnIterator).end(); ++rowIterator)
{
int currentValue=*rowIterator;
CHECK_EQUAL(currentValue, verify1++);
}
}
}
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
iD8DBQFIQH/4/X5Z5iyVCbERArsCAJ0S4nnqxw+Rp1RgXRaqa++KtJHOCACcDLq1
O1VoIPHN3GBz6nTOK29GAkY=
=QzHu
-----END PGP SIGNATURE-----