Skip to content

Instantly share code, notes, and snippets.

@yuba
Created November 11, 2015 05:30
Show Gist options
  • Save yuba/6621c3e365319d50877c to your computer and use it in GitHub Desktop.
Save yuba/6621c3e365319d50877c to your computer and use it in GitHub Desktop.
std::set<T>の所属判定をスマートに書く ref: http://qiita.com/yuba/items/f06846ea9bb1147bf581
s.find(e) != s.end()
/// <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;
}
s > e
// もしくは
e < s
/// <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