How to restrict an iterator to being a forward iterator?

后端 未结 4 2022
终归单人心
终归单人心 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:46

    You can use SFINAE and replace bool by:

    typename enable_if<
       is_same::iterator_category,
               std::forward_iterator_tag>::value,
       bool>::type
    

    You may need to define is_same and enable_if yourself if you don't want to pull them from Boost or TR1:

    template 
    struct is_same { static const bool value = false; };
    
    template 
    struct is_same { static const bool value = true; };
    
    template  struct enable_if { };
    template  struct enable_if { typedef T type; };
    

提交回复
热议问题