Janoma
Janoma

Reputation: 522

Can I check that a class is *not* default constructible?

First of all, note that I'm using C++03 (and C++11 is not an option). I'm using boost concept to check that a certain class is default-constructible:

BOOST_CONCEPT_ASSERT((boost::DefaultConstructible<my_class>));

However, for some other class I'd like to assert that the type does not have a default constructor. Is there a way of doing this?

Update: to all those super-duper experts marking the question as duplicate or already answered without reading it: I state in the very first paragraph that I already use boost concept to check that classes are default-constructible (which is the question this is supposed to be a duplicate of). I also explicitly state that I can't use C++11, so type_traits are not available to me. So, could somebody please point me to the specific part where my question was "already answered"? Because I haven't found it yet.

Upvotes: 9

Views: 377

Answers (1)

migle
migle

Reputation: 949

The disappointing bit is that no, this is not possible with boost concept check.

The not so disappointing bit is: aren't you trying to use this tool backwards?

Generally, you write code that needs a type that has a certain number of features, such as constructors, functions that operate on that type, and so on. I can't imagine a situation where you would write code that needs a type which lacks specific features.

You seem not to be wanting to do concept-oriented programming, but to enforce coding style. And this is not the right tool for it.

Upvotes: 2

Related Questions