This combines `EraseLastKElementsIf` (introduced in D9863) with the existing `EraseLastKElements` function by using a default `return true` predicate.
This is a backport of core#20197 [5/6]
https://github.com/bitcoin/bitcoin/pull/20197/commits/8f1a53eb027727a4c0eaac6d82f0a8279549f638
Depends on D10978