#Pointer comparisons
24 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
@topaz hatch we can discuss here so that the text channel does not get cluttered
But yeah, basically, the standard only defines pointer comparison for different pointers when:
- Two pointers in the same array
- Two pointers to different data members (non static) of the same object, subobjects of that object (recursively) when the subobjectis not zero sized or a union
Any other comparisons are not defined. So, your vector contains is only well defined if it indeed contains the object
right
so my original problem was that, i have a pointer to an object i am sure is contained in one of two vectors, and i want to determine which vector the object is in because i want to remove the object from the corresponding vector. is there a way to do this without resorting to linear search?
Is the data sorted?
no
Then linear it is

You could also use a bloom filter as an early out, but that's only a test for does not contain, it doesn't prove that it contains
i see
If you need a cheap lookup, you can use a hash set too, instead of a vector
But if your data set is small, linear search is cheap
i see
i am going to be iterating through this container a lot so i want to use a vector
well i found another fix for my problem in context what i am doing
i suppose thats the same for pointer arithmetic?
pointer1 + pointer2
https://eel.is/c++draft/expr.add
this is getting weirder
welcome to the weird world of pointers