A
Alan
I was wondering if anyone had design advice on this. . . . I am
doing some mathematical operations looking at different metrics for
data (in objects) I have captured. The object class has several data
attributes, say: metric1, metric2, . . . metricN. These are different
metrics on which I am running statistics.
There are a number of operations I have to do on these objects for
each metric separately: sort, group (i.e., group a list of objects
based on a metric), etc. I understand the very basics of C++ template
functions, overloading, etc. However, I cannot figure out a way to
design a generic function to sort by each single attribute. So, I end
up with functions like: sort_by_metric1, sort_by_metric2, . . .
sort_by_metricN.
Is there a way to avoid so many nearly-duplicative functions? For
example, is there a way in the function call to tell the function what
metric I want to sort by? This would allow me to use one, generic
function vice a bunch of nearly-duplicative ones.
I hope this is clear. If not, please let me know, and I will
attempt to clarify.
Thanks, Alan
doing some mathematical operations looking at different metrics for
data (in objects) I have captured. The object class has several data
attributes, say: metric1, metric2, . . . metricN. These are different
metrics on which I am running statistics.
There are a number of operations I have to do on these objects for
each metric separately: sort, group (i.e., group a list of objects
based on a metric), etc. I understand the very basics of C++ template
functions, overloading, etc. However, I cannot figure out a way to
design a generic function to sort by each single attribute. So, I end
up with functions like: sort_by_metric1, sort_by_metric2, . . .
sort_by_metricN.
Is there a way to avoid so many nearly-duplicative functions? For
example, is there a way in the function call to tell the function what
metric I want to sort by? This would allow me to use one, generic
function vice a bunch of nearly-duplicative ones.
I hope this is clear. If not, please let me know, and I will
attempt to clarify.
Thanks, Alan