J
johnbrown105
Assuming that you have a vector<Item>, where Item is a class that has
a
member function get_qty(), which tells you the number of this kind of
item in stock.
The problem is to use remove_copy_if and bind2nd to get a list of all
items where the quantity is less than a given minimum.
I solved this by defining a function object:
struct qtyGE{
// typedefs for result_type, etc.
bool operator()(Item i, int minimum){return i.get_qty() >=
minimum);}
};
in combination with:
remove_copy_if(v1.begin(), v1.end(), back_inserter(v2)
bind2nd(qtyGE(), MINIMUM_QTY));
My question is:
Is there a set of fancy template expressions that combines such
constructs
as mem_fun_ref(&Item::get_qty), greater_equal<int>() and bind2nd, and
maybe others that I missed or have not seen yet so that I can do
without
qtyGE and instead write:
remove_copy_if(v1.begin(), v1.end(), back_inserter(v2)
<some-fancy-template-expressions>)
Yes or no will do. If there *is* a way, I don't really need to know
what
it is.
a
member function get_qty(), which tells you the number of this kind of
item in stock.
The problem is to use remove_copy_if and bind2nd to get a list of all
items where the quantity is less than a given minimum.
I solved this by defining a function object:
struct qtyGE{
// typedefs for result_type, etc.
bool operator()(Item i, int minimum){return i.get_qty() >=
minimum);}
};
in combination with:
remove_copy_if(v1.begin(), v1.end(), back_inserter(v2)
bind2nd(qtyGE(), MINIMUM_QTY));
My question is:
Is there a set of fancy template expressions that combines such
constructs
as mem_fun_ref(&Item::get_qty), greater_equal<int>() and bind2nd, and
maybe others that I missed or have not seen yet so that I can do
without
qtyGE and instead write:
remove_copy_if(v1.begin(), v1.end(), back_inserter(v2)
<some-fancy-template-expressions>)
Yes or no will do. If there *is* a way, I don't really need to know
what
it is.