lurscher
lurscher

Reputation: 26993

boost_assert that a parameter class implements a certain method

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

Answers (3)

GrafikRobot
GrafikRobot

Reputation: 3059

Look into the various static assertion utilities in Boost. In particular:

  • BOOST_STATIC_ASSERT (see docs here)
  • BOOST_MPL_ASSERT (see docs here)

Upvotes: 0

Steve M
Steve M

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

Steve Townsend
Steve Townsend

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

Related Questions