Boost logo

Boost :

From: Andrei Tovtchigretchko (andrey_at_[hidden])
Date: 2000-01-18 22:18:12


Jim Argeropoulos wrote:

> I can see how it would be used, but it also looks like a maintance
> nightmare. When Box changes, you better make sure you are not relying on
the
> internal order/format/number of Box's members.

Sorry, I cannot figure out what you mean.
Do you see any reliance on internal order/format/number of Box's members in
expression like:
copy( memb_iter(vbox.begin(),&Box::width),
    memb_iter(vbox.end(),&Box::width),
    vwidth.begin() ); ?

The only information about Box that is used here is the name of the class
member -
"width". This is designed like mem_fun_ref adaptor.in STL.

> You also have to be sure
> someone does not pass in (depth,width] by mistake or missunderstanding.
You can do that kind of mistake with any "normal" iterator/container, if you
are not using
some "debug" version of STL (like stlport):
vector<int> a(10), b(10), c(10);
copy(a.begin(),b.end(),c.begin());
- will compile.

There is a way to make memb_iterators for Box::depth and Box::width
different
types by supplying &Box::depth and &Box::width as non-type template
parameters
for the iterator object (this will also conserve space in memb_iterator):
template <class _Iterator,class _MemberType,class _MemberPtr,_MemberPtr
_member_ptr>
class memb_iterator
{
    _Iterator x;
   ...
};
But in that case, I don't find the way to create a helper function that
would not require to
explicitly specify the type of the member (float in our example). So, I
decided against it.

Andrei


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk