lower bound 和upper bound的意义

发布时间 2023-07-05 15:02:08作者: xuyv

它们通常来说可以成对出现,寻找某个值的range: [first, last)。

因为这个range符合数学意义的上界和下界,因此被命名为lower bound何upper bound。

如果这个值,存在,那么它其实等价于equal_range。

如1,2,2,3。val = 2,则lower_bound, upper_bound = [1,3)

     ^    ^

 

lower_bound() 和 upper_bound() 函数在 C++ 中被命名为这样是因为它们用于在已排序的元素范围中查找指定值的位置。lower_bound() 函数返回一个迭代器,指向范围中第一个不小于指定值的元素,而 upper_bound() 函数返回一个迭代器,指向范围中第一个大于指定值的元素。"lower bound" 和 "upper bound" 这些术语在数学中通常用于描述某个限制范围内的值范围,这就是为什么在 C++ 中这些函数被命名为这样的原因。