how to detect if a type is an iterator or const_iterator

前端 未结 5 472
北荒
北荒 2020-12-31 07:24

I\'m wondering, if there is a way to check at compile time whether a type T of some iterator type is a const_iterator, or not. Is there some difference in the types that ite

5条回答
  •  再見小時候
    2020-12-31 07:43

    With C++11, the new standard header provides std::is_const, so Nawaz's solution can be simplified:

    template
    struct is_const_iterator
    {
        typedef typename std::iterator_traits::pointer pointer; 
        static const bool value = 
            std::is_const::type>::value;
    };
    

提交回复
热议问题