Re: Sorting two arrays with one call to sort()?
{ Edits: Yahoo spam-like links removed from signature portion. Note 1:
the quoted article by "xxx@gmail.com" doesn't appear to have been posted
in clc++m, although the inner quoted article by John was. Note 2: Tom
arken has the same e-mail address as John, the original poster. -mod }
I think all the comp.lang.c++.moderated replies
were BS! I wasted time on each one of them and it was
a total waste of time...! None of those suggestions
work...the zip iterator was not designed to do what I
want to do...(well I'm glad I learnt about its useless
existence for my problem) and the other solution is
not that trivial...as it looks...beware...
your suggestion doesnt work either :) Try them
urself and you will find out why...its a waste of
time to overload those operators!
I think I found a solution, but its way more
complicated than I thought it would be...so I guess
I'll let all the gurus in c++.moderated think about
it...I know others have posted solutions elsewhere to
this problem...but I wish there was a clean way to
solve the problem...a nice,clean, short answer...
If this email ever gets posted to moderated,
please do not post any pseudo-code solutions to this
problem...And make sure you can sort two
vectors/arrays with your code before you post. (If
you need pseudo-code to sort two arrays in
code...well...shall we say, keep it to yourself...!)
Thanks.
xxx@gmail.com wrote:
On Sep 23, 11:38 am, John wrote:
Here is as far as I got, it still doesnt work :(
...
template < typename tA, typename tB >
struct double_iterator {
tA* a;
tB* b;
size_t i;
struct ref {
tA& p; tB& q;
ref(tA& p, tB& q) : p(p), q(q) {};
void operator=(ref y){
p= y.p; q = y.q;
};
void operator<(ref y){
return p < y.p;
};
};
ref operator*(){ return ref(a[i],b[i]); }
double_iterator(tA* _a, tB* _b, size_t _i){
a = _a;
b = _b;
i = _i;
};
};
1. double_iterator::ref::operator< should return
bool, not void.
2. std::sort requires the iterators to be
random-access, and your
double_iterator is not an iterator at all; you need
to define operator+
+, operator-- (both prefix and postfix versions),
operator==,
operator<, operator+, operator-, operator+=,
operator-=, operator[],
and operator* for it to be a random-access iterator.
All these are
easily implemented by delegation to both underlying
pointers.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]