1) 对于给定的stl
算法,如何找出需要实现哪些自定义容器/迭代器特性才能使用该容器?
2) 为使容器与所有stl
算法完全兼容,需要实现什么?
1) 对于给定的stl
算法,如何找出需要实现哪些自定义容器/迭代器特性才能使用该容器?
2) 为使容器与所有stl
算法完全兼容,需要实现什么?
template <class InputIterator, class Predicate>
bool any_of(InputIterator first, InputIterator last, Predicate pred);
因此,您需要提供一个输入迭代器,然后可以在§24.2.3中查看其要求并实现它们:
a != b
)*a
)a->m
)对于每种类型的迭代器,情况相同。
STL算法使用模板类型来描述函数的要求。如果以std::sort
为例。
template<class RandomAccessIterator>
void sort(RandomAccessIterator first, RandomAccessIterator last);
std::sort
一起使用。