A
Alan
I now know how to compose a function object for some standard
algorithms, e.g., std::sort(). However, I cannot find an explanation
of how to use a function object in my own code of an algorithm. All
the links I find focus on the former. Could anyone explain this to me
and/or point me to a clear explanation?
For example, how could I use the function object instantiated from the
class "less metric1" below?
What I want to do is to tell a function (e.g., do-something()) to do
some math based on a particular object`s attribute (out of several
attributes). It is very similar to how std::sort uses it (on the
surface), but I do not know how sort() uses a function object
internally.
Thanks, Alan
class measurement
{
public:
double metric1, metric2, metric3;
};
class less_metric1 : binary_function<measurement, measurement, bool>
{
public:
return_type operator()(const measurement& a, const measurement&
b)
{
return a.metric1 < b.metric1;
}
algorithms, e.g., std::sort(). However, I cannot find an explanation
of how to use a function object in my own code of an algorithm. All
the links I find focus on the former. Could anyone explain this to me
and/or point me to a clear explanation?
For example, how could I use the function object instantiated from the
class "less metric1" below?
What I want to do is to tell a function (e.g., do-something()) to do
some math based on a particular object`s attribute (out of several
attributes). It is very similar to how std::sort uses it (on the
surface), but I do not know how sort() uses a function object
internally.
Thanks, Alan
class measurement
{
public:
double metric1, metric2, metric3;
};
class less_metric1 : binary_function<measurement, measurement, bool>
{
public:
return_type operator()(const measurement& a, const measurement&
b)
{
return a.metric1 < b.metric1;
}