“Generic” iterator in c++

后端 未结 7 1244
慢半拍i
慢半拍i 2021-01-04 06:09

I have:

void add_all_msgs(std::deque::iterator &iter);

How can I make that function \"generic\", so it can take any kind

7条回答
  •  感情败类
    2021-01-04 07:00

    template 
    void add_all_messages(Iterator first, Iterator last)
    

    usage :

    vector v;
    add_all_messages(v.begin(), v.end());
    

    You need to specify the end, otherwise you won't know when to stop! It also gives you the flexibility of adding only a subrange of a container.

提交回复
热议问题