SFINAE working in return type but not as template parameter

后端 未结 3 2061
情深已故
情深已故 2020-11-22 14:20

I already used the SFINAE idiom quite a few times and I got used to put my std::enable_if<> in template parameters rather than in return types. However, I

3条回答
  •  青春惊慌失措
    2020-11-22 14:52

    Values in the templates work:

    template::value, int>::type = 0>
    auto foo(T)
        -> void
    {
        std::cout << "I'm an integer!\n";
    }
    
    template::value, int>::type = 0>
    auto foo(T)
        -> void
    {
        std::cout << "I'm a floating point number!\n";
    }
    

提交回复
热议问题