A class:
class foo{
public:
int data;
};
Now I want to add a method to this class, to do some comparison, to see if its data is equal to on
Any optimization is going to depend on properties of the set of numbers being compared to.
If there's a definite upper bound, you can use a std::bitset. Testing membership (that is, indexing into the bitset, which behaves like an array), is O(1), effectively a few fast instructions. This is often the best solution up to limits in the hundreds, although depending on the application millions could be practical.