我想写一些类似于以下代码的东西
class c{
public:
//...
big_structure* find(int e){
auto it = std::lower_bound(v1.begin(), v1.end(), e);
return v2[it - v1.begin()];
}
private:
std::vector<int> v1; //v1 is sorted;
std::vector<big_structure*> v2; //v2.size() = v1.size() + 1
}
Run Code Online (Sandbox Code Playgroud)
这是合法的,而且当e不在v1中时它会返回v2 [v1.size()]吗?
如果可能的话我不想特殊情况它== v1.end().