|
Boost Users : |
From: Greg Link (link_at_[hidden])
Date: 2006-04-25 22:11:26
I would agree with you there - a 'foreach' would do what I need as
well, but as I'm not 100% familiar with the way libraries such as
boost are implemented, I worry that making your own control structure
is much more difficult than making an accessor/modifier pair. I can't
even imagine the syntax needed to convert the following into a
theoretical boost-defined 'foreach'
double previous = 0;
double accumulator = 0;
for(iterator_t myIterator = m_array.data(); myIterator != m_array.end
(); myIterator++)
{
accumulator += (*myIterator);
(*myIterator) *= previous
accumulator = (previous > 7) ? (do_function(accumulator)) : (0);
}
Sure, it's a contrived example, but I just don't know how a primarily
header library such as boost (or any library for that matter) would
be able to define a
foreach(m_array) {
}
in a syntactically and compiler-friendly manner. That doesn't mean,
however, that I'm still not interested in the possibility of
using .data() and iterating, I'm just concerned that if the data in
the container isn't sequential, I'm violating some law. I know (from
testing) that making an iterator
myIterator = m_array.begin();
and incrementing it only goes as high as the size of the highest
dimension before it hits m_array.end(), so I'm concerned that doing
myIterator = m_array.data();
will end at the same point (or just walk off into nowheresville).
Don't have my test code in front of me until tomorrow, where I'll
test for sure.
- Greg
On Apr 25, 2006, at 9:02 PM, Bruno Martínez wrote:
> On Tue, 25 Apr 2006 20:15:37 -0300, Antonio Piccolboni
> <piccolbo_at_[hidden]> wrote:
>
>> I guess what you want is origin(). Iterate from origin() to
>> origin+num_elements
>
> I think you meant data(). I also think that does not work if you
> have a
> multiarray that is a subset of another, because the elements are not
> contiguous.
>
> I also would like to iterate easily over all elements of a multiarray.
> Maybe a foreach-like function is easier to write than a general
> iterator.
>
> Bruno
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net