Skip to content

Instantly share code, notes, and snippets.

@adam-currie
Created December 30, 2021 18:55
Show Gist options
  • Save adam-currie/297a67cd9ca2db8159816d5bb13c31bf to your computer and use it in GitHub Desktop.
Save adam-currie/297a67cd9ca2db8159816d5bb13c31bf to your computer and use it in GitHub Desktop.
checks if a container contains an item eg: strings>>contains("hello")
#pragma once
template<typename T>
class contains {
const T& item;
public:
contains(const T& item) : item(item) {}
template<typename C>
friend const bool operator>>(const C& container, const contains& args) {
for (const auto& i : container)
if (i == args.item)
return true;
return false;
}
};
@adam-currie
Copy link
Author

strings>>contains("hello")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment