I have a template that I would like to conditionally compile depending on the type of the argument. I only care about differentiating between \"Plain Old Data\" (POD), i.e., in
You can do it without enable_if, because all you need is to dispatch depending on type traits. enable_if is used to add/remove template instantiations to/from overload resolution. You may want to use call traits to choose the best method to pass objects to your function. As a rule, objects should be passed by reference, whereas POD is passed by value. call_traits let's you choose between const and non-const references. The code below uses const reference.
#include
#include
template
class foo {
public:
void bar(typename boost::call_traits::param_type obj) {
do_something(obj, boost::is_pod());
}
private:
void do_something(T obj, const boost::true_type&)
{
// do something for POD
}
void do_something(const T& obj, const boost::false_type&)
{
// do something for classes
}
};