
Originally Posted by
Zaccheus
There must be a simpler way of doing this.
Sure----just implement the copy constructor. I'm just playing around with ideas for alternatives in the case when *most* of the object doesn't need special copy treatment.
I'm still not clear what exactly are you trying to achieve, can you show us an actual example?
Code:
vector<double> actualvals;
struct CmpInds
{
vector<double> *vals;
CmpInds(vector<double> &vals_): vals(&vals_) {}
bool operator<(int i1, int i2) const
{ return (*vals)[i1] < (*vals)[i2]; }
};
struct Sorted
{
vector<int> inds;
CmpInds cmp;
Sorted(vector<double> &actualvals):
inds(boost::counting_iterator(0),boost::counting_iterator(actualvals.size())),
cmp(CmpInds(actualvals))
{
sort(inds.begin(), inds.end(), cmp);
}
};
This is the basic idea, except with a simple sort rather than a KDTree, and only 1-D data (doubles). Now, put the Sorted object into another object alongside the actualvals:
Code:
struct Object
{
vector<double> vals;
Sorted srt;
Object(): srt(vals) {}
}
Now, what do you do to make sure srt remains valid when an Object is copied?
Assume that Sorted has some additional query functions which require the use of cmp.