is_constructible in c++17 for types without user defined constructors

Viewed 39

I would like to check at compile time if a type is constructible from the types of the arguments to its constructor. The static assertion below passes in C++2a while fails with C++17 and the reason why is in the code snippet below the static assertion. Question: how can I reformulate the static assertion for it to work with C++17 ?

struct X
{
   int x;
   float y;
};

int main()
{
   static_assert(std::is_constructible_v<X, int, float>);
   
   // Below is valid in both C++17 and 2a
   X x1{10, 1.3f};

   // Below is only valid in C++2a
   X x2(10, 1.3f);
}
0 Answers
Related