Hughes, James wrote:
Hello all,
I want some template code to assert if the passed in template type is NOT derived from a particular base class.
I've looked through the Template Metaprogamming book, but haven't seen anything that can do this, but I seem to remember something along those lines.
Can anyone help?
James
Hi James,
the easiest way is something like the following:
#include
#include BOOST_STATIC_ASSERT (boost::is_base_of
::value); Hope this helps,
Martin
Thanks Martin - I knew I had seen it somewhere. That covers the first point, but I've just realised I need to be a bit cleverer. The incoming type can either be the type itself or a pointer to the type, or a boost::shared_ptr to the type, and the type must be derived as the original question. Depending on which it is I need to do slightly different things, so I need to, effectively, conditionally compile a bit of code depending on the results of the tests, or assert if the type (after getting rid of the pointer/shared point bit) isn't derived from my base class. Basically I'm iterating through a vector of the incoming type and calling a function in the type stored. That function comes from the base class, but in order to be really generic I need to handle the shared_ptr and pointer cases. I think I need mpl for that, but I only get to chapter three of the book before my head starts to hurt. Any ideas/hints/places I can look? James This message (including any attachments) contains confidential and/or proprietary information intended only for the addressee. Any unauthorized disclosure, copying, distribution or reliance on the contents of this information is strictly prohibited and may constitute a violation of law. If you are not the intended recipient, please notify the sender immediately by responding to this e-mail, and delete the message from your system. If you have any questions about this e-mail please notify the sender immediately.