I’m using a vector for several arrays in my code due to the requirement of random access to the individual elements of the array. Some user GUI operations require searching through the array (but not enough to warrant the use of std::map), so littered through the code is this:
if (std::find(array.begin(), array.end(), searchfor) != array.end()) { ... }
I’m thinking of a better and more easily readable way of doing this, perhaps creating a method so I can do something like if (array_find(searchfor) != array.end()) or maybe even extending vector so I can do if (array.find(searchfor) != array.end()).
I’m not sure of the best way to do it. Any ideas?
Use whatever you prefer. I believe doing a function is better though, it avoids the hassle of creating a new class and using it everywhere. Something like :