Repository: xbmc/xbmc
File: xbmc/guilib/GUIBaseContainer.cpp (C++)

Code before:
    if (focusedLayout && focusedLayout->MoveLeft())
      return;
  }
  CGUIControl::OnLeft();
}

void CGUIBaseContainer::OnRight()
{
  CGUIAction action = GetAction(ACTION_MOVE_RIGHT);
  bool wrapAround = action.GetNavigation() == GetID() || !action.HasActionsMeetingCondition();
  if (m_orientation == HORIZONTAL && MoveDown(wrapAround))
    return;
  else if (m_orientation == VERTICAL)
  {
    CGUIListItemLayout *focusedLayout = GetFocusedLayout();
    if (focusedLayout && focusedLayout->MoveRight())
      return;
  }
  CGUIControl::OnRight();
}

void CGUIBaseContainer::OnNextLetter()
{
  const int offset = CorrectOffset(GetOffset(), GetCursor());
  // Binary search for first letter offset greater than current position
  auto it = std::upper_bound(m_letterOffsets.begin(), m_letterOffsets.end(), offset,
                             [](int value, const std::pair<int, std::string>& elem)
                             { return value < elem.first; });
  if (it != m_letterOffsets.end())
    SelectItem(it->first);
}

void CGUIBaseContainer::OnPrevLetter()
{
  const int offset = CorrectOffset(GetOffset(), GetCursor());
  if (m_letterOffsets.empty())
    return;
  // Binary search for last letter offset less than current position
  auto it = std::lower_bound(m_letterOffsets.begin(), m_letterOffsets.end(), offset,
                             [](const std::pair<int, std::string>& elem, int value)
                             { return elem.first < value; });
  if (it != m_letterOffsets.begin())
    SelectItem((--it)->first);
}

void CGUIBaseContainer::OnJumpLetter(const std::string& letter, bool skip /*=false*/)
{
  if (m_matchTimer.GetElapsedMilliseconds() < letter_match_timeout)
    m_match += letter;
  else
    m_match = letter;

Review comment (suggestion):
Please use ranges (and projection would also be possible here):
```suggestion
  auto it = std::ranges::upper_bound(m_letterOffsets, offset, {}, &std::pair<int, std::string>::first);
```

Same for the other calls below. You don't need `<ranges>`, `<algorithm>` is enough

Code after:
    if (focusedLayout && focusedLayout->MoveLeft())
      return;
  }
  CGUIControl::OnLeft();
}

void CGUIBaseContainer::OnRight()
{
  CGUIAction action = GetAction(ACTION_MOVE_RIGHT);
  bool wrapAround = action.GetNavigation() == GetID() || !action.HasActionsMeetingCondition();
  if (m_orientation == HORIZONTAL && MoveDown(wrapAround))
    return;
  else if (m_orientation == VERTICAL)
  {
    CGUIListItemLayout *focusedLayout = GetFocusedLayout();
    if (focusedLayout && focusedLayout->MoveRight())
      return;
  }
  CGUIControl::OnRight();
}

void CGUIBaseContainer::OnNextLetter()
{
  const int offset = CorrectOffset(GetOffset(), GetCursor());
  // Binary search for first letter offset greater than current position
  auto it =
      std::ranges::upper_bound(m_letterOffsets, offset, {}, &std::pair<int, std::string>::first);
  if (it != m_letterOffsets.end())
    SelectItem(it->first);
}

void CGUIBaseContainer::OnPrevLetter()
{
  const int offset = CorrectOffset(GetOffset(), GetCursor());
  if (m_letterOffsets.empty())
    return;
  // Binary search for last letter offset less than current position
  auto it =
      std::ranges::lower_bound(m_letterOffsets, offset, {}, &std::pair<int, std::string>::first);
  if (it != m_letterOffsets.begin())
    SelectItem((--it)->first);
}

void CGUIBaseContainer::OnJumpLetter(const std::string& letter, bool skip /*=false*/)
{
  if (m_matchTimer.GetElapsedMilliseconds() < letter_match_timeout)
    m_match += letter;
  else
    m_match = letter;

  m_matchTimer.StartZero();