P
Piotr
Hi,
I have the following code which uses STL transform algorithm. It
basically takes a list of Rect* object, get all the y attribute and
store it in a vector of 'int'.
My question is: is there a way to simplify the code? Is there a way for
me to get rid of the GetY class, since it essentially just calls
'getY()'. Thank you.
class GetY : public std::unary_function<Rect*, int>
{
public:
int operator()(Rect* r);
};
int GetY :: operator()( Rect* r)
{
return r->getY();
}
vector<int>& getY(list<Rect*> _rectList) {
vector<int>* _y = new vector<int>(_rectList.size()),
transform(_rectList.begin(), _rectList.end(), _y->begin(), GetY());
return *(_y);
}
I have the following code which uses STL transform algorithm. It
basically takes a list of Rect* object, get all the y attribute and
store it in a vector of 'int'.
My question is: is there a way to simplify the code? Is there a way for
me to get rid of the GetY class, since it essentially just calls
'getY()'. Thank you.
class GetY : public std::unary_function<Rect*, int>
{
public:
int operator()(Rect* r);
};
int GetY :: operator()( Rect* r)
{
return r->getY();
}
vector<int>& getY(list<Rect*> _rectList) {
vector<int>* _y = new vector<int>(_rectList.size()),
transform(_rectList.begin(), _rectList.end(), _y->begin(), GetY());
return *(_y);
}