std::lower_bound() および std::upper_bound() 構文 (まあ、実際には型変換) で矛盾しているように見えるものを見たので、誰かが解明できるかどうか疑問に思っていましたか? コメントによると、2 行目は 1 行目と明らかに類似しているにもかかわらず、コンパイルされません。3行目に示されているフォームを使用する必要があります(少なくともgcc 4.7.3 / ubuntu 64ビットでは-これですべてです)
#include <set>
#include <algorithm>
using namespace std;
class MyInt {
private:
int val;
public:
MyInt(int _val): val(_val) {}
bool operator<(const MyInt& other) const {return val < other.val;}
};
int main() {
set<MyInt> s;
s.insert(1); // demonstrate implicit conversion works
s.insert(MyInt(2));
s.insert(3); // one last one for the road
set<MyInt>::iterator itL = lower_bound(s.begin(), s.end(), 2); //LINE 1
// the line below will NOT compile
set<MyInt>::iterator itU = upper_bound(s.begin(), s.end(), 2); //LINE 2
// the line below WILL compile
set<MyInt>::iterator itU2 = upper_bound(s.begin(), s.end(), MyInt(2)); // LINE 3
return 0;
}