How to restrict an iterator to being a forward iterator?

后端 未结 4 2015
终归单人心
终归单人心 2021-02-09 16:38

I have a function that needs to enumerate an iterator multiple times, but according to MSDN, \"Once you increment any copy of an input iterator, none of the other copies can

4条回答
  •  攒了一身酷
    2021-02-09 16:51

    Not tested but you could try something along the lines of:

    template
    bool EnumerateTwice_Interal(const It &begin, const It &end, TCallback callback, 
          std::forward_iterator_tag)
    {
         //do your things
    }
    
    template
    bool EnumerateTwice(const It &begin, const It &end, TCallback callback)
    {
        EnumerateTwice_Internal(begin, end, callback,
            typename std::iterator_traits::iterator_category());
    }
    

提交回复
热议问题