Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

testing

c++03

I am writing a test driver for a type this is explicitly supposed to not be default constructable. Is there any way to assert in my test driver that this is the case? I can verify manually via compilation errors, but I want something that will protect against future changes that may misguidedly add a default constructor.

Edit: I'm stuck in an environment with C++03. Keeping that in mind, are there any other options than is_default_constructable?

like image 707
GBleaney Avatar asked Jul 08 '14 17:07

GBleaney


1 Answers

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

like image 55
Kerrek SB Avatar answered Nov 14 '22 22:11

Kerrek SB