How to restrict an iterator to being a forward iterator?

后端 未结 4 2096
终归单人心
终归单人心 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 17:06

    You can do this using std::enable_if:

    #include 
    #include 
    #include 
    
    template 
    typename std::enable_if::iterator_category>::value,
                        bool>::type
    EnumerateTwice(It begin, It end, TCallback) {
        ...
    }
    

    This uses class from C++11 but all of this can be done in C++03 as well.

提交回复
热议问题