|
Boost Users : |
From: Chris Goller (cgoller_at_[hidden])
Date: 2005-01-26 19:21:43
I have a struct that contains two values.
struct box
{
double width;
double length;
}
vector<box> boxes;
I want to accumlate all the widths of the boxes. The only solution I've
found is to create a member function get_width that
will return the width for use in mem_fun_ref
eg:
accumulate(make_transform_iterator(boxes.begin(),
mem_fun_ref(&boxes::get_width)),
make_transform_iterator(boxes.end(), mem_fun_ref(&boxes::get_width)),
0.0,
plus<double>()));
Is there a boost way of not using mem_fun_ref, but rather returns the
public member variable. Something that could
be named mem_var_ref that would look like this:
accumulate(make_transform_iterator(boxes.begin(),
mem_var_ref(&boxes::width)),
make_transform_iterator(boxes.end(), mem_fun_ref(&boxes::width)),
0.0,
plus<double>()));
This way I wouldn't need to add extra get logic to a structure that
doesn't really need it othewise.
Thanks,
Chris
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