I have a template, template
, that I would like to specialize based on the existence of typename T::context_type
. If
Using @K-ballo's answer, I wrote the following:
namespace detail {
BOOST_MPL_HAS_XXX_TRAIT_DEF(context_type)
}
template
class wrapper
{
public:
wrapper() {
std::cout << "T::context_type does not exist." << std::endl;
}
};
template
class wrapper >::type>
{
public:
typedef typename T::context_type context_type;
private:
context_type ctx;
public:
wrapper(context_type ctx_)
: ctx(ctx_)
{
std::cout << "T::context_type exists." << std::endl;
}
};
Now, the sample code compiles and outputs:
T::context_type exists. T::context_type does not exist.