class 模板参数 Proj 和 class 模板 IndirectUnaryPredicate 在 TS 范围内的目的是什么?

What is the purpose of class template parameter Proj and class template IndirectUnaryPredicate in the ranges TS?

Cpp-reference 显示来自(实验)范围 TS 的以下函数模板(以及其他):

template< ranges::InputIterator I, ranges::Sentinel<I> S,
   class Proj = ranges::identity,
   ranges::IndirectUnaryPredicate<ranges::projected<I, Proj>> Pred >
bool all_of( I first, S last, Pred pred, Proj proj = Proj{} );

模板参数 ProjIndirectUnaryPredicate 结合使用有什么用?

这是一个投影。在将它们传递给谓词之前,您可以使用它来 "project" 范围的元素。它很有用,例如,当您要将谓词应用于 std::pair 等复杂数据类型时,我们希望将谓词应用于 std::pair::second.

all_of(range_of_std_pairs, pred, &pair_t::second);

使用对的第二个元素上的谓词 pred 检查 std::pairs 的范围。