我想升级我的自定义容器以与std::ranges
诸如find_if
和其他算法兼容,如下所示
auto is_satisfy = [](CustomContainer::value_type x) { ... };
std::ranges::find_if(custom_container, is_satisfy);
// instead of std::find_if(custom_container.begin(), custom_container.end(), is_satisfy);
std::ranges::find_if
喜欢的签名
struct find_if_fn {
template< ranges::input_range R,
class Proj = std::identity,
std::indirect_unary_predicate<std::projected<ranges::iterator_t<R>,
Proj>> Pred >
constexpr ranges::borrowed_iterator_t<R>
operator()( R&& r, Pred pred = {}, Proj proj = {} ) const
{
return (*this)(ranges::begin(r), ranges::end(r), std::ref(pred), std::ref(proj));
}
};
什么是input_range 概念以及我自己的自定义容器如何支持此功能?