Home:ALL Converter>What is the difference between std::lower_bound and std::upper_bound?

What is the difference between std::lower_bound and std::upper_bound?

Ask Time:2020-09-25T04:38:59         Author:Dmitriano

Json Formatter

The code below does not compile with both MSVC2017 and GCC11:

#include <deque>
#include <chrono>
#include <algorithm>

using Clock = std::chrono::system_clock;
using TimePoint = std::chrono::time_point<Clock>;

struct PricePoint
{
    TimePoint dt;
    double buy;
    double sell;
};

inline bool operator < (const TimePoint & dt, const PricePoint & a)
{
    return a.dt < dt;
}

int main()
{
    std::deque<PricePoint> priceSequence;
    const auto begin = std::lower_bound(priceSequence.begin(), priceSequence.end(), Clock::now());
    return 0;
}

But if I replace std::lower_bound with std::upper_bound it starts to compile. What is the difference?

Author:Dmitriano,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/64054070/what-is-the-difference-between-stdlower-bound-and-stdupper-bound
yy