Why lower_bound() and upper_bound() functions in C++ are named so ?

Правка en1, от Acadaniket_1729, 2023-03-26 11:34:10

The terms "lower bound" and "upper bound" come from the mathematical concept of intervals and are used in computer science to refer to the two endpoints of a range.

In the case of the C++ Standard Library functions lower_bound and upper_bound, these endpoints are the first element in a range that is not less than (i.e., greater than or equal to) a given value, and the first element in a range that is strictly greater than a given value, respectively.

The terms "lower" and "upper" are used because they convey the idea that the endpoints of the range can be thought of as the "lower" and "upper" limits of the values that fall within the range. This terminology is consistent with the use of the terms in mathematics, where the lower bound and upper bound of an interval define the smallest and largest values that belong to the interval.

By using the terms "lower_bound" and "upper_bound" to name these functions, the C++ Standard Library is making a connection to the mathematical concept of intervals and making it clear that these functions are designed to work with sorted ranges of values.

Теги #lower_bound(), #upper_bound()

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский Acadaniket_1729 2023-03-26 11:34:10 1177 Initial revision (published)