5

I want to implement static check to find out if type constructible:

#include <iostream>

template<typename T>
struct IsConstr
{
    typedef char TrueType;
    typedef struct{char a[2];} FalseType;
    template<typename C>
    static decltype((C(),TrueType())) test(int);
    template<typename C>
    static FalseType test(...);

    enum{value=(sizeof(test<T>(0))==sizeof(TrueType))};
}; 


struct S{private: S();};
int main()
{
    std::cout<<IsConstr<S>::value<<std::endl;
    std::cout<<IsConstr<int>::value<<std::endl;
    return 0;
}

The code doesn't compile, showing an error

"Substitution failed. 'S::S()' is private".

Why doesn't SFINAE work here? Thanks.

O'Neil
  • 3,790
  • 4
  • 16
  • 30
Alexander
  • 779
  • 8
  • 17

0 Answers0