A lambda is quite short:
// std::lower_bound(myVec.rbegin(), myVec.rend(), myVal,
[&valComp](const auto& l, const auto& r) { return valComp(r, l); }
// );
The standard built-in solution would be std::bind
// std::lower_bound(myVec.rbegin(), myVec.rend(), myVal,
std::bind(valComp, std::placeholders::_2, std::placeholders::_1)
// );
But lambdas are universally more readable. You can make a helper function to make this simpler at the point of use:
template<typename F>
auto swap_two_args(F&& f) {
return [f=std::forward<F>(f)](auto&& l, auto&& r) {
return f(std::forward<decltype(r)>(r), std::forward<decltype(l)>(l));
};
}
// std::lower_bound(myVec.rbegin(), myVec.rend(), myVal,
swap_two_args(valComp)
// );
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…