“通用"C++中的迭代器

2022-01-10 00:00:00 iterator c++ stl

我有:

void add_all_msgs(std::deque<Message>::iterator &iter);

如何使该函数通用",以便它可以采用任何类型的输入迭代器?我真的不在乎它是否在迭代双端队列、向量或其他东西,只要迭代器正在迭代消息.- 这在 C++ 中是不是很简单?

How can I make that function "generic", so it can take any kind of inputiterators ? I don't really care if it's iterating a deque,a vector or something else, as long as the iterator is iterating Message's. - is this at all straight forward possible in c++ ?

推荐答案

template<class InputIterator>
void add_all_msgs(InputIterator iter);

用法:

std::deque<Message> deq;
add_all_msgs(deq.begin());

相关文章