Hi,
Of course the statement as shown does not return anything; do you mean that the find returns an iterator testing equal to myvec.end() in all cases; or that (std::find(.....) == myvec.end) evaluates to false in all cases?
Of course "1B" is of type const char *. (And has a value equal to the address where this literal is stored.) You may be relying here on an implicit conversion of this to a wxString. Ask yourself what is the type of an iterator into the vector. Hint: with the vector container, is it, effectively, a pointer - in this case a char *? And if so, even if the vector contains a element constructed out of a "1B", this element will, almost certainly, not be at the same location as the address of the "1B" literal being used in the comparison. No? So the use of char * will allow the code to compile, but not to give the effect you're looking for. (ISTM that there is an analogy here with string comparison of two literal values: strcmp() can find these equal - but a comparison of their addresses would show inequality.) Can you use the debugger to view the relevant iterator values in your example? If so, what do you see?
In the case that the vector contains a wxString constructed out of "1B", I'd expect the find to return an iterator not equal to myvec.end(); and equal in all other cases.
Is this what you're expecting, and not finding? If so, could you post a little more of your test and diagnostic code that is failing?
Hi, Alec,On Tue, May 14, 2013 at 12:42 AM, al...@arlross.demon.co.uk <al...@arlross.demon.co.uk> wrote:
Hi,
Of course the statement as shown does not return anything; do you mean that the find returns an iterator testing equal to myvec.end() in all cases; or that (std::find(.....) == myvec.end) evaluates to false in all cases?
The latter.
Of course "1B" is of type const char *. (And has a value equal to the address where this literal is stored.) You may be relying here on an implicit conversion of this to a wxString. Ask yourself what is the type of an iterator into the vector. Hint: with the vector container, is it, effectively, a pointer - in this case a char *? And if so, even if the vector contains a element constructed out of a "1B", this element will, almost certainly, not be at the same location as the address of the "1B" literal being used in the comparison. No? So the use of char * will allow the code to compile, but not to give the effect you're looking for. (ISTM that there is an analogy here with string comparison of two literal values: strcmp() can find these equal - but a comparison of their addresses would show inequality.) Can you use the debugger to view the relevant iterator values in your example? If so, what do you see?
In the case that the vector contains a wxString constructed out of "1B", I'd expect the find to return an iterator not equal to myvec.end(); and equal in all other cases.
That was my understanding as well.
Is this what you're expecting, and not finding? If so, could you post a little more of your test and diagnostic code that is failing?
Not sure what else to post. This statement
bool res2 = std::find( positions.begin(), positions.end(), "1B" ) == positions.end();
evaluates res2 as false in all cases, whether positions vector contains "1B" string or not.
On Tue, May 14, 2013 at 5:59 PM, Igor Korot <ikor...@gmail.com> wrote:
Hi, Alec,On Tue, May 14, 2013 at 12:42 AM, al...@arlross.demon.co.uk <al...@arlross.demon.co.uk> wrote:
Hi,
Of course the statement as shown does not return anything; do you mean that the find returns an iterator testing equal to myvec.end() in all cases; or that (std::find(.....) == myvec.end) evaluates to false in all cases?
The latter.
Of course "1B" is of type const char *. (And has a value equal to the address where this literal is stored.) You may be relying here on an implicit conversion of this to a wxString. Ask yourself what is the type of an iterator into the vector. Hint: with the vector container, is it, effectively, a pointer - in this case a char *? And if so, even if the vector contains a element constructed out of a "1B", this element will, almost certainly, not be at the same location as the address of the "1B" literal being used in the comparison. No? So the use of char * will allow the code to compile, but not to give the effect you're looking for. (ISTM that there is an analogy here with string comparison of two literal values: strcmp() can find these equal - but a comparison of their addresses would show inequality.) Can you use the debugger to view the relevant iterator values in your example? If so, what do you see?
In the case that the vector contains a wxString constructed out of "1B", I'd expect the find to return an iterator not equal to myvec.end(); and equal in all other cases.
That was my understanding as well.
Is this what you're expecting, and not finding? If so, could you post a little more of your test and diagnostic code that is failing?
Not sure what else to post. This statement
bool res2 = std::find( positions.begin(), positions.end(), "1B" ) == positions.end();
evaluates res2 as false in all cases, whether positions vector contains "1B" string or not.I just tried it with g++ / mingw - works as advertised (i.e. res2 is false when "1B" exists in positions vector, else its true)Maybe its a compiler thing...Have you tried wrapping "1B" in a wxString() ? like this:bool res2 = std::find( positions.begin(), positions.end(), wxString("1B") ) == positions.end();