// How many times does the integer [val] appear in an entire vector of integers? intcountOccurences(const vector<int>& vec, int val){ int count = 0; for (size_t i = 0; i < vec.size(); ++i) { if (vec[] == val) ++count; } return count; }
// How many times does the [type] [val] appear in an entire vector of [type]? template <typename DataType> intcountOccurences(const vector<DataType>& vec, DataType val){ int count = 0; for (size_t i = 0; i < vec.size(); ++i) { if (vec[] == val) ++count; } return count; }
// How many times does the [type] [val] appear in an entire [collection] of [type]? template <typename Collection, typename DataType> intcountOccurences(const Collection& list, DataType val){ int count = 0; for (auto iter = list.begin(); iter != list.end(); ++iter) { if (*iter == val) ++count; } return count; }
// How many times does the [type] [val] appear in [a range of elements]? template <typename InputIt, typename DataType> intcountOccurences(InputIt begin, InputIt end, DataType val){ int count = 0; for (auto iter = begin; iter != end; ++iter) { if (*iter == val) ++count; } return count; }