Is there a way to verify that the default constructor does not exist?

I am writing a test driver for a type that obviously should not be constructive by default. Is there a way to claim in my test driver that this is so? I can check it manually with compilation errors, but I want something that will protect against future changes that the default constructor might mistakenly add.

Edit: I am stuck in an environment with C ++ 03. Keeping this in mind, are there any other options besides is_default_constructable ?

+6
source share
1 answer

You can use static_assert(!std::is_default_constructible<T>::value, "Boo"); . Make sure #include <type_traits> .

+11
source

Source: https://habr.com/ru/post/971932/


All Articles