Created
December 30, 2021 18:55
-
-
Save adam-currie/297a67cd9ca2db8159816d5bb13c31bf to your computer and use it in GitHub Desktop.
checks if a container contains an item eg: strings>>contains("hello")
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
strings>>contains("hello")