How to check if a template parameter is an iterator type or not?

后端 未结 5 1433
迷失自我
迷失自我 2020-12-17 19:21
template
struct is_iterator
{
    static const bool value = ??? // What to write ???
};

int main()
{
    assert(false == is_iterator::valu         


        
5条回答
  •  情书的邮戳
    2020-12-17 20:03

    Well, you could check for the type to have a nested typedef called iterator_category This can be done using SFINAE, and the exact technique can be found in wiki page for SFINAE. This isn't a 100% method, but all decent iterators should provide the common typedefs for iterators, and the iterator_category is one that is unique to iterators. Also don't forget to check if TYPE is simply a pointer. Pointers are iterators.

提交回复
热议问题