How to use sfinae for selecting constructors?

后端 未结 5 1848
北海茫月
北海茫月 2020-11-29 04:24

In template meta programming, one can use SFINAE on the return type to choose a certain template member function, i.e.

template struct          


        
5条回答
  •  野性不改
    2020-11-29 05:22

    In C++11, you can use a defaulted template parameter:

    template = N>::type>
    explicit A(A const &);
    

    However, if your compiler doesn't support defaulted template parameters yet, or you need multiple overloads, then you can use a defaulted function parameter like this:

    template 
    explicit A(A const &, typename std::enable_if= N>::type* = 0);
    

提交回复
热议问题