Why do my SFINAE expressions no longer work with GCC 8.2?

前端 未结 3 417
醉话见心
醉话见心 2020-12-05 14:28

I recently upgraded GCC to 8.2, and most of my SFINAE expressions have stopped working.

The following is somewhat simplified, but demonstrates the problem:



        
3条回答
  •  孤街浪徒
    2020-12-05 15:03

    Partial answer: use typename = typename enable_if<...>, T=0 with different Ts:

    #include 
    #include 
    
    class Class {
    public:
        template <
            typename U,
            typename = typename std::enable_if_t<
                std::is_const::type>::value
            >, int = 0
        >
        void test() {
            std::cout << "Constant" << std::endl;
        }
    
        template <
            typename U,
            typename = typename  std::enable_if_t<
                !std::is_const::type>::value
            >, char = 0
        >
        void test() {
            std::cout << "Mutable" << std::endl;
        }
    };
    
    int main() {
        Class c;
        c.test();
        c.test();
        return 0;
    }
    

    (demo)

    Still trying to figure out what the heck does std::enable_if<...>::type... mean knowing the default type is void.

提交回复
热议问题