SFINAE compiler troubles

前端 未结 5 844
一向
一向 2021-02-06 08:54

The following code of mine should detect whether T has begin and end methods:

template 
struct is_contai         


        
5条回答
  •  再見小時候
    2021-02-06 09:34

    This probably should be a comment, but I don't have enough points

    @MSalters

    Even though your is_container works (almost) and I've used your code myself, I've discovered two problems in it.

    First is that type deque::iterator is detected as a container (in gcc-4.7). It seems that deque::iterator has begin/end members and const_iterator type defined.

    2nd problem is that this code is invalid according to GCC devs. I qoute: values of default arguments are not part of the function type and do not take part in deduction. See GCC bug 51989

    I am currently using this (C++11 only) for is_container:

    template 
    struct is_container {
        template <
            typename U,
            typename S = decltype (((U*)0)->size()),
            typename I = typename U::const_iterator
        >
        static char test(U* u);
        template  static long test(...);
        enum { value = sizeof test(0) == 1 };
    };
    

提交回复
热议问题