What's the use of second parameter of std::enable_if?

前端 未结 2 1300
忘掉有多难
忘掉有多难 2021-01-14 01:11

I am confused about the second parameter of std::enable_if. In using of a return type of int, we can make it using:

template 
typename std::en         


        
2条回答
  •  不思量自难忘°
    2021-01-14 01:44

    what's the difference of too functions below:

    One is a template that can be called for any CopyConstructible type, the enable_if only constrains it when the default template argument is used:

    #include 
    
    template::value>::type >
    T too(T t) { std::cout << "here" << std::endl; return t; }
    
    int too(int t) { std::cout << "there" << std::endl; return t; }
    
    int main()
    {
        too(1.0);
    }
    

提交回复
热议问题