I have found myself repeatedly writing the following function :
// This function will try to find the 'item' in 'array'.
// If successful, it will return 'true' and set the 'index' appropriately.
// Otherwise it will return false.
bool CanFindItem(data_type item, const data_type* array, int array_size, int& index) const
{
bool found = false;
index=0;
while(!found && i < array_size)
{
if (array[index] == item)
found = true;
else index++;
}
return found;
}
Usually I write a similar function for each class/struct etc. need it.
My question is, is there a way to have this snippet ready to use without rewriting it ? I am programming in VS 2010.