fork(1) download
  1. #include <string>
  2. #include <iostream>
  3. #include <set>
  4. #include <initializer_list>
  5. #include <algorithm>
  6.  
  7. template<typename T2, typename T>
  8. bool contains(T const& value, std::initializer_list<T2> const& set)
  9. {
  10. return std::find(std::begin(set), std::end(set), value) != std::end(set);
  11. }
  12.  
  13. int main(void)
  14. {
  15. std::set<std::wstring> values = { L"bar", L"not" };
  16.  
  17. for (std::wstring val : values) {
  18. std::wcout << "\"" << val << "\" ";
  19. if (contains(val, { L"foo", L"bar", L"baz", L"doom" })) {
  20. std::wcout << "found" << std::endl;
  21. }
  22. else {
  23. std::wcout << "not found" << std::endl;
  24. }
  25. }
  26. }
Success #stdin #stdout 0s 3492KB
stdin
Standard input is empty
stdout
"bar" found
"not" not found