Reputation: 26993
Suppose you have a certain template that takes a parameter class
template <typename ConnectorClass>
struct myClass {
}
I want to add a BOOST_ASSERT_MSG
to validate that ConnectorClass
implements a certain method of signature
returnType MethodName(param1, param2)
How should i write the assert condition in this case?
EDIT: since the question does not seem to have a clear solution, i'm posting a sub-question with intermediate results based on some references on the answers please follow here
Upvotes: 0
Views: 513
Reputation: 3059
Look into the various static assertion utilities in Boost. In particular:
Upvotes: 0
Reputation: 8526
You can't. BOOST_ASSERT_MSG is evaluated during runtime. If the class doesn't have that member, you'll get a compilation error wherever your template expects it.
If your goal is better error messages, look into Boost's Concept Check library. If your goal is to have your template do something different depending on what members are available, look into Boost's enable_if
.
Here's an answer to a similar question.
Upvotes: 2
Reputation: 54178
If you are on Windows, and not too picky, you can do this via __if_exists, a hack extension to Visual C++
Upvotes: 0