Membership ckecks in C++ containers

#include <iostream> #include <algorithm> #include <vector> #include <set> #include <map> #include <string> using namespace std; template<typename T> inline void t(T what) { cout << what << endl; } template<typename T> bool in_vector(vector<T> v, T val) { return find(v.begin(), v.end(), val) != v.end(); } template<typename T> bool in_set(set<T> s, T val) { return find(s.begin(), s.end(), val) != s.end(); } template<typename T> bool in_map(map<string, T> m, string val) { return m.find(val) != m.end(); } int main() { vector<double> v = {42.2, 35.7, 22.6, 14.2}; set<int> s {7, 4, 11, 10}; map<string, int> m = {{"Spiegel", 1}, {"Zeit", 2}, {"FAZ", 3}}; t(in_vector(v, 22.6)); // 1 t(in_vector(v, 10.7)); // 0 t(in_set(s, 6)); // 0 t(in_set(s, 4)); //1 t(in_map(m, "Bild")); // 0 t(in_map(m, "Zeit")); // 1 return 0; }