I’ve used python for a long time, and I’m just beginning to use C++
In python, if one has a set or a dictionary it is relatively easy to get a boolean value indicating whether or not a particular item is in that sequence using the in keyword.
i.e.
a = set(2,4,3)
if 4 in a
print "yes, 4 is in a, thank you for asking!"
it’s much more efficient than doing this:
a = [2,3,4]
for number in a
>if number == 4
>>return "yes, 4 is in a, thank you for asking!"
is there a way to do make a membership test simple and efficient in cpp or do you always have to iterate through some ordered sequence?
You have functionality like this in std::set and tr1::unordered_set (not yet in C++ standard).
In reality, if your data set is small, linear search may still be the faster option.