Page 1 of 1

How to convert C++ const_iterator and more to Lisp

Posted: Thu May 15, 2014 5:10 am
by joeish80829
How do I convert this section of C++ code into Lisp using Lisp lists. I don't really need to show it but I have a C++ vector<int>. I converted into lisp using CFFI. I converted the vector<int> filled with 5 numbers ,to a Lisp List.

Here is the final Lisp list:

Code: Select all

(1 2 3 4 5)
I would like you to hopefully ignore what I said previously and pretend that I'm just starting out with the previously mentioned Lisp list and know I need to operate on it precisely as below so it will fit into the other C++ code I'm converting to Lisp. can you kind gentleman possible show my the exact Lisp equivelant of the below statement, operating on this exact list...

Code: Select all

(1 2 3 4 5)
....thanks in advance for any help on this.

Code: Select all

       for( vector<int>::const_iterator r = number.begin(); r != number.end(); r++ )
        {
            number.push_back(1);
        }

Re: How to convert C++ const_iterator and more to Lisp

Posted: Thu May 15, 2014 10:28 am
by Goheeca
What should that snippet of code do? Because by every iteration you are extending the vector and you can't reach the end of it. Moreover, the iterator is invalidated by performing the push_back action.

Re: How to convert C++ const_iterator and more to Lisp

Posted: Fri May 16, 2014 4:41 am
by joeish80829
It is valid code from a working function..I changed the name of the vector<Rect> to vector<int> to show it here and to save confusion. Here is the original snippet:

Code: Select all

        for( vector<Rect>::const_iterator r = faces2.begin(); r != faces2.end(); r++ )
        {
            faces.push_back(Rect(smallImg.cols - r->x - r->width, r->y, r->width, r->height));
        }
It is from line 193 at this link :

https://github.com/Itseez/opencv/blob/m ... detect.cpp

There is a lot of code at that link and could get confusing. I did simplify right though and it is a valid expression

Re: How to convert C++ const_iterator and more to Lisp

Posted: Fri May 16, 2014 7:45 am
by joeish80829
Actually I grabbed the wrong one it was this I need to convert from line 199 at the above link:

Code: Select all

    for( vector<Rect>::iterator r = faces.begin(); r != faces.end(); r++, i++ ) {}

Also on the line 223 code:

Code: Select all

smallImgROI = smallImg(*r);
I'll have to call r as a pointer because calling as:

Code: Select all

smallImgROI = smallImg(r);
breaks the code. So a hint on that would really help as well eg don't know how to call as a pointer in CFFI yet.

You don't have to read all that code at the link...even a general idea would get me farther, Thanks for your attention to this so far:)

Re: How to convert C++ const_iterator and more to Lisp

Posted: Fri May 16, 2014 9:41 am
by Goheeca
The dereference for an iterator is an overloaded operator, thus you can call it in this way:

Code: Select all

smallImgROI = smallImg(r.operator*());
So manage invoking a method and you should be right.