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

后端 未结 5 1432
迷失自我
迷失自我 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 19:55

    template
    struct is_iterator
    {   
        static T makeT();
        typedef void * twoptrs[2];  // sizeof(twoptrs) > sizeof(void *)
        static twoptrs & test(...); // Common case
        template static typename R::iterator_category * test(R); // Iterator
        template static void * test(R *); // Pointer
    
        static const bool value = sizeof(test(makeT())) == sizeof(void *); 
    };
    

提交回复
热议问题