Fancy template expressions

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.
 
D

Dave Rahardja

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.

Yes.

-dr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top