Created
November 11, 2015 05:30
-
-
Save yuba/6621c3e365319d50877c to your computer and use it in GitHub Desktop.
std::set<T>の所属判定をスマートに書く ref: http://qiita.com/yuba/items/f06846ea9bb1147bf581
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
s.find(e) != s.end() |
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
/// <summary>std::setの所属判定演算子</summary> | |
template <typename T> | |
static bool operator>(const std::set<T>& s, const T& item){ | |
return s.find(item) != s.end(); | |
} | |
/// <summary>std::setの所属判定演算子</summary> | |
template <typename T> | |
static bool operator<(const T& item, const std::set<T>& s){ | |
return s > e; | |
} |
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
s > e | |
// もしくは | |
e < s |
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
/// <summary>std::vectorの所属判定演算子</summary> | |
template <typename T> | |
static bool operator>(const std::vector<T>& s, const T& item){ | |
return std::find(s.cbegin(), s.cend(), e) != s.cend(); | |
} | |
/// <summary>std::vectorの所属判定演算子</summary> | |
template <typename T> | |
static bool operator<(const T& item, const std::vector<T>& s){ | |
return s > e; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment