bool xInItems = std::find(items.begin(), items.end(), x) != items.end();
Is there a shorter way to check if there are x in elements? This seems overly detailed (repeating paragraphs three times), which makes it difficult to read the code.
For example, is there something like the following:
bool xInItems = boost::contains(items, x);
If there is no more concise boost / stl algorithm to check if a collection contains an element, is it considered good or bad practice to use a helper function instead to include contains(items, x) ?
Am I using the wrong STL container? Even std :: set will result in bool xInItems = items.find(x) != items.end(); that still seems verbose. Am I thinking about it wrong?
source share