使用 STL 的映射中最大的下限绑定
Biggest inferior bound in a map using STL
使用下面的代码,我可以找到某个值的最低上级界限。除了最大的劣势,我怎么能做同样的事情?
double Sup(double const x) const {
//Lower bound: first element that is greater-or-equal.
map<double,double>::iterator it=MapCurve.lower_bound(x);
if (it!=MapCurve.end()) {
return it->first;
} else {
--it;
return it->first;
}
}
假设您在地图上有这些键值:0.2 | 0.7 | 1.3 | 2.4 | 5.1
上(1.2) 给出 1.3
现在我想要 Inf 函数,使得 Inf(1.2) 将给出 0.7。 我该怎么做?
lower_bound(x)
给出第一个不在x之前的元素(即>=)。你想要上一个元素。
auto it = MapCurve.lower_bound(x);
if (it == MapCurve.begin()) {
// No element less than x in the map.
// throw error or return error code.
}
--it;
return it->first;
相关文章:
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 在基于范围的for循环中使用结构化绑定声明
- 使用 LuaBridge 将 LuaJIT 绑定到C++会导致"PANIC: unprotected error"
- 尝试通过OCI例程从Oracle获取blob数据,但出现错误:ORA-01008:并非所有变量都绑定
- 在使用GPU支持编译Tensorflow时,会遇到CUDA_TOOLKIT_PATH未绑定变量
- 视觉studo 2019中的漫画和静态/动态绑定
- 将自由函数绑定为类成员函数
- 将常量指针引用绑定到非常量指针
- 在派生类中绑定非静态模板化成员函数
- 绑定派生类方法C++从实例范围之外的分隔 std::function 变量调用
- 在 openGL 中多次绑定缓冲区
- 定义有趣的宏和正则表达式在Z3 C++绑定
- 使用结构化绑定'Reflection'
- 为什么 std::绑定错误参数可以成功?
- 如何绑定 C++ gRPC 客户端的网络接口
- 在 openmp 中,omp_get_thread_num是否绑定到物理线程?
- C++绑定(已弃用)
- 如何将 STL 队列推送函数绑定到 std::函数?
- SGI STL 中的绑定好友模板
- 使用 STL 的映射中最大的下限绑定