I'm constructing a javascript indicator for my client and they gave me below C++ code from their old system. I have never done C++ program before. Below is the part of the C++ code. What I want to know is in the lineif (it3 != d1Swing.end() && it3->x == h[i].x) --(it1 = it2 = it3);
what is the meaning of --(it1 = it2 = it3)? What will it looks like in javascript?
vector<PTPoint::PTIndexPoint> dnSwing;
list<PTPoint::PTIndexPoint> hq, lq;
vector<PTPoint::PTIndexPoint>::iterator it1 = d1Swing.begin(), it2 = d1Swing.begin(), it3 = ++d1Swing.begin();
//
// more code here
//
for (int i = 0; i < period; ++i)
{
while (!hq.empty() && hq.back().y < h[i].y) hq.pop_back();
hq.push_back(h[i]);
while (!lq.empty() && lq.back().y > l[i].y) lq.pop_back();
lq.push_back(l[i]);
if (it3 != d1Swing.end() && it3->x == h[i].x) --(it1 = it2 = it3);
//
// more code here
//
}
//
// more code here
//
p->swap(dnSwing);
Thanks in advance.
tslin
It means that their previous programmer loved being "clever".
The value of an assignment is a reference to the object that was assigned to, and assignment associates to the right.
--(it1 = it2 = it3)
is
--(it1 = (it2 = it3))
and it's intended to assign the value of it3
to it2
and it1
, then decrement it1
.
(I have a hunch that this may be undefined, which is a thing that happens frequently when you're being clever in C++.)
it1
is apparently intended to be "one step behind" it2
.
A more reasonable way to write that is
it2 = it3;
it1 = it2 - 1;
(In JavaScript, I suspect that you need to work with array indices rather than iterators to accomplish the same thing.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.