fork(1) download
  1. #include <vector>
  2. #include <string>
  3.  
  4. using namespace std;
  5. template<class T>
  6. struct MyType {
  7. string name;
  8. T data;
  9. };
  10.  
  11. template<class T>
  12. vector<MyType<T>> filter(vector<MyType<T>> items, vector<string> filter)
  13. {
  14. vector<MyType<T>> filteredItems;
  15. copy_if(begin(items), end(items), begin(filteredItems), any_of(begin(filter), end(filter), [](const MyType<T>& lhs, const MyType<T>& rhs) {return lhs.name == rhs.name; }));
  16. return filteredItems;
  17. };
  18.  
  19. int main() {
  20. vector<MyType<int>> items { {"a", 1}, {"b", 2}, {"c", 3} };
  21. vector<string> filter { "a", "c" };
  22. auto filteredItems = filter(items, filter);
  23. }
  24.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:22:44: error: no match for call to '(std::vector<std::basic_string<char> >) (std::vector<MyType<int> >&, std::vector<std::basic_string<char> >&)'
   auto filteredItems = filter(items, filter);
                                            ^
stdout
Standard output is empty