Y
yinglcs
I have a function in STL which add the 'area'
attribute of a list of Rect.
template< class T1, class T2> class add_area_per_cent
: public binary_function<T2, T1, T2>
{
public:
add_area_per_cent() { }
T2 operator() (T2 initial, T1 element) {
if (element != NULL) {
return initial + element->getAreaPerCent();
} else {
return initial;
}
}
};
float getTotalAreaPerCent(BlockDataList& bdl) {
return accumulate (bdl.begin(), bdl.end(), 0.0,
add_area_per_cent<BlockData*, float>());
}
Can you please tell me how can I reduce the amount of
code and use Boost bind library to achieve the same
thing?
Thank you.
attribute of a list of Rect.
template< class T1, class T2> class add_area_per_cent
: public binary_function<T2, T1, T2>
{
public:
add_area_per_cent() { }
T2 operator() (T2 initial, T1 element) {
if (element != NULL) {
return initial + element->getAreaPerCent();
} else {
return initial;
}
}
};
float getTotalAreaPerCent(BlockDataList& bdl) {
return accumulate (bdl.begin(), bdl.end(), 0.0,
add_area_per_cent<BlockData*, float>());
}
Can you please tell me how can I reduce the amount of
code and use Boost bind library to achieve the same
thing?
Thank you.