• lower_bound with reverse-iterators

    From Bonita Montero@3:633/10 to All on Tue Jul 7 20:32:30 2026
    What does lower_bound( ... ) below ?


    auto date_1601::leappishShift( int64_t timestamp, bool add ) noexcept -> optional<shift_result>
    {
    vector<int64_t> &ls = t_leapSeconds;
    auto atOrBeyond = lower_bound( ls.rbegin(), ls.rend(), timestamp,
    []( int64_t larger, int64_t smaller )
    {
    return larger > smaller;
    } ).base();
    int64_t shift = (atOrBeyond - t_leapSeconds.begin()) * SSecond;
    if( !add )
    return shift_result( timestamp - shift, false );
    if( timestamp >= TpMax - shift ) [[unlikely]]
    return nullopt;
    timestamp += shift;
    bool inLeap = atOrBeyond != ls.end() && timestamp >= *atOrBeyond;
    return shift_result( timestamp + (inLeap ? SSecond : 0), inLeap );
    }

    --- PyGate Linux v1.5.18
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)