GBleaney
GBleaney

Reputation: 2196

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

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?

Upvotes: 6

Views: 236

Answers (1)

Kerrek SB
Kerrek SB

Reputation: 477100

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

Upvotes: 11

Related Questions